[FEATURE] Support deleting partitions without dropping parent table
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start in pkg/diff/sql_generator.go around lines 860-866 to inspect the existing unsupported-partition path. Then review partitioned_table_cases_test.go and its existing test patterns. Done means a removed partition with its parent retained generates a DROP TABLE statement with the appropriate data-deletion hazard, and the new case passes.
Written by the indexing model from the issue text.
Description
Describe the feature
Support for deleting partitions without dropping the parent table.
Currently, when attempting to delete a partition while keeping the parent table, pg-schema-diff returns an error:
Error: generating plan: generating plan statements: generating migration statements:
resolving table diff: generating delete statements for "public"."prtimes_media_outlet_release_log_2025_02":
generating sql: deleting partitions without dropping parent table: not implemented
Expected behavior:
pg-schema-diff should generate a DROP TABLE statement for the partition when:
- A partition exists in the old schema
- The partition is removed in the new schema
- The parent table still exists in both schemas
Example:
-- Old schema
CREATE TABLE parent_table (...) PARTITION BY RANGE (created_at);
CREATE TABLE partition_2025_01 PARTITION OF parent_table FOR VALUES FROM ('2025-01-01') TO ('2025-02-01');
CREATE TABLE partition_2025_02 PARTITION OF parent_table FOR VALUES FROM ('2025-02-01') TO ('2025-03-01');
-- New schema (dropping old partition)
CREATE TABLE parent_table (...) PARTITION BY RANGE (created_at);
CREATE TABLE partition_2025_02 PARTITION OF parent_table FOR VALUES FROM ('2025-02-01') TO ('2025-03-01');
Expected migration output:
DROP TABLE partition_2025_01;
Motivation
In time-based partitioning strategies (e.g., monthly or yearly partitions), it's common to drop old partitions to manage data retention policies while keeping the parent table active for ongoing operations.
Currently, we must manually drop partitions outside of pg-schema-diff, which breaks the declarative schema management workflow and requires manual intervention for routine partition maintenance.
According to the code comment in sql_generator.go:860-861:
Don't support dropping partitions without dropping the base table. This would be easy to implement, but we would need to add tests for it.
This suggests the implementation is straightforward and mainly requires test coverage.
Contribution
I'm interested in contributing this feature. Would a pull request be welcome?
The implementation would involve:
- Removing the restriction in
sql_generator.go:860-866that returnsErrNotImplementedwhen deleting partitions without dropping the parent table - Generating
DROP TABLEstatement for the partition with appropriate hazard warnings (MigrationHazardTypeDeletesData) - Adding test coverage in
partitioned_table_cases_test.gofollowing the existing test pattern
Please let me know if this aligns with the project's roadmap and if there are any specific requirements I should consider.
- Dominant language
- Go
- Stars
- 884
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stripe/pg-schema-diff
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 76/100
stripe/pg-schema-diff#302 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
stripe/pg-schema-diff#283 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
stripe/pg-schema-diff#301 ·
-
Is the repo active? Open
Difficulty 1/5 Under an hour Newbie friendliness 15/100
stripe/pg-schema-diff#289 · 7 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
stripe/pg-schema-diff#284 ·
All issues in stripe/pg-schema-diff
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100