| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | # Per-user GitHub OAuth connection used by the "Import from GitHub" flow. |
| 4 | # |
| 5 | # This is deliberately separate from the smbCloud-brokered "Continue with |
| 6 | # GitHub" sign-in: that gives us a smbCloud session, not a GitHub API token. |
| 7 | # Importing needs a real GitHub token (scoped `repo` or `public_repo`) to list |
| 8 | # private repos and clone them, so we run our own minimal OAuth app and store |
| 9 | # the resulting token here — encrypted at rest, one row per user, revocable. |
| 10 | class CreateGithubConnections < ActiveRecord::Migration[8.1] |
| 11 | def change |
| 12 | create_table :github_connections do |t| |
| 13 | t.references :user, null: false, foreign_key: true, index: { unique: true } |
| 14 | t.string :github_login |
| 15 | # Encrypted at rest via ActiveRecord::Encryption (`encrypts :access_token`). |
| 16 | # text, not string: encrypted + base64 ciphertext is longer than the token. |
| 17 | t.text :access_token, null: false |
| 18 | t.string :scope |
| 19 | t.string :token_type, default: "bearer", null: false |
| 20 | t.datetime :connected_at |
| 21 | |
| 22 | t.timestamps |
| 23 | end |
| 24 | end |
| 25 | end |