UW-Macrostrat / macrostrat

A geological data platform for exploration, integration, and analysis
Apache License 2.0
3 stars 1 forks source link

V2 Dev migration applications to the Prod V1 data dump #75

Open mwestphall opened 1 month ago

mwestphall commented 1 month ago

While the migration system now applies successfully to a schema-only dump of the prod db (https://github.com/UW-Macrostrat/macrostrat/issues/70), several new issues arise when applying to a data dump:

macrostrat-core-v2

UPDATE macrostrat.strat_names SET ref_id = NULL WHERE ref_id = 0;

null value in column "ref_id" of relation "strat_names" violates not-null constraint
ALTER TABLE macrostrat.cols
    ADD CONSTRAINT cols_project_fk  FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE;

insert or update on table "cols" violates foreign key constraint "cols_project_fk"
DETAIL:  Key (project_id)=(5) is not present in table "projects".
UPDATE macrostrat.col_groups cg SET project_id = c.project_id FROM macrostrat.cols c WHERE c.col_group_id = cg.id;

permission denied for schema macrostrat
LINE 1: SELECT 1 FROM ONLY "macrostrat"."projects" x WHERE "id" OPER...
                           ^
QUERY:  SELECT 1 FROM ONLY "macrostrat"."projects" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x

partition-maps

ALTER TABLE maps.lines ADD CONSTRAINT maps_lines_geom_check CHECK (maps.lines_geom_is_valid(geom));
check constraint "maps_lines_geom_check" of relation "lines_large" is violated by some row

partition-carto

ALTER TABLE carto.lines ATTACH PARTITION carto.lines_large FOR VALUES IN ('large');
insert or update on table "lines_large" violates foreign key constraint "lines_source_id_fkey"
DETAIL:  Key (source_id)=(145) is not present in table "sources".
ALTER TABLE carto.polygons ADD CONSTRAINT polygons_pkey PRIMARY KEY (map_id, scale);
could not create unique index "polygons_tiny_pkey"
DETAIL:  Key (map_id, scale)=(3189765, tiny) is duplicated.
davenquinn commented 1 month ago

I have made some "ad hoc migrations" that solve some of these data issues. In particular the "Carto" rows being duplicated is one we have solved previously.

mwestphall commented 1 month ago

I was able to resolve the following issues with a combination of the ad-hoc migrations and borrowing missing data from dev:

macrostrat-core-v2

ALTER TABLE macrostrat.cols
    ADD CONSTRAINT cols_project_fk  FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE;

partition-carto

ALTER TABLE carto.lines ATTACH PARTITION carto.lines_large FOR VALUES IN ('large');
insert or update on table "lines_large" violates foreign key constraint "lines_source_id_fkey"
ALTER TABLE carto.lines ATTACH PARTITION carto.lines_large FOR VALUES IN ('large');
insert or update on table "lines_large" violates foreign key constraint "lines_source_id_fkey"

partition-maps

ALTER TABLE carto.polygons ADD CONSTRAINT polygons_pkey PRIMARY KEY (map_id, scale);
could not create unique index "polygons_tiny_pkey"