class Object
Constants
- TABLES
Public Instance Methods
conditions_for_row(table, row)
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/022_store_flows_as_msgpack.rb, line 25 def conditions_for_row(table, row) row.slice(*table_pkeys(table)) end
from_uuid(table_name, column_name)
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/018_add_uuid_column.rb, line 6 def from_uuid(table_name, column_name) set_column_type table_name, column_name, String, primary_key: true, size: 36, fixed: true end
migrate_table(table, from_names, to_names, new_type) { |row| ... }
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/022_store_flows_as_msgpack.rb, line 29 def migrate_table(table, from_names, to_names, new_type) alter_table(table) do to_names.each do |new| add_column new, new_type end end relevant_columns = table_pkeys(table) | from_names from(table).select(*relevant_columns).each do |row| update = from_names.zip(to_names).reduce({}) do |acc, (from, to)| row[from].nil? ? acc : acc.merge(to => yield(row[from])) end next if update.empty? from(table).where(conditions_for_row(table, row)).update(update) end from_names.zip(to_names).each do |old, new| alter_table(table) do drop_column old end if database_type == :mysql type = new_type == File ? 'blob' : 'mediumtext' run "ALTER TABLE #{table} CHANGE COLUMN `#{new}` `#{old}` #{type};" else rename_column table, new, old end end end
table_pkeys(table)
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/022_store_flows_as_msgpack.rb, line 6 def table_pkeys(table) case table when :dynflow_execution_plans [:uuid] when :dynflow_actions, :dynflow_steps [:execution_plan_uuid, :id] when :dynflow_coordinator_records [:id, :class] when :dynflow_delayed_plans [:execution_plan_uuid] when :dynflow_envelopes [:id] when :dynflow_output_chunks [:chunk] else raise "Unknown table '#{table}'" end end
to_uuid(table_name, column_name)
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/018_add_uuid_column.rb, line 2 def to_uuid(table_name, column_name) set_column_type(table_name, column_name, :uuid, :using => "#{column_name}::uuid") end
with_foreign_key_recreation(&block)
click to toggle source
# File lib/dynflow/persistence_adapters/sequel_migrations/018_add_uuid_column.rb, line 10 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 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