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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f62004e4153d3351bda79f2cf1f09db95e42b83302d016909cbe7d8d081ef3ba
|
|
4
|
+
data.tar.gz: e005456aca83c931019db903ff6a860efff9111da2de5bbe35fe7021192e1f28
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/lib/statecraft/version.rb
CHANGED