wedding-planner/db/migrate/20241216231415_create_group_affinities.rb
Manuel Bustillo e20a366410
All checks were successful
Check usage of free licenses / check-licenses (pull_request) Successful in 56s
Add copyright notice / copyright_notice (pull_request) Successful in 1m36s
Run unit tests / unit_tests (pull_request) Successful in 3m56s
Build Nginx-based docker image / build-static-assets (pull_request) Successful in 28m26s
Update copyright assignment to cover 2025 and include all contributors
2025-01-13 21:37:02 +01:00

30 lines
1.0 KiB
Ruby

# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
class CreateGroupAffinities < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
def change
create_table :group_affinities, if_not_exists: true do |t|
t.references :group_a, type: :uuid, null: false, foreign_key: { to_table: :groups }
t.references :group_b, type: :uuid, null: false, foreign_key: { to_table: :groups }
t.float :discomfort, null: false
t.timestamps
end
add_check_constraint :group_affinities, 'group_a_id != group_b_id', name: :check_distinct_groups, if_not_exists: true
add_check_constraint :group_affinities, 'discomfort >= 0 AND discomfort <= 2', if_not_exists: true
reversible do |dir|
dir.up do
execute <<~SQL
CREATE UNIQUE INDEX CONCURRENTLY uindex_group_pair ON group_affinities (least(group_a_id, group_b_id), greatest(group_a_id, group_b_id));
SQL
end
dir.down do
remove_index :group_affinities, name: :uindex_group_pair, if_exists: true
end
end
end
end