Class: CreateActiveSagaTables

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/active_saga/install/templates/migrations/create_active_saga_tables.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
# File 'lib/generators/active_saga/install/templates/migrations/create_active_saga_tables.rb', line 4

def change
  create_table :as_executions do |t|
    t.string  :workflow_class, null: false
    t.string  :state, null: false
    t.text    :ctx, null: false
    t.string  :cursor_step
    t.string  :idempotency_key
    t.jsonb   :metadata, null: false, default: {}
    t.datetime :timeout_at
    t.string   :last_error_class
    t.text     :last_error_message
    t.datetime :last_error_at
    t.datetime :last_enqueued_at
    t.datetime :completed_at
    t.datetime :cancelled_at

    t.timestamps
  end

  add_index :as_executions, :workflow_class
  add_index :as_executions, :state
  add_index :as_executions, :idempotency_key, unique: true

  create_table :as_steps do |t|
    t.references :execution, null: false, foreign_key: { to_table: :as_executions }
    t.string  :name, null: false
    t.string  :style, null: false
    t.jsonb   :options, null: false, default: {}
    t.string  :state, null: false
    t.integer :position, null: false
    t.integer :attempts, null: false, default: 0
    t.datetime :scheduled_at
    t.datetime :waiting_since
    t.datetime :timeout_at
    t.datetime :started_at
    t.datetime :completed_at
    t.datetime :last_error_at
    t.string   :last_error_class
    t.text     :last_error_message
    t.jsonb    :last_error_details, null: false, default: {}
    t.text     :last_error_backtrace
    t.jsonb    :init_result
    t.jsonb    :completion_payload
    t.string   :completion_idempotency_key
    t.string   :correlation_id
    t.datetime :last_heartbeat_at

    t.timestamps
  end

  add_index :as_steps, [:execution_id, :position]
  add_index :as_steps, [:execution_id, :name]
  add_index :as_steps, [:execution_id, :completion_idempotency_key], unique: true, where: "completion_idempotency_key IS NOT NULL"

  create_table :as_events do |t|
    t.references :execution, null: false, foreign_key: { to_table: :as_executions }
    t.string  :name, null: false
    t.jsonb   :payload, null: false, default: {}
    t.datetime :consumed_at

    t.timestamps
  end

  add_index :as_events, [:execution_id, :name]
  add_index :as_events, [:execution_id, :name], where: "consumed_at IS NULL", name: "index_as_events_unconsumed"
end