From 2f2d44f817c25f0102194741da803497566805f0 Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Fri, 16 Sep 2022 12:30:08 +0000 Subject: [PATCH 1/3] fix: prevent deletion of 'raster_columns' and 'raster_overviews' PostGIS columns in prisma migrate --- .../sql_schema_differ/sql_schema_differ_flavour/postgres.rs | 2 ++ .../migration-engine-tests/tests/migrations/postgres.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs index 2eb7e2f9df51..8f8ffdb64b9a 100644 --- a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs +++ b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs @@ -22,6 +22,8 @@ static POSTGIS_TABLES_OR_VIEWS: Lazy = Lazy::new(|| { "(?i)^spatial_ref_sys$", "(?i)^geometry_columns$", "(?i)^geography_columns$", + "(?i)^raster_columns$", + "(?i)^raster_overviews$", ]) .unwrap() }); diff --git a/migration-engine/migration-engine-tests/tests/migrations/postgres.rs b/migration-engine/migration-engine-tests/tests/migrations/postgres.rs index 1f527f2904b1..a8ffb20075a1 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/postgres.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/postgres.rs @@ -71,6 +71,8 @@ fn existing_postgis_tables_must_not_be_migrated(api: TestApi) { /* The capitalized Geometry is intentional here, because we want the matching to be case-insensitive. */ CREATE TABLE IF NOT EXISTS "Geometry_columns" ( id SERIAL PRIMARY KEY ); CREATE TABLE IF NOT EXISTS "geography_columns" ( id SERIAL PRIMARY KEY ); + CREATE TABLE IF NOT EXISTS "raster_columns" ( id SERIAL PRIMARY KEY ); + CREATE TABLE IF NOT EXISTS "raster_overviews" ( id SERIAL PRIMARY KEY ); "#; api.raw_cmd(create_tables); @@ -79,7 +81,9 @@ fn existing_postgis_tables_must_not_be_migrated(api: TestApi) { api.assert_schema() .assert_has_table("spatial_ref_sys") .assert_has_table("Geometry_columns") - .assert_has_table("geography_columns"); + .assert_has_table("geography_columns") + .assert_has_table("raster_columns") + .assert_has_table("raster_overviews"); } // Reference for the views created by PostGIS: https://postgis.net/docs/manual-1.4/ch04.html#id418599 From 9a6bc87f2e139da5e95ee8f4632d126611ed60e5 Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Fri, 16 Sep 2022 16:21:02 +0200 Subject: [PATCH 2/3] Add link as a comment --- .../src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs index 8f8ffdb64b9a..b38917612040 100644 --- a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs +++ b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs @@ -22,6 +22,8 @@ static POSTGIS_TABLES_OR_VIEWS: Lazy = Lazy::new(|| { "(?i)^spatial_ref_sys$", "(?i)^geometry_columns$", "(?i)^geography_columns$", + + // See §11.2 in: https://postgis.net/docs/using_raster_dataman.html "(?i)^raster_columns$", "(?i)^raster_overviews$", ]) From 32bdca578e300b43e008afb36fec610c2992e34a Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Fri, 16 Sep 2022 16:26:27 +0200 Subject: [PATCH 3/3] Fix formatting issue --- .../src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs index b38917612040..e4837309b074 100644 --- a/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs +++ b/migration-engine/connectors/sql-migration-connector/src/sql_schema_differ/sql_schema_differ_flavour/postgres.rs @@ -22,7 +22,6 @@ static POSTGIS_TABLES_OR_VIEWS: Lazy = Lazy::new(|| { "(?i)^spatial_ref_sys$", "(?i)^geometry_columns$", "(?i)^geography_columns$", - // See §11.2 in: https://postgis.net/docs/using_raster_dataman.html "(?i)^raster_columns$", "(?i)^raster_overviews$",