Add VSA stage hashes organization_id foreign key
What does this MR do and why?
This change adds the foreign key to the organization_id
column in the analytics_cycle_analytics_stage_event_hashes
table. The MR also removes the default value from the column.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Migration
Up:
main: == [advisory_lock_connection] object_id: 128840, pg_backend_pid: 29342
main: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: migrating ======
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute("ALTER TABLE analytics_cycle_analytics_stage_event_hashes ADD CONSTRAINT fk_0839874e4f FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0009s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0003s
main: -- execute("ALTER TABLE analytics_cycle_analytics_stage_event_hashes VALIDATE CONSTRAINT fk_0839874e4f;")
main: -> 0.0008s
main: -- execute("RESET statement_timeout")
main: -> 0.0004s
main: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: migrated (0.0280s)
main: == [advisory_lock_connection] object_id: 128840, pg_backend_pid: 29342
ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 29344
ci: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: migrating ======
ci: -- transaction_open?(nil)
ci: -> 0.0000s
ci: -- transaction_open?(nil)
ci: -> 0.0000s
ci: -- execute("ALTER TABLE analytics_cycle_analytics_stage_event_hashes ADD CONSTRAINT fk_0839874e4f FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE NOT VALID;")
ci: -> 0.0007s
ci: -- execute("SET statement_timeout TO 0")
ci: -> 0.0004s
ci: -- execute("ALTER TABLE analytics_cycle_analytics_stage_event_hashes VALIDATE CONSTRAINT fk_0839874e4f;")
ci: -> 0.0008s
ci: -- execute("RESET statement_timeout")
ci: -> 0.0002s
ci: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: migrated (0.0223s)
ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 29344
main: == [advisory_lock_connection] object_id: 129400, pg_backend_pid: 29347
main: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: migrating ========
main: -- change_column_default(:analytics_cycle_analytics_stage_event_hashes, :organization_id, nil)
main: -> 0.0026s
main: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: migrated (0.0051s)
main: == [advisory_lock_connection] object_id: 129400, pg_backend_pid: 29347
ci: == [advisory_lock_connection] object_id: 129560, pg_backend_pid: 29349
ci: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: migrating ========
ci: -- change_column_default(:analytics_cycle_analytics_stage_event_hashes, :organization_id, nil)
ci: -> 0.0027s
ci: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: migrated (0.0097s)
ci: == [advisory_lock_connection] object_id: 129560, pg_backend_pid: 29349
Down:
main: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 27553
main: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: reverting ========
main: -- change_column_default(:analytics_cycle_analytics_stage_event_hashes, :organization_id, 1)
main: -> 0.0132s
main: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: reverted (0.0160s)
main: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 27553
ci: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 27984
ci: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: reverting ========
ci: -- change_column_default(:analytics_cycle_analytics_stage_event_hashes, :organization_id, 1)
ci: -> 0.0125s
ci: == 20240704111127 RemoveDefaultValueFromVsaStageHashesTable: reverted (0.0205s)
ci: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 27984
main: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 28551
main: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: reverting ======
main: -- remove_foreign_key(:analytics_cycle_analytics_stage_event_hashes, {:column=>:organization_id})
main: -> 0.0025s
main: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: reverted (0.0211s)
main: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 28551
ci: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 28940
ci: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: reverting ======
ci: -- remove_foreign_key(:analytics_cycle_analytics_stage_event_hashes, {:column=>:organization_id})
ci: -> 0.0036s
ci: == 20240704070311 AddStageEventHashesOrganizationIdForeignKey: reverted (0.0344s)
ci: == [advisory_lock_connection] object_id: 128340, pg_backend_pid: 28940
Related to #469775 (closed)
Edited by Adam Hegyi