Class: AddProcessIdToDuctworkExecution

Inherits:
Ductwork::Migration show all
Defined in:
lib/generators/ductwork/update/templates/db/add_process_id_to_ductwork_executions.rb

Instance Method Summary collapse

Methods included from Ductwork::MigrationHelper

#belongs_to, #create_ductwork_table, #mysql?, #postgresql?, #uuid_column_type

Instance Method Details

#downObject



29
30
31
32
33
34
# File 'lib/generators/ductwork/update/templates/db/add_process_id_to_ductwork_executions.rb', line 29

def down
  remove_reference :ductwork_executions,
                   :process,
                   foreign_key: { to_table: :ductwork_processes },
                   index: true
end

#upObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generators/ductwork/update/templates/db/add_process_id_to_ductwork_executions.rb', line 4

def up
  options = if postgresql?
              {
                type: uuid_column_type,
                index: true,
                null: true,
                foreign_key: { to_table: :ductwork_processes },
              }
            else
              {
                type: uuid_column_type,
                limit: 36,
                index: true,
                null: true,
                foreign_key: { to_table: :ductwork_processes },
              }
            end

  add_reference :ductwork_executions, :process, **options

  Ductwork::Execution.find_each do |execution|
    execution.update!(process: execution.availability.process)
  end
end