Implement child partition table exclusion for schema dumper#93
Implement child partition table exclusion for schema dumper#93dannote wants to merge 3 commits intorkrage:masterfrom
Conversation
|
I mean it is explicitly called out in the docs that if you're using this gem you should be using a structure file: https://github.com/rkrage/pg_party?tab=readme-ov-file#limitations When I first wrote this gem, the partitioned tables absolutely were not represented correctly in the schema file. Has that maybe changed in newer versions of Rails? |
|
Thanks for the quick response! I see in the docs that create_list_partition :import_features, partition_key: :session_id do |t|
t.references :layer, null: false, foreign_key: { to_table: :import_layers }
t.references :session, null: false, foreign_key: { to_table: :import_sessions }
t.bigint :source_id
t.geometry :geometry
t.jsonb :properties
t.timestamps
endAnd the resulting create_table "import_features", id: false, options: "PARTITION BY LIST (session_id)", force: :cascade do |t|
t.bigserial "id", null: false
t.bigint "layer_id", null: false
t.bigint "session_id", null: false
t.bigint "source_id"
t.geometry "geometry", limit: { srid: 0, type: "geometry" }
t.jsonb "properties"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["layer_id"], name: "index_import_features_on_layer_id"
t.index ["session_id"], name: "index_import_features_on_session_id"
end
create_table "import_features_template", id: :bigint, default: -> { "nextval('import_features_id_seq'::regclass)" }, force: :cascade do |t|
t.bigint "layer_id", null: false
t.bigint "session_id", null: false
t.bigint "source_id"
t.geometry "geometry", limit: { srid: 0, type: "geometry" }
t.jsonb "properties"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["layer_id"], name: "import_features_template_layer_id_idx"
t.index ["session_id"], name: "import_features_template_session_id_idx"
endThe base table shows up nicely with the partitioning option, and my PR ensures child partitions don’t clutter it. It feels like Rails might have improved its handling of partitioned tables in newer versions now. Do you recall any specific issues with If compatibility is a concern, I could add a version check like: if Rails.version >= "8.0"
ActiveRecord::SchemaDumper.prepend(PgParty::SchemaDumperExtension)
end |
What does this PR do?
Adds support for excluding partition child tables from
db/schema.rbdumps whenPgParty.config.schema_exclude_partitionsis true, by overridingActiveRecord::SchemaDumper#ignored?.Why is this needed?
While
PgParty::Hacks::PostgreSQLDatabaseTasksexcludes partitions fromstructure.sqldumps,schema.rbcurrently includes them, leading to clutter and inconsistency. This PR ensures uniform exclusion behavior across both formats.