Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/code0/zero_track/database/schema_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def remove_dynamic_partitions!(structure)

# Remove ALTER INDEX ... ATTACH PARTITION <schema>.<partition>;
structure.gsub!(/^ALTER INDEX \S+ ATTACH PARTITION #{schema}\.\S+;\n/, '')

# Remove COMMENT ON TABLE <schema>.<partition> IS '<comment>';
structure.gsub!(/^COMMENT ON TABLE #{schema}\.\S+ IS .*;\n/, '')
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/code0/zero_track/database/schema_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
ALTER TABLE ONLY users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);

COMMENT ON TABLE partitions_dynamic."p_audit_events_202606" IS '{"table":"p_audit_events","detached_at":"2026-10-17T15:32:48Z"}';

COMMENT ON TABLE "p_audit_events" IS 'partitioned table';

CREATE INDEX index_p_audit_events_on_author_id ON ONLY p_audit_events USING btree (author_id);

CREATE INDEX p_audit_events_202607_author_id_idx ON partitions_dynamic.p_audit_events_202607 USING btree (author_id);
Expand Down Expand Up @@ -193,6 +197,14 @@
it 'preserves foreign keys on the parent table' do
expect(clean).to include('fk_rails_9c5a4c4493 FOREIGN KEY (author_id) REFERENCES users(id)')
end

it 'removes comments from dynamic partitions' do
expect(clean).not_to include('COMMENT ON TABLE partitions_dynamic."p_audit_events_202606"')
end

it 'preserves comment on the parent table' do
expect(clean).to include('COMMENT ON TABLE "p_audit_events"')
end
end

context 'with a custom dynamic partition schema name' do
Expand Down
Loading