Open mwestphall opened 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.
I was able to resolve the following issues with a combination of the ad-hoc migrations and borrowing missing data from dev:
ALTER TABLE macrostrat.cols
ADD CONSTRAINT cols_project_fk FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE;
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"
carto-rebuild.sql
ALTER TABLE carto.polygons ADD CONSTRAINT polygons_pkey PRIMARY KEY (map_id, scale);
could not create unique index "polygons_tiny_pkey"
Can be fixed by running carto-rebuild.sql
with the following modifications:
diff --git a/cli/macrostrat/cli/ad-hoc-migrations/carto-rebuild.sql b/cli/macrostrat/cli/ad-hoc-migrations/carto-rebuild.sql
index 9161264..8a74f69 100644
--- a/cli/macrostrat/cli/ad-hoc-migrations/carto-rebuild.sql
+++ b/cli/macrostrat/cli/ad-hoc-migrations/carto-rebuild.sql
@@ -6,6 +6,7 @@ do that until we've removed the duplicates.
*/
ALTER TABLE carto.polygons ADD COLUMN updated boolean NOT NULL DEFAULT false;
+ALTER TABLE carto.polygons_large ADD COLUMN updated boolean NOT NULL DEFAULT false;
INSERT INTO carto.polygons_tiny (map_id, source_id, geom_scale, geom, scale, updated)
@@ -69,4 +70,5 @@ DELETE FROM carto.polygons_large WHERE NOT updated AND map_id IN (SELECT map_id
/** Once we have reduced duplicate geometries, we can add a unique constraint */
ALTER TABLE carto.polygons ADD CONSTRAINT polygons_pkey PRIMARY KEY (map_id, scale);
-ALTER TABLE carto.polygons DROP COLUMN updated;
\ No newline at end of file
+ALTER TABLE carto.polygons_large DROP COLUMN updated;
+ALTER TABLE carto.polygons DROP COLUMN updated;
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
partition-maps
partition-carto