dag_me 0.5.0 → 0.5.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: c1012817d36f748b2056aec9ea431941bccab8abb2f9e28bb6e1cf576dc40c87
4
- data.tar.gz: 18e716d54532f6a25605454dcc1ae08fe91d3e1f6c54dca5e39ede20a2fe8ba2
3
+ metadata.gz: 83c01ab2574e730c6ad4e8c48c33aec03cb55f3047d84a10ef85472ca84a3f29
4
+ data.tar.gz: d080b05511fb0a3ac754e2036232a2c732b335bfb1555d8cfc44d384109c3fac
5
5
  SHA512:
6
- metadata.gz: 43b71fef3c469db2e0fbeb5ee2b8831a8ae9553015d813c68cbe72004db61c25ca5154a71563579ca0100e4f7839c0553edaa706037906be9d8b7a84200532c2
7
- data.tar.gz: 05ef5140aa9a23e43f02414179a55ce9849b8b7809d1eb5923378bda3bacd1e3032ab89a73384081eefcc8a0d69011a3642c8f8e1e4cff7324618fedabed3f2a
6
+ metadata.gz: cea758b279576fea148ee0fe5a775684eb26daebb9788ecf42981d0864431bb5cd09b4133ffba181a8717c551e225cbc2cfc0bc53bcacec338d1fe2be595aef8
7
+ data.tar.gz: 35ed14cdef53553e85815f76d66097d61bae16d942b101ad3089db55c6ae9571015658a39e057fa77214dd1b16b7590596b6531c8f008f28bd917cd99f69f22b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.1](https://github.com/ClosureTree/dag_me/compare/v0.5.0...v0.5.1) (2026-10-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * name generator migrations after the full class path and pin refresh migrations to table options ([8da44c1](https://github.com/ClosureTree/dag_me/commit/8da44c1b2a38622e53e31494d4c95006ccfed2f3))
9
+
3
10
  ## [0.5.0](https://github.com/ClosureTree/dag_me/compare/v0.4.2...v0.5.0) (2026-10-06)
4
11
 
5
12
 
data/README.md CHANGED
@@ -335,9 +335,16 @@ needs a migration. Function bodies are stamped with `DagMe::DDL::REVISION`, and
335
335
  rails generate dag_me:refresh Mission
336
336
  ```
337
337
 
338
- The migration calls `DagMe::DDL.refresh!(Mission)`, which replaces every function body
339
- with `CREATE OR REPLACE` and reapplies the closure table's storage settings. Tables,
340
- triggers, and rows are left alone.
338
+ The migration replaces every function body with `CREATE OR REPLACE` and reapplies the
339
+ closure table's storage settings. Tables, triggers, and rows are left alone. It does not
340
+ reference `Mission`: each dag is pinned to its node table and options as declared when
341
+ you generate it, so the migration still runs after the model is renamed or removed:
342
+
343
+ ```ruby
344
+ def up
345
+ refresh "missions", maintain: :postgresql_closure, prefix: "mission_dag"
346
+ end
347
+ ```
341
348
 
342
349
  ## Testing your app's graphs
343
350
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DagMe
4
- VERSION = '0.5.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -13,7 +13,7 @@ module DagMe
13
13
  source_root File.expand_path('templates', __dir__)
14
14
 
15
15
  def create_migration_file
16
- migration_template 'install_dag.rb.erb', "db/migrate/install_dag_me_for_#{file_name.pluralize}.rb"
16
+ migration_template 'install_dag.rb.erb', "db/migrate/install_dag_me_for_#{table_name}.rb"
17
17
  end
18
18
 
19
19
  def self.next_migration_number(dirname)
@@ -11,14 +11,37 @@ module DagMe
11
11
  # Upgrades an installed graph's function bodies to the current
12
12
  # DagMe::DDL::REVISION. Named after the revision, so later refreshes
13
13
  # get their own migration.
14
+ #
15
+ # The migration pins each dag to its node table and options instead of
16
+ # naming the model: migrations replay long after a model is renamed or
17
+ # removed, and a missing constant would abort db:migrate.
14
18
  class RefreshGenerator < Rails::Generators::NamedBase
15
19
  include Rails::Generators::Migration
16
20
 
17
21
  source_root File.expand_path('templates', __dir__)
18
22
 
23
+ # Keyword arguments that rebuild +config+ on a stand-in model carrying
24
+ # only its table name (and composite key). The prefix is always pinned;
25
+ # table names only when they were overridden rather than derived.
26
+ def self.snapshot(config)
27
+ options = { primary_key: (config.node_pk_columns.map(&:to_sym) if config.composite_pk?),
28
+ name: config.name,
29
+ maintain: config.maintain,
30
+ scope: config.scope_columns.presence,
31
+ prefix: config.prefix }
32
+ options[:edge_table] = config.edge_table unless config.edge_table == config.qualify("#{config.prefix}_edges")
33
+ options[:paths_table] = config.paths_table unless config.paths_table == config.qualify("#{config.prefix}_paths")
34
+ options.compact
35
+ end
36
+
37
+ def check_dag_model
38
+ return if model.is_a?(Class) && model.include?(DagMe::Model)
39
+
40
+ raise Thor::Error, "#{class_name} is not a dag_me model (no dag_me call)"
41
+ end
42
+
19
43
  def create_migration_file
20
- migration_template 'refresh_dag.rb.erb',
21
- "db/migrate/refresh_dag_me_r#{revision}_for_#{file_name.pluralize}.rb"
44
+ migration_template 'refresh_dag.rb.erb', "db/migrate/refresh_dag_me_r#{revision}_for_#{table_name}.rb"
22
45
  end
23
46
 
24
47
  def self.next_migration_number(dirname)
@@ -27,6 +50,17 @@ module DagMe
27
50
 
28
51
  private
29
52
 
53
+ def model
54
+ @model ||= class_name.safe_constantize
55
+ end
56
+
57
+ def refresh_calls
58
+ model.dag_configs.each_value.map do |config|
59
+ args = self.class.snapshot(config).map { |key, value| "#{key}: #{value.inspect}" }
60
+ "refresh #{[config.node_table.inspect, *args].join(', ')}"
61
+ end
62
+ end
63
+
30
64
  def revision
31
65
  DagMe::DDL::REVISION
32
66
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class InstallDagMeFor<%= class_name.pluralize %> < ActiveRecord::Migration<%= migration_version %>
3
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
4
4
  def up
5
5
  DagMe::DDL.install!(<%= class_name %>)
6
6
  end
@@ -1,9 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class RefreshDagMeR<%= revision %>For<%= class_name.pluralize %> < ActiveRecord::Migration<%= migration_version %>
4
- # Replaces dag_me's function bodies with revision <%= revision %>.
5
- # Tables, triggers, and rows are left alone.
3
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
4
+ # Replaces dag_me's function bodies for <%= class_name %> with revision <%= revision %>.
5
+ # Tables, triggers, and rows are left alone. Each dag is pinned to its node
6
+ # table and options, so renaming the model cannot break this migration.
6
7
  def up
7
- DagMe::DDL.refresh!(<%= class_name %>)
8
+ <% refresh_calls.each do |call| -%>
9
+ <%= call %>
10
+ <% end -%>
11
+ end
12
+
13
+ private
14
+
15
+ def refresh(table, primary_key: nil, **options)
16
+ node = Class.new(ActiveRecord::Base) { self.table_name = table }
17
+ node.primary_key = primary_key if primary_key
18
+ DagMe::DDL.new(DagMe::Configuration.new(model: node, **options)).refresh!
8
19
  end
9
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dag_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 4.0.20
93
+ rubygems_version: 4.0.10
94
94
  specification_version: 4
95
95
  summary: Multi-parent DAGs for ActiveRecord, powered by PostgreSQL 18+
96
96
  test_files: []