| 1 | # frozen_string_literal: true |
| 2 | |
| 3 | # Tracks one "import a repo into siGit" operation end to end so the UI can show |
| 4 | # live progress and a failed import can be retried. The heavy lifting (clone, |
| 5 | # push, LFS) runs off the request thread in RepositoryImportJob; this row is the |
| 6 | # durable state machine it drives. |
| 7 | class CreateRepositoryImports < ActiveRecord::Migration[8.1] |
| 8 | def change |
| 9 | create_table :repository_imports do |t| |
| 10 | t.references :user, null: false, foreign_key: true |
| 11 | # Set once the target repo exists on disk; nil while queued/cloning and |
| 12 | # after a cleaned-up failure. Nullified if the repo is later destroyed. |
| 13 | t.references :repository, null: true, foreign_key: { on_delete: :nullify } |
| 14 | |
| 15 | t.string :source_url, null: false # normalized https git URL |
| 16 | t.string :source_host # e.g. "github.com" |
| 17 | t.string :mode, null: false, default: "migrate" # migrate | mirror |
| 18 | t.string :status, null: false, default: "queued" # see RepositoryImport::STATUSES |
| 19 | t.text :error_message |
| 20 | |
| 21 | # Target repo attributes captured up front so a retry is deterministic and |
| 22 | # doesn't depend on re-reading GitHub. |
| 23 | t.string :target_name, null: false |
| 24 | t.boolean :target_private, null: false, default: false |
| 25 | t.string :default_branch |
| 26 | t.text :description |
| 27 | |
| 28 | # Best-effort LFS accounting surfaced in the UI. |
| 29 | t.boolean :lfs_detected, null: false, default: false |
| 30 | t.boolean :lfs_skipped, null: false, default: false |
| 31 | |
| 32 | t.bigint :source_size_kb # reported by GitHub, for size caps |
| 33 | t.datetime :started_at |
| 34 | t.datetime :finished_at |
| 35 | |
| 36 | t.timestamps |
| 37 | end |
| 38 | |
| 39 | add_index :repository_imports, [ :user_id, :status ] |
| 40 | end |
| 41 | end |