statecraft 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0c939e1b5d335a23df4ee4bdd3fc9f5ac5a1d42e53c1bec2d8b5b8c3bc8dde8
4
- data.tar.gz: 2dc1c3391139562722cd1b6cfed0e7827582b06254fec0b9b8e24680b2d16e37
3
+ metadata.gz: f62004e4153d3351bda79f2cf1f09db95e42b83302d016909cbe7d8d081ef3ba
4
+ data.tar.gz: e005456aca83c931019db903ff6a860efff9111da2de5bbe35fe7021192e1f28
5
5
  SHA512:
6
- metadata.gz: 40f3727eb9fc1acddcff7c95c9dce6783633175b0ee2bc7b78013ed5d5f45556b8cb9cff1cecbd54916449d38a2071796b28fbfc4f2dea40d7af4fb51019c743
7
- data.tar.gz: ad2778897f1c4609f6c01b3c3e8129fa329da6dcbc131641ccc153f21bfc94a261754c142b086941d3a9a57aca68eafa03f4039ca1a2ad1fe23f1e06706b8649
6
+ metadata.gz: 8c8bd36f37d3c0392cfc4c17562f071f66e8e3252253e2237bc84283418dea222db32327e30aab4f3cd10b408e37852f6cddf3f93171a026194f1a6787f26c83
7
+ data.tar.gz: f1a14781c925c5bc72da7e7120fc8e1e0a4809b17f36f03f8e55b72e6a8a1163056b730804bb871d0961d1139428bd1084cffa5437f03847674e1dd49c989c9d
@@ -32,6 +32,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
32
32
 
33
33
  def convert_parent_table
34
34
  add_column :<%= table_name %>, :state, :string
35
+ add_column :<%= table_name %>, :state_changed_at, :datetime
35
36
 
36
37
  # The current state is the to_state of the LAST transition by sort_key —
37
38
  # deliberately not most_recent, which statesman itself ships a repair
@@ -45,6 +46,16 @@ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Mi
45
46
  )
46
47
  SQL
47
48
 
49
+ # The mounting says changed_at: true, so the column must exist — and the
50
+ # conversion knows the honest value: the moment of the last recorded
51
+ # transition. Rows that never transitioned stay NULL, exactly like a
52
+ # freshly created record.
53
+ execute <<~SQL
54
+ UPDATE <%= table_name %> SET state_changed_at =
55
+ (SELECT MAX(t.created_at) FROM <%= log_table_name %> t
56
+ WHERE t.<%= foreign_key_column %> = <%= table_name %>.id)
57
+ SQL
58
+
48
59
  change_column_default :<%= table_name %>, :state, "<%= initial_state %>"
49
60
  change_column_null :<%= table_name %>, :state, false
50
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Statecraft
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statecraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Pugachev