partition_gardener 0.3.7 → 0.3.8
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 +4 -0
- data/docs/THIRD_PARTY_LICENSE_MANIFEST.tsv +2 -2
- data/docs/changelogs/20261105085411_hot-switch-migration-connection-stack-overflow.md +24 -0
- data/docs/changelogs/20261105090326_cut-patch-release-0-3-8.md +27 -0
- data/docs/issues/20261105085411_hot-switch-migration-connection-stack-overflow.md +30 -0
- data/docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md +38 -0
- data/docs/reviews/20261105090507_engineering-audit-release-preparation.md +42 -0
- data/lib/partition_gardener/migration/hot_switch_concern.rb +33 -28
- data/lib/partition_gardener/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ebf369d2fcab7b189d2c99e1ac2e55bc1c280c8a02db75c81bd1ecd60c0d841
|
|
4
|
+
data.tar.gz: b41d5c9be9577411d70855566d21d4db12acbb2f4003633223e33932d119f6a8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 870391d868e46568da268ff1ff6b5950eb6461790af61cb03f91caaf7f0cae76e9ac1db83c9098d6ba6184be2530c1cf0c7b37bcf0278cb92e4a415626d7c37e
|
|
7
|
+
data.tar.gz: b7f6894465691e62f3c80290a350beebd553ab43be0e666fcd4a8c25dd906e33641f2dbef8ebd2178c9ce8dabc81dc4dfb09bee5628bcee6a05e65a184072042
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.3.8 (2026-11-05)
|
|
6
|
+
|
|
7
|
+
- Fix hot-switch migrations aborting with `SystemStackError` when included into `ActiveRecord::Migration` on Rails 8 (private `connection` override recursed through `DefaultStrategy`)
|
|
8
|
+
|
|
5
9
|
## 0.3.7 (2026-10-29)
|
|
6
10
|
|
|
7
11
|
- Fix rebalance resume so phase `detach` still runs detach and drain until the record advances to `segments`
|
|
@@ -19,13 +19,13 @@ root logger 1.7.0 Ruby|BSD-2-Clause
|
|
|
19
19
|
root minitest 6.0.6 MIT
|
|
20
20
|
root parallel 2.3.0 MIT
|
|
21
21
|
root parser 3.3.13.0 MIT
|
|
22
|
-
root partition_gardener 0.3.
|
|
22
|
+
root partition_gardener 0.3.8 MIT
|
|
23
23
|
root pg 1.6.3 BSD-2-Clause
|
|
24
24
|
root polyrun 2.2.5 MIT
|
|
25
25
|
root prism 1.9.0 MIT
|
|
26
26
|
root prosopite 2.2.0 Apache-2.0
|
|
27
27
|
root racc 1.8.1 Ruby|BSD-2-Clause
|
|
28
|
-
root rack 3.2.
|
|
28
|
+
root rack 3.2.8 MIT
|
|
29
29
|
root rainbow 3.1.1 MIT
|
|
30
30
|
root rake 13.4.2 MIT
|
|
31
31
|
root rbs 4.2.0 BSD-2-Clause|Ruby
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Hot-switch migrations including HotSwitchConcern could stack-overflow on Rails 8 when any Migration DSL method ran through DefaultStrategy.
|
|
2
|
+
|
|
3
|
+
## Participants
|
|
4
|
+
|
|
5
|
+
Andrei Makarov (@amkisko)
|
|
6
|
+
|
|
7
|
+
## Decisions
|
|
8
|
+
|
|
9
|
+
- Rename the concern's connection helper to gardener_connection so ActiveRecord::Migration#connection stays public.
|
|
10
|
+
- Keep hot-switch SQL on gardener_connection.execute (configured resolver), not Migration#execute.
|
|
11
|
+
|
|
12
|
+
## Effects
|
|
13
|
+
|
|
14
|
+
- SystemStackError with repeating `-- connection(nil)` no longer occurs for create_table after include.
|
|
15
|
+
- Cut into CHANGELOG under `## 0.3.8 (2026-11-05)`.
|
|
16
|
+
|
|
17
|
+
## Next
|
|
18
|
+
|
|
19
|
+
- Commit, tag `0.3.8`, push, and run `make release`.
|
|
20
|
+
|
|
21
|
+
## Source
|
|
22
|
+
|
|
23
|
+
- docs/issues/20261105085411_hot-switch-migration-connection-stack-overflow.md
|
|
24
|
+
- docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Cut patch release 0.3.8
|
|
2
|
+
|
|
3
|
+
## Participants
|
|
4
|
+
|
|
5
|
+
Andrei Makarov (@amkisko)
|
|
6
|
+
|
|
7
|
+
## Decisions
|
|
8
|
+
|
|
9
|
+
- Bump `PartitionGardener::VERSION` to `0.3.8`.
|
|
10
|
+
- Record the Rails 8 hot-switch `SystemStackError` fix in `CHANGELOG.md` under `## 0.3.8 (2026-11-05)`.
|
|
11
|
+
- Stay on `main`. No trunk branch.
|
|
12
|
+
|
|
13
|
+
## Effects
|
|
14
|
+
|
|
15
|
+
- Moved the Unreleased note into the 0.3.8 section.
|
|
16
|
+
- Synced path-gem lockfile versions to 0.3.8.
|
|
17
|
+
|
|
18
|
+
## Next
|
|
19
|
+
|
|
20
|
+
- Commit the prepared tree on `main`, tag `0.3.8`, push, and run `make release` (gem push, tag push, GitHub release).
|
|
21
|
+
|
|
22
|
+
## Source
|
|
23
|
+
|
|
24
|
+
- Fix note: `docs/changelogs/20261105085411_hot-switch-migration-connection-stack-overflow.md`
|
|
25
|
+
- Issue: `docs/issues/20261105085411_hot-switch-migration-connection-stack-overflow.md`
|
|
26
|
+
- Review: `docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md`
|
|
27
|
+
- `CHANGELOG.md`, `lib/partition_gardener/version.rb`
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Hot-switch migrations that include HotSwitchConcern abort with SystemStackError on Rails 8 while printing many `-- connection(nil)` lines. Local RANGE partition DDL can succeed; the failure is in the migration connection path.
|
|
2
|
+
|
|
3
|
+
## Participants
|
|
4
|
+
|
|
5
|
+
Andrei Makarov (@amkisko)
|
|
6
|
+
|
|
7
|
+
## Decisions
|
|
8
|
+
|
|
9
|
+
- Stop overriding ActiveRecord::Migration#connection from HotSwitchConcern.
|
|
10
|
+
- Route hot-switch SQL through a private gardener_connection helper and adapter execute, so Strong Migrations still does not see Migration#execute.
|
|
11
|
+
- Prefer Migration @connection when present (multi-db migrate scope); otherwise use PartitionGardener.configuration.connection.
|
|
12
|
+
- Keep Migration#connection public so DefaultStrategy can resolve the adapter without entering method_missing recursion.
|
|
13
|
+
|
|
14
|
+
## Effects
|
|
15
|
+
|
|
16
|
+
- Reproduced before the fix: including HotSwitchConcern, then create_table or execution_strategy.respond_to?(:create_table), overflows through DefaultStrategy#connection -> Migration#method_missing -> respond_to_missing? -> connection again.
|
|
17
|
+
- After the fix: same path completes; Migration#connection owner stays ActiveRecord::Migration.
|
|
18
|
+
- Spec coverage added for the non-recursion contract; focused hot-switch specs pass on Rails 7.2 and Rails 8.1 appraisals.
|
|
19
|
+
|
|
20
|
+
## Next
|
|
21
|
+
|
|
22
|
+
- Publish `0.3.8` (`make release` after commit and clean tree).
|
|
23
|
+
- Host apps pinned on 0.3.7 need `0.3.8` or an equivalent local patch before hot-switch cutover migrations that also use Migration DSL.
|
|
24
|
+
|
|
25
|
+
## Source
|
|
26
|
+
|
|
27
|
+
- lib/partition_gardener/migration/hot_switch_concern.rb
|
|
28
|
+
- activerecord migration DefaultStrategy#connection
|
|
29
|
+
- docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md
|
|
30
|
+
- docs/changelogs/20261105085411_hot-switch-migration-connection-stack-overflow.md
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Engineering audit of HotSwitchConcern connection handling after a reported SystemStackError on Rails 8 multi-database migrate.
|
|
2
|
+
|
|
3
|
+
## Participants
|
|
4
|
+
|
|
5
|
+
Andrei Makarov (@amkisko)
|
|
6
|
+
|
|
7
|
+
## Decisions
|
|
8
|
+
|
|
9
|
+
- Claims from the incident note were checked only against this repository and installed ActiveRecord 8.1 sources; no consumer app tree was opened.
|
|
10
|
+
- Root cause is a private connection method on HotSwitchConcern that shadows Migration#connection. DefaultStrategy calls migration.connection with an explicit receiver; that hits Migration#method_missing, which asks execution_strategy.respond_to?, which calls connection again.
|
|
11
|
+
- The `-- connection(nil)` spam is Rails format_arguments on an empty argument list (last is nil), not a literal nil argument from the host.
|
|
12
|
+
- connected_to_stack can appear when the configured resolver calls ActiveRecord::Base.connection; it is on the stack, not the recursion engine.
|
|
13
|
+
- Multi-database migrate context is where the host hit the bug; the overflow reproduces without a second database once the concern is included and Migration DSL runs.
|
|
14
|
+
- schema.rb dropping PARTITION BY is a separate Rails schema dump limitation; out of scope for this connection fix.
|
|
15
|
+
- Boundary and control mode skipped: library SQL helpers, no physical actuators.
|
|
16
|
+
- Product-surface, privacy, learned-systems, lineage modes skipped: no person-facing product surface in this change.
|
|
17
|
+
- Resource and budget: overflow is unbounded stack growth until SystemStackError; fix removes the recursive path (measured: create_table completes after fix).
|
|
18
|
+
- Trace and identification: verbose migration lines are local process stdout only; no new identifiers emitted by the fix.
|
|
19
|
+
|
|
20
|
+
## Effects
|
|
21
|
+
|
|
22
|
+
- Finding F1 confirmed and fixed: private connection override vs DefaultStrategy recursion.
|
|
23
|
+
- Finding F2 confirmed and fixed: gardener_connection prefers Migration @connection when exec_migration set it, else configuration.connection_resolver, so multi-db migrate SQL stays on the migration-scoped adapter.
|
|
24
|
+
- Regression specs added; rails8ruby34 and rails72 focused suites green for hot_switch_concern_spec.
|
|
25
|
+
- Second pass: no other HotSwitchConcern methods shadow Migration DSL entry points (execute, transaction, say).
|
|
26
|
+
|
|
27
|
+
## Next
|
|
28
|
+
|
|
29
|
+
- Publish `0.3.8` after commit on a clean tree (`make release`).
|
|
30
|
+
- Cutover docs do not imply overriding `Migration#connection`; no doc change required for this fix.
|
|
31
|
+
|
|
32
|
+
## Source
|
|
33
|
+
|
|
34
|
+
- lib/partition_gardener/migration/hot_switch_concern.rb
|
|
35
|
+
- lib/partition_gardener/rails.rb
|
|
36
|
+
- lib/partition_gardener/configuration.rb
|
|
37
|
+
- spec/partition_gardener/migration/hot_switch_concern_spec.rb
|
|
38
|
+
- activerecord-8.1.3 lib/active_record/migration/default_strategy.rb
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Engineering audit and release preparation
|
|
2
|
+
|
|
3
|
+
## Participants
|
|
4
|
+
|
|
5
|
+
Andrei Makarov (@amkisko)
|
|
6
|
+
|
|
7
|
+
## Decisions
|
|
8
|
+
|
|
9
|
+
- Continue on main while preserving uncommitted work. Do not commit, tag, push, or publish in this session.
|
|
10
|
+
- Cut patch release version 0.3.8 for the Rails 8 hot-switch `SystemStackError` fix. Set the CHANGELOG heading date to 2026-11-05.
|
|
11
|
+
- Re-check lint, executable coverage, workflow YAML parse, package boundaries, and cold-require cost after the cut.
|
|
12
|
+
|
|
13
|
+
## Effects
|
|
14
|
+
|
|
15
|
+
- Bump `PartitionGardener::VERSION` and path-gem lockfiles to 0.3.8. Move the Unreleased bullet under `## 0.3.8 (2026-11-05)`.
|
|
16
|
+
- Fix rubocop offenses in `hot_switch_concern_spec` introduced by the connection helper rewrite (`RSpec/InstanceVariable`, `Layout/EmptyLineBetweenDefs`).
|
|
17
|
+
- Final serial JSON report: 190 examples, 0 failures with `INTEGRATION=1` and PostgreSQL on port 5432; no pending examples. Parallel polyrun with five workers: exit 0.
|
|
18
|
+
- Required project checks passed: rubocop (116 files, no offenses), rbs validate, `INTEGRATION=1` polyrun parallel-rspec. Environment: Ruby 4.0.2, `BUNDLE_PATH=vendor/bundle`.
|
|
19
|
+
- `release_spec`: 2 examples, 0 failures.
|
|
20
|
+
- Build the gem, verify it with `Gem::Package#verify`, and confirm the changelog heading matches version 0.3.8. Compressed package: 121344 bytes; source payload: 421347 bytes across 109 packaged paths. These are compressed versus uncompressed sizes, not interchangeable quantities.
|
|
21
|
+
- Cold process measurement on macOS arm64 with `/usr/bin/time -p` and `bundle exec ruby -Ilib`: 0.18 CPU seconds, 0.26 elapsed seconds. Peak RSS via `/usr/bin/time -l`: 31293440 bytes. Local smoke ceilings: 1 MiB compressed gem, 128 MiB RSS, 2 CPU seconds. Measured gem size, RSS, and CPU fit those ceilings. CPU seconds are the energy proxy; electricity use was not measured.
|
|
22
|
+
- Parse every workflow YAML, verify lockfile own-gem versions at 0.3.8, and run `git diff --check`. All passed.
|
|
23
|
+
|
|
24
|
+
## Next
|
|
25
|
+
|
|
26
|
+
- Commit, tag 0.3.8, push, and publish remain operator steps; this session did not run them. When the tree is clean, `make release` runs gem push, tag, and GitHub release.
|
|
27
|
+
- Hosted GitHub Actions and the complete supported Ruby/framework matrix were not executed locally beyond the default Gemfile path used by `make test`.
|
|
28
|
+
- Scope limits: production traffic, production database size and query plans, external service retention, and co-located resource interference were not measured. The local byte/CPU results do not establish those properties.
|
|
29
|
+
- Trace review follows local file/log and protocol emissions. No live customer identities or credentials were used. Data retention and deletion in embedding applications remain host contracts.
|
|
30
|
+
- Learned-system training/evaluation and cloud deployment modes do not apply to this library tree. Database-boundary mode applies to PostgreSQL maintenance DDL and hot-switch migration SQL. The library has no independent production health endpoint to assess.
|
|
31
|
+
|
|
32
|
+
## Source
|
|
33
|
+
|
|
34
|
+
- AGENTS.md
|
|
35
|
+
- .agents/skills/engineering-audit/SKILL.md
|
|
36
|
+
- .agents/skills/changelog-update/SKILL.md
|
|
37
|
+
- CHANGELOG.md
|
|
38
|
+
- Makefile
|
|
39
|
+
- spec/README.md
|
|
40
|
+
- docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md
|
|
41
|
+
- docs/changelogs/20261105090326_cut-patch-release-0-3-8.md
|
|
42
|
+
- docs/changelogs/20261105085411_hot-switch-migration-connection-stack-overflow.md
|
|
@@ -42,7 +42,7 @@ module PartitionGardener
|
|
|
42
42
|
|
|
43
43
|
all_months.each do |identifier|
|
|
44
44
|
partition_name = partition_name_format.call(identifier).gsub(/^#{current_table}_/, "#{partitioned_table}_")
|
|
45
|
-
next if
|
|
45
|
+
next if gardener_connection.table_exists?(partition_name)
|
|
46
46
|
|
|
47
47
|
for_values_clause = partition_definition.call(identifier)
|
|
48
48
|
sql = <<~SQL
|
|
@@ -149,12 +149,12 @@ module PartitionGardener
|
|
|
149
149
|
derived_columns = config[:derived_columns] || {}
|
|
150
150
|
stale_column = config[:sync_stale_column] || "updated_at"
|
|
151
151
|
base_key = partition_key_column.to_s.split("::").first.strip
|
|
152
|
-
current_partition_key_expression = config[:current_partition_key_expression] || "s.#{
|
|
152
|
+
current_partition_key_expression = config[:current_partition_key_expression] || "s.#{gardener_connection.quote_column_name(base_key)}"
|
|
153
153
|
today = PartitionGardener.configuration.today
|
|
154
154
|
start_date = DateCalendar.add_months(today, -3)
|
|
155
155
|
end_date = DateCalendar.add_months(today, 3)
|
|
156
|
-
start_date_sql =
|
|
157
|
-
end_date_sql =
|
|
156
|
+
start_date_sql = gardener_connection.quote(start_date)
|
|
157
|
+
end_date_sql = gardener_connection.quote(end_date)
|
|
158
158
|
|
|
159
159
|
say "Syncing delta data from #{source_table} to #{target_table}"
|
|
160
160
|
|
|
@@ -162,26 +162,26 @@ module PartitionGardener
|
|
|
162
162
|
partitioned_columns = table_columns(target_table)
|
|
163
163
|
common_columns = current_columns & partitioned_columns
|
|
164
164
|
insert_columns = (common_columns + derived_columns.keys) & partitioned_columns
|
|
165
|
-
columns_str = insert_columns.map { |column|
|
|
165
|
+
columns_str = insert_columns.map { |column| gardener_connection.quote_column_name(column) }.join(", ")
|
|
166
166
|
inner_select_columns_str = insert_columns.map do |column|
|
|
167
167
|
if derived_columns.key?(column)
|
|
168
|
-
"#{derived_columns[column]} AS #{
|
|
168
|
+
"#{derived_columns[column]} AS #{gardener_connection.quote_column_name(column)}"
|
|
169
169
|
else
|
|
170
|
-
"s.#{
|
|
170
|
+
"s.#{gardener_connection.quote_column_name(column)}"
|
|
171
171
|
end
|
|
172
172
|
end.join(", ")
|
|
173
173
|
|
|
174
|
-
conflict_key_str = conflict_key.map { |column|
|
|
175
|
-
conflict_match = conflict_key.map { |column| "d.#{
|
|
174
|
+
conflict_key_str = conflict_key.map { |column| gardener_connection.quote_column_name(column) }.join(", ")
|
|
175
|
+
conflict_match = conflict_key.map { |column| "d.#{gardener_connection.quote_column_name(column)} = s.#{gardener_connection.quote_column_name(column)}" }.join(" AND ")
|
|
176
176
|
update_columns = insert_columns - conflict_key
|
|
177
|
-
update_clause = update_columns.map { |column| "#{
|
|
177
|
+
update_clause = update_columns.map { |column| "#{gardener_connection.quote_column_name(column)} = EXCLUDED.#{gardener_connection.quote_column_name(column)}" }.join(", ")
|
|
178
178
|
unless current_columns.include?(stale_column) && partitioned_columns.include?(stale_column)
|
|
179
179
|
raise ArgumentError,
|
|
180
180
|
"sync_stale_column #{stale_column.inspect} is missing from source or target; " \
|
|
181
181
|
"refusing unbounded delta sync"
|
|
182
182
|
end
|
|
183
183
|
|
|
184
|
-
stale_check = "d.#{
|
|
184
|
+
stale_check = "d.#{gardener_connection.quote_column_name(stale_column)} >= s.#{gardener_connection.quote_column_name(stale_column)}"
|
|
185
185
|
window_predicate = [
|
|
186
186
|
"#{current_partition_key_expression} >= #{start_date_sql}",
|
|
187
187
|
"AND #{current_partition_key_expression} < #{end_date_sql}",
|
|
@@ -191,7 +191,7 @@ module PartitionGardener
|
|
|
191
191
|
"AND #{stale_check}",
|
|
192
192
|
")"
|
|
193
193
|
].join(" ")
|
|
194
|
-
order_clause = conflict_key.map { |column| "s.#{
|
|
194
|
+
order_clause = conflict_key.map { |column| "s.#{gardener_connection.quote_column_name(column)}" }.join(", ")
|
|
195
195
|
|
|
196
196
|
count_sql = <<~SQL
|
|
197
197
|
SELECT COUNT(*) AS count
|
|
@@ -215,7 +215,7 @@ module PartitionGardener
|
|
|
215
215
|
<<~SQL.chomp
|
|
216
216
|
ON CONFLICT (#{conflict_key_str}) DO UPDATE SET
|
|
217
217
|
#{update_clause}
|
|
218
|
-
WHERE #{quoted_table(target_table)}.#{
|
|
218
|
+
WHERE #{quoted_table(target_table)}.#{gardener_connection.quote_column_name(stale_column)} < EXCLUDED.#{gardener_connection.quote_column_name(stale_column)}
|
|
219
219
|
SQL
|
|
220
220
|
end
|
|
221
221
|
|
|
@@ -249,8 +249,8 @@ module PartitionGardener
|
|
|
249
249
|
sql = <<~SQL
|
|
250
250
|
SELECT column_name
|
|
251
251
|
FROM information_schema.columns
|
|
252
|
-
WHERE table_schema = #{
|
|
253
|
-
AND table_name = #{
|
|
252
|
+
WHERE table_schema = #{gardener_connection.quote(PartitionGardener.configuration.schema_name)}
|
|
253
|
+
AND table_name = #{gardener_connection.quote(table_name)}
|
|
254
254
|
ORDER BY ordinal_position
|
|
255
255
|
SQL
|
|
256
256
|
|
|
@@ -283,7 +283,7 @@ module PartitionGardener
|
|
|
283
283
|
sql = <<~SQL
|
|
284
284
|
SELECT inhrelid::regclass AS child
|
|
285
285
|
FROM pg_catalog.pg_inherits
|
|
286
|
-
WHERE inhparent = #{
|
|
286
|
+
WHERE inhparent = #{gardener_connection.quote(table_name)}::regclass
|
|
287
287
|
SQL
|
|
288
288
|
run_sql(sql).map { |row| row["child"] }
|
|
289
289
|
end
|
|
@@ -294,7 +294,7 @@ module PartitionGardener
|
|
|
294
294
|
partitioned_table = config[:partitioned_table]
|
|
295
295
|
old_table = "#{current_table}_old"
|
|
296
296
|
|
|
297
|
-
return if
|
|
297
|
+
return if gardener_connection.table_exists?(old_table)
|
|
298
298
|
|
|
299
299
|
say "Performing hot switch: #{current_table} -> #{partitioned_table}"
|
|
300
300
|
|
|
@@ -323,8 +323,8 @@ module PartitionGardener
|
|
|
323
323
|
partitioned_table = config[:partitioned_table]
|
|
324
324
|
old_table = "#{current_table}_old"
|
|
325
325
|
|
|
326
|
-
return unless
|
|
327
|
-
return if
|
|
326
|
+
return unless gardener_connection.table_exists?(old_table)
|
|
327
|
+
return if gardener_connection.table_exists?(partitioned_table)
|
|
328
328
|
|
|
329
329
|
say "Performing hot unswitch: #{current_table} -> #{partitioned_table}"
|
|
330
330
|
|
|
@@ -351,7 +351,7 @@ module PartitionGardener
|
|
|
351
351
|
|
|
352
352
|
table_columns(table_name).filter_map do |column_name|
|
|
353
353
|
sql = <<~SQL
|
|
354
|
-
SELECT pg_get_serial_sequence(#{
|
|
354
|
+
SELECT pg_get_serial_sequence(#{gardener_connection.quote(qualified_table)}, #{gardener_connection.quote(column_name)}) AS sequence_name
|
|
355
355
|
SQL
|
|
356
356
|
result = run_sql(sql).first
|
|
357
357
|
sequence_name = result["sequence_name"]
|
|
@@ -397,7 +397,7 @@ module PartitionGardener
|
|
|
397
397
|
timeout = swap_lock_timeout_setting
|
|
398
398
|
return if timeout.nil?
|
|
399
399
|
|
|
400
|
-
run_sql "SET LOCAL lock_timeout = #{
|
|
400
|
+
run_sql "SET LOCAL lock_timeout = #{gardener_connection.quote(timeout)}"
|
|
401
401
|
end
|
|
402
402
|
|
|
403
403
|
def rename_partition_children!(parent_table, from_prefix, to_prefix)
|
|
@@ -409,23 +409,23 @@ module PartitionGardener
|
|
|
409
409
|
new_bare_name = bare_name.sub(from_prefix, to_prefix)
|
|
410
410
|
next if new_bare_name == bare_name
|
|
411
411
|
|
|
412
|
-
run_sql "ALTER TABLE #{partition} RENAME TO #{
|
|
412
|
+
run_sql "ALTER TABLE #{partition} RENAME TO #{gardener_connection.quote_column_name(new_bare_name)}"
|
|
413
413
|
say "Renamed #{partition} to #{new_bare_name}"
|
|
414
414
|
end
|
|
415
415
|
end
|
|
416
416
|
|
|
417
417
|
def repoint_serial_sequences!(table_name, sequence_pairs)
|
|
418
418
|
sequence_pairs.each do |column_name, sequence_name|
|
|
419
|
-
quoted_column =
|
|
419
|
+
quoted_column = gardener_connection.quote_column_name(column_name)
|
|
420
420
|
live_table = quoted_table(table_name)
|
|
421
421
|
run_sql <<~SQL
|
|
422
422
|
ALTER TABLE #{live_table}
|
|
423
423
|
ALTER COLUMN #{quoted_column}
|
|
424
|
-
SET DEFAULT nextval(#{
|
|
424
|
+
SET DEFAULT nextval(#{gardener_connection.quote(sequence_name)}::regclass)
|
|
425
425
|
SQL
|
|
426
426
|
run_sql "ALTER SEQUENCE #{sequence_name} OWNED BY #{live_table}.#{quoted_column}"
|
|
427
427
|
max_id = run_sql("SELECT COALESCE(MAX(#{quoted_column}), 1) AS max_id FROM #{live_table}").first["max_id"].to_i
|
|
428
|
-
run_sql "SELECT setval(#{
|
|
428
|
+
run_sql "SELECT setval(#{gardener_connection.quote(sequence_name)}, #{[max_id, 1].max})"
|
|
429
429
|
say "Repointed #{sequence_name} to #{table_name}.#{column_name}"
|
|
430
430
|
end
|
|
431
431
|
end
|
|
@@ -440,15 +440,20 @@ module PartitionGardener
|
|
|
440
440
|
end
|
|
441
441
|
|
|
442
442
|
def run_sql(sql)
|
|
443
|
-
|
|
443
|
+
gardener_connection.execute(sql)
|
|
444
444
|
end
|
|
445
445
|
|
|
446
|
-
|
|
446
|
+
# ActiveRecord::Migration#exec_migration assigns @connection for the target database.
|
|
447
|
+
# Prefer that adapter during migrate; otherwise use the configured resolver.
|
|
448
|
+
def gardener_connection
|
|
449
|
+
migration_connection = instance_variable_get(:@connection) if instance_variable_defined?(:@connection)
|
|
450
|
+
return migration_connection if migration_connection
|
|
451
|
+
|
|
447
452
|
PartitionGardener.configuration.connection
|
|
448
453
|
end
|
|
449
454
|
|
|
450
455
|
def quoted_table(name)
|
|
451
|
-
|
|
456
|
+
gardener_connection.quote_table_name(name)
|
|
452
457
|
end
|
|
453
458
|
end
|
|
454
459
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: partition_gardener
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -279,6 +279,8 @@ files:
|
|
|
279
279
|
- docs/changelogs/20261005135700_checkpoint-table-name.md
|
|
280
280
|
- docs/changelogs/20261005141621_cut-patch-release-0-3-6.md
|
|
281
281
|
- docs/changelogs/20261021220000_cut-patch-release-0-3-7.md
|
|
282
|
+
- docs/changelogs/20261105085411_hot-switch-migration-connection-stack-overflow.md
|
|
283
|
+
- docs/changelogs/20261105090326_cut-patch-release-0-3-8.md
|
|
282
284
|
- docs/cli.md
|
|
283
285
|
- docs/configuration.md
|
|
284
286
|
- docs/cutover.md
|
|
@@ -289,6 +291,7 @@ files:
|
|
|
289
291
|
- docs/issues/20260909164000_shipped-contract-rfcs.md
|
|
290
292
|
- docs/issues/20260916113300_opaque-composite-public-ids.md
|
|
291
293
|
- docs/issues/20260917123253_ci-drop-automatic-dependency-audit.md
|
|
294
|
+
- docs/issues/20261105085411_hot-switch-migration-connection-stack-overflow.md
|
|
292
295
|
- docs/monitoring.md
|
|
293
296
|
- docs/naming.md
|
|
294
297
|
- docs/operations.md
|
|
@@ -300,6 +303,8 @@ files:
|
|
|
300
303
|
- docs/reviews/20261021220000_engineering-audit-0-3-7.md
|
|
301
304
|
- docs/reviews/20261028075216_engineering-audit-release-preparation.md
|
|
302
305
|
- docs/reviews/20261029150855_engineering-audit-release-preparation.md
|
|
306
|
+
- docs/reviews/20261105085411_engineering-audit-hot-switch-connection.md
|
|
307
|
+
- docs/reviews/20261105090507_engineering-audit-release-preparation.md
|
|
303
308
|
- docs/schemas/partition_garden.schema.json
|
|
304
309
|
- docs/schemas/plan_report.schema.json
|
|
305
310
|
- docs/tooling_split.md
|