Class: InstallChronoForge

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/chrono_forge/install/templates/install_chrono_forge.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/generators/chrono_forge/install/templates/install_chrono_forge.rb', line 4

def change
  create_table :chrono_forge_workflows, id: primary_key_type do |t|
    t.string :key, null: false, index: true
    t.string :job_class, null: false

    if t.respond_to?(:jsonb)
      t.jsonb :kwargs, null: false, default: {}
      t.jsonb :options, null: false, default: {}
      t.jsonb :context, null: false, default: {}
    else
      t.json :kwargs, null: false, default: {}
      t.json :options, null: false, default: {}
      t.json :context, null: false, default: {}
    end

    t.integer :state, null: false, default: 0
    t.string :locked_by
    t.datetime :locked_at

    t.datetime :started_at
    t.datetime :completed_at

    t.timestamps
    t.index %i[job_class key], unique: true
  end

  create_table :chrono_forge_execution_logs, id: primary_key_type do |t|
    t.references :workflow, null: false,
      foreign_key: {to_table: :chrono_forge_workflows},
      type: primary_key_type

    t.string :step_name, null: false
    t.integer :attempts, null: false, default: 0
    t.datetime :started_at
    t.datetime :last_executed_at
    t.datetime :completed_at

    if t.respond_to?(:jsonb)
      t.jsonb :metadata
    else
      t.json :metadata
    end

    t.integer :state, null: false, default: 0
    t.string :error_class
    t.text :error_message

    t.timestamps
    t.index %i[workflow_id step_name], unique: true
  end

  create_table :chrono_forge_error_logs, id: primary_key_type do |t|
    t.references :workflow, null: false,
      foreign_key: {to_table: :chrono_forge_workflows},
      type: primary_key_type

    t.string :error_class
    t.text :error_message
    t.text :backtrace

    if t.respond_to?(:jsonb)
      t.jsonb :context
    else
      t.json :context
    end

    t.timestamps
  end
end