scenic-cascade 0.3.1 → 0.4.0

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: 1dddf4e05de1c253c42eec7c88435f614b8b39debb51eb33b3f58d752b550451
4
- data.tar.gz: 2ea712e31ebb4f51948c4dfe5b907d4c6a236dabd74469380c91528fc2ac6f27
3
+ metadata.gz: f0a61489b23b4b1757128a51a42a282cf5160dd5ee370fd7022e90deb7137adc
4
+ data.tar.gz: 97b54d42d86066dc187edd11a772e2b2797201166be839e1ebdcee3d06e5ec92
5
5
  SHA512:
6
- metadata.gz: 335b36dc1ebdbf29b1cff211a5a0de70d2d21a1469120995f39abd4d519f9f40c88a08117f7b93da5e57eeeb6160a380721e251b7c114e8f90b7cb58fb4d691a
7
- data.tar.gz: f2def0555d395913de1285af40c232f34b70b9098bc7ad2a93abcca4f1f6c391229da3bbbf50bf83dc23915698e5251f223f954210b9b75fe4801e39494cd05c
6
+ metadata.gz: f360c29db6d494105b25cb3f4f2de0c022b603edcf8773c3cd4b25b0cfd8d5002bb3d19b797b8bc98b4b3a3878069faaf4536bd7b864b512d77985df46f11a24
7
+ data.tar.gz: 64973ffd675ba862946d3d8537eb93cd2c4d6eb4ef5c3831ff34ff7600cf836389ec5b51a97e9414e7804822ccc23b4bac02cb33d668478feed61005eef09a7e
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-11-05
11
+
12
+ ### Fixed
13
+
14
+ - Preserve index names and definitions on dependent materialized views when applying or reversing cascade migrations.
15
+
10
16
  ## [0.3.1] - 2026-11-05
11
17
 
12
18
  ### Fixed
@@ -72,7 +78,8 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
72
78
 
73
79
  - Initial release of the cascading Scenic view migration generator.
74
80
 
75
- [Unreleased]: https://github.com/akiomik/scenic-cascade/compare/v0.3.1...HEAD
81
+ [Unreleased]: https://github.com/akiomik/scenic-cascade/compare/v0.4.0...HEAD
82
+ [0.4.0]: https://github.com/akiomik/scenic-cascade/compare/v0.3.1...v0.4.0
76
83
  [0.3.1]: https://github.com/akiomik/scenic-cascade/compare/v0.3.0...v0.3.1
77
84
  [0.3.0]: https://github.com/akiomik/scenic-cascade/compare/v0.2.0...v0.3.0
78
85
  [0.2.0]: https://github.com/akiomik/scenic-cascade/compare/v0.1.5...v0.2.0
data/README.md CHANGED
@@ -75,22 +75,7 @@ $ bin/rails generate scenic:view:cascade first_results
75
75
  ```
76
76
 
77
77
  Since all dependencies are described, you can execute `bin/rails db:migrate` without changing the migration file.
78
-
79
- > [!WARNING]
80
- > Currently, index re-creation is not supported.
81
- > Please change a migration file to recreate indexes if it contains `drop_view` for materialized views.
82
-
83
- ```ruby
84
- class UpdateSearchResultsToVersion2 < ActiveRecord::Migration
85
- def change
86
- drop_view :third_results, revert_to_version: 2, materialized: false
87
- drop_view :second_results, revert_to_version: 3, materialized: true
88
- replace_view :first_results, version: 2, revert_to_version: 1
89
- create_view :second_results, version: 3, materialized: true
90
- create_view :third_results, version: 2, materialized: false
91
- end
92
- end
93
- ```
78
+ The migration drops `third_results` and `second_results`, updates `first_results`, then recreates the dependents in the opposite order. It captures indexes on `second_results` immediately before dropping it and recreates them after the materialized view is restored. The same happens when the migration is reversed.
94
79
 
95
80
  ## Development
96
81
 
@@ -15,6 +15,12 @@ class <%= migration_class_name %> < <%= activerecord_migration_class %>
15
15
  <%- materialized_options = materialized_flags.empty? ? 'true' : "{ #{materialized_flags.join(', ')} }" -%>
16
16
  def change
17
17
  <%- dependents.reverse_each do |dep| -%>
18
+ <%- if dep.materialized? -%>
19
+ reversible do |direction|
20
+ direction.up { capture_dependent_indexes(<%= dep.database_name.inspect %>) }
21
+ direction.down { restore_dependent_indexes(<%= dep.database_name.inspect %>) }
22
+ end
23
+ <%- end -%>
18
24
  <%- if dep.database_name == dep.name -%>
19
25
  drop_view ExactViewName.new(<%= dep.database_name.inspect %>),
20
26
  revert_to_version: <%= dep.version %>,
@@ -59,6 +65,30 @@ class <%= migration_class_name %> < <%= activerecord_migration_class %>
59
65
  end
60
66
  end
61
67
  <%- end -%>
68
+ <%- if dep.materialized? -%>
69
+ reversible do |direction|
70
+ direction.up { restore_dependent_indexes(<%= dep.database_name.inspect %>) }
71
+ direction.down { capture_dependent_indexes(<%= dep.database_name.inspect %>) }
72
+ end
73
+ <%- end -%>
62
74
  <%- end -%>
63
75
  end
76
+
77
+ <%- if dependents.any?(&:materialized?) -%>
78
+ private
79
+
80
+ def capture_dependent_indexes(name)
81
+ @dependent_indexes ||= {}
82
+ @dependent_indexes[name] = connection.select_values(<<~SQL)
83
+ SELECT pg_get_indexdef(indexrelid)
84
+ FROM pg_index
85
+ WHERE indrelid = to_regclass(#{connection.quote(name)})
86
+ ORDER BY indexrelid
87
+ SQL
88
+ end
89
+
90
+ def restore_dependent_indexes(name)
91
+ @dependent_indexes.fetch(name).each { |definition| execute(definition) }
92
+ end
93
+ <%- end -%>
64
94
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Scenic
4
4
  module Cascade
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scenic-cascade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akiomi Kamakura