2023-09-25 17:24:50 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AddRepositoryRowConnections < ActiveRecord::Migration[7.0]
|
|
|
|
def change
|
|
|
|
create_table :repository_row_connections do |t|
|
2024-01-08 19:01:06 +08:00
|
|
|
t.references :parent, index: true, foreign_key: { to_table: :repository_rows }, null: false
|
|
|
|
t.references :child, index: true, foreign_key: { to_table: :repository_rows }, null: false
|
2023-09-25 17:24:50 +08:00
|
|
|
t.references :created_by, foreign_key: { to_table: :users }
|
|
|
|
t.references :last_modified_by, foreign_key: { to_table: :users }
|
|
|
|
|
|
|
|
t.timestamps
|
|
|
|
end
|
|
|
|
|
|
|
|
change_table :repository_rows, bulk: true do |t|
|
|
|
|
t.integer :parent_connections_count
|
|
|
|
t.integer :child_connections_count
|
|
|
|
end
|
2024-01-08 19:01:06 +08:00
|
|
|
|
|
|
|
add_index :repository_row_connections,
|
|
|
|
'LEAST(parent_id, child_id), GREATEST(parent_id, child_id)',
|
|
|
|
name: 'index_repository_row_connections_on_connection_pair',
|
|
|
|
unique: true
|
|
|
|
add_check_constraint :repository_row_connections, 'parent_id != child_id',
|
|
|
|
name: 'constraint_repository_row_connections_on_self_connection'
|
2023-09-25 17:24:50 +08:00
|
|
|
end
|
|
|
|
end
|