Files
ubicloud/migrate/20231208_drop_pg_foreign_key_constraints.rb
Burak Yucesoy 5dc3d6dbaa Drop foreign key constraints in PostgresResource and PostgresTimeline
Both of these tables has parent_id column referencing themselves. They are used
in forks to refer the parent PostgresResource and PostgresTimeline. Foreign key
constraints prevents deletion of the parent entity while the child entity is
still around, so we are removing the constraint.
2023-12-08 13:23:50 +01:00

26 lines
596 B
Ruby

# frozen_string_literal: true
Sequel.migration do
# When column names are passed in array form, Sequel only drops or creates
# the constraint, without touching to the column itself.
up do
alter_table(:postgres_resource) do
drop_foreign_key [:parent_id]
end
alter_table(:postgres_timeline) do
drop_foreign_key [:parent_id]
end
end
down do
alter_table(:postgres_resource) do
add_foreign_key([:parent_id], :postgres_resource)
end
alter_table(:postgres_timeline) do
add_foreign_key([:parent_id], :postgres_timeline)
end
end
end