scenic-cascade 0.3.0 → 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 +4 -4
- data/CHANGELOG.md +15 -1
- data/README.md +1 -16
- data/lib/generators/scenic/view/cascade/templates/db/migrate/update_view.rb.erb +30 -0
- data/lib/scenic/cascade/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f0a61489b23b4b1757128a51a42a282cf5160dd5ee370fd7022e90deb7137adc
|
|
4
|
+
data.tar.gz: 97b54d42d86066dc187edd11a772e2b2797201166be839e1ebdcee3d06e5ec92
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f360c29db6d494105b25cb3f4f2de0c022b603edcf8773c3cd4b25b0cfd8d5002bb3d19b797b8bc98b4b3a3878069faaf4536bd7b864b512d77985df46f11a24
|
|
7
|
+
data.tar.gz: 64973ffd675ba862946d3d8537eb93cd2c4d6eb4ef5c3831ff34ff7600cf836389ec5b51a97e9414e7804822ccc23b4bac02cb33d668478feed61005eef09a7e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ 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
|
+
|
|
16
|
+
## [0.3.1] - 2026-11-05
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Include runtime code and type signatures when building the gem from a source archive without Git metadata.
|
|
21
|
+
|
|
10
22
|
## [0.3.0] - 2026-11-05
|
|
11
23
|
|
|
12
24
|
### Changed
|
|
@@ -66,7 +78,9 @@ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.ht
|
|
|
66
78
|
|
|
67
79
|
- Initial release of the cascading Scenic view migration generator.
|
|
68
80
|
|
|
69
|
-
[Unreleased]: https://github.com/akiomik/scenic-cascade/compare/v0.
|
|
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
|
|
83
|
+
[0.3.1]: https://github.com/akiomik/scenic-cascade/compare/v0.3.0...v0.3.1
|
|
70
84
|
[0.3.0]: https://github.com/akiomik/scenic-cascade/compare/v0.2.0...v0.3.0
|
|
71
85
|
[0.2.0]: https://github.com/akiomik/scenic-cascade/compare/v0.1.5...v0.2.0
|
|
72
86
|
[0.1.5]: https://github.com/akiomik/scenic-cascade/compare/v0.1.4...v0.1.5
|
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
|