Skip to content

Commit

Permalink
use create_table instead of create_join_table
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenhinkle committed Apr 8, 2024
1 parent 48ecf31 commit 3e9e00a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions db/migrate/20240405184242_create_orgs_reps_tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,30 @@ def change
add_index :accredited_organizations, :location, using: :gist
add_index :accredited_organizations, :name

create_join_table :accredited_organizations, :accredited_representatives do |t|
t.index :accredited_organization_id
t.index :accredited_representative_id
# Use create_table (instead of create_join_table) to explicitly define the table and its columns
create_table :accredited_organizations_accredited_representatives, id: false do |t|
t.uuid :accredited_organization_id
t.uuid :accredited_representative_id
end

# Add the indexes
add_index :accredited_organizations_accredited_representatives, :accredited_organization_id
add_index :accredited_organizations_accredited_representatives, :accredited_representative_id
add_index :accredited_organizations_accredited_representatives,
%i[accredited_organization_id accredited_representative_id],
[:accredited_organization_id, :accredited_representative_id],
unique: true,
name: 'index_organization_representatives_on_rep_and_org',
algorithm: :concurrently

# Add the foreign keys
add_foreign_key :accredited_organizations_accredited_representatives, :accredited_representatives,
column: :accredited_representative_id,
validate: false
add_foreign_key :accredited_organizations_accredited_representatives, :accredited_organizations,
column: :accredited_organization_id,
validate: false

# Validate the foreign keys
validate_foreign_key :accredited_organizations_accredited_representatives, :accredited_representatives
validate_foreign_key :accredited_organizations_accredited_representatives, :accredited_organizations
end
Expand Down

0 comments on commit 3e9e00a

Please sign in to comment.