Skip to content

Commit

Permalink
Fix warnings from 018 migration differently
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Jan 26, 2024
1 parent 83d2ad9 commit 7144555
Showing 1 changed file with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,62 +1,67 @@
# frozen_string_literal: true
helper = Object.new
def helper.to_uuid(table_name, column_name)
set_column_type(table_name, column_name, :uuid, :using => "#{column_name}::uuid")
end

def helper.from_uuid(table_name, column_name)
set_column_type table_name, column_name, String, primary_key: true, size: 36, fixed: true
end

def helper.with_foreign_key_recreation(&block)
# Drop the foreign key constraints so we can change the column type
alter_table :dynflow_actions do
drop_foreign_key [:execution_plan_uuid]
end
alter_table :dynflow_steps do
drop_foreign_key [:execution_plan_uuid]
drop_foreign_key [:execution_plan_uuid, :action_id], :name => :dynflow_steps_execution_plan_uuid_fkey1
helper = Module.new do
def to_uuid(table_name, column_name)
set_column_type(table_name, column_name, :uuid, :using => "#{column_name}::uuid")
end
alter_table :dynflow_delayed_plans do
drop_foreign_key [:execution_plan_uuid]

def from_uuid(table_name, column_name)
set_column_type table_name, column_name, String, primary_key: true, size: 36, fixed: true
end

block.call
def with_foreign_key_recreation(&block)
# Drop the foreign key constraints so we can change the column type
alter_table :dynflow_actions do
drop_foreign_key [:execution_plan_uuid]
end
alter_table :dynflow_steps do
drop_foreign_key [:execution_plan_uuid]
drop_foreign_key [:execution_plan_uuid, :action_id], :name => :dynflow_steps_execution_plan_uuid_fkey1
end
alter_table :dynflow_delayed_plans do
drop_foreign_key [:execution_plan_uuid]
end

# Recreat the foreign key constraints as they were before
alter_table :dynflow_actions do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans
end
alter_table :dynflow_steps do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans
add_foreign_key [:execution_plan_uuid, :action_id], :dynflow_actions,
:name => :dynflow_steps_execution_plan_uuid_fkey1
end
alter_table :dynflow_delayed_plans do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans,
:name => :dynflow_scheduled_plans_execution_plan_uuid_fkey
block.call

# Recreat the foreign key constraints as they were before
alter_table :dynflow_actions do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans
end
alter_table :dynflow_steps do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans
add_foreign_key [:execution_plan_uuid, :action_id], :dynflow_actions,
:name => :dynflow_steps_execution_plan_uuid_fkey1
end
alter_table :dynflow_delayed_plans do
add_foreign_key [:execution_plan_uuid], :dynflow_execution_plans,
:name => :dynflow_scheduled_plans_execution_plan_uuid_fkey
end
end
end

Sequel.migration do
up do
if database_type.to_s.include?('postgres')
helper.with_foreign_key_recreation do
helper.to_uuid :dynflow_execution_plans, :uuid
helper.to_uuid :dynflow_actions, :execution_plan_uuid
helper.to_uuid :dynflow_steps, :execution_plan_uuid
helper.to_uuid :dynflow_delayed_plans, :execution_plan_uuid
Sequel::Postgres::Database.include helper

with_foreign_key_recreation do
to_uuid :dynflow_execution_plans, :uuid
to_uuid :dynflow_actions, :execution_plan_uuid
to_uuid :dynflow_steps, :execution_plan_uuid
to_uuid :dynflow_delayed_plans, :execution_plan_uuid
end
end
end

down do
if database_type.to_s.include?('postgres')
helper.with_foreign_key_recreation do
helper.from_uuid :dynflow_execution_plans, :uuid
helper.from_uuid :dynflow_actions, :execution_plan_uuid
helper.from_uuid :dynflow_steps, :execution_plan_uuid
helper.from_uuid :dynflow_delayed_plans, :execution_plan_uuid
Sequel::Postgres::Database.include helper

with_foreign_key_recreation do
from_uuid :dynflow_execution_plans, :uuid
from_uuid :dynflow_actions, :execution_plan_uuid
from_uuid :dynflow_steps, :execution_plan_uuid
from_uuid :dynflow_delayed_plans, :execution_plan_uuid
end
end
end
Expand Down

0 comments on commit 7144555

Please sign in to comment.