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 4cc2bb2e40cf..4be80f43da00 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 @@ -20,6 +20,9 @@ static POSTGIS_TABLES_OR_VIEWS: Lazy = Lazy::new(|| { .unwrap() }); +// https://www.postgresql.org/docs/12/pgbuffercache.html +static EXTENSION_VIEWS: Lazy = Lazy::new(|| RegexSet::new(&["(?i)^pg_buffercache$"]).unwrap()); + /// The maximum length of postgres identifiers, in bytes. /// /// Reference: https://www.postgresql.org/docs/12/limits.html @@ -111,7 +114,7 @@ impl SqlSchemaDifferFlavour for PostgresFlavour { } fn view_should_be_ignored(&self, view_name: &str) -> bool { - POSTGIS_TABLES_OR_VIEWS.is_match(view_name) + POSTGIS_TABLES_OR_VIEWS.is_match(view_name) || EXTENSION_VIEWS.is_match(view_name) } } diff --git a/migration-engine/migration-engine-tests/tests/migrations/postgres.rs b/migration-engine/migration-engine-tests/tests/migrations/postgres.rs index 5a16d521134e..baff8dc18f91 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/postgres.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/postgres.rs @@ -65,39 +65,33 @@ fn adding_a_scalar_list_for_a_model_with_id_type_int_must_work(api: TestApi) { // Reference for the tables created by PostGIS: https://postgis.net/docs/manual-1.4/ch04.html#id418599 #[test_connector(tags(Postgres))] fn existing_postgis_tables_must_not_be_migrated(api: TestApi) { - let create_spatial_ref_sys_table = "CREATE TABLE IF NOT EXISTS \"spatial_ref_sys\" ( id SERIAL PRIMARY KEY )"; - // The capitalized Geometry is intentional here, because we want the matching to be case-insensitive. - let create_geometry_columns_table = "CREATE TABLE IF NOT EXiSTS \"Geometry_columns\" ( id SERIAL PRIMARY KEY )"; - - api.raw_cmd(create_spatial_ref_sys_table); - api.raw_cmd(create_geometry_columns_table); - - api.assert_schema() - .assert_has_table("spatial_ref_sys") - .assert_has_table("Geometry_columns"); - - let schema = ""; + let create_tables = r#" + CREATE TABLE IF NOT EXISTS "spatial_ref_sys" ( id SERIAL PRIMARY KEY ); + /* 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 ); + "#; - api.schema_push(schema).send().assert_green_bang().assert_no_steps(); + api.raw_cmd(create_tables); + api.schema_push("").send().assert_green_bang().assert_no_steps(); api.assert_schema() .assert_has_table("spatial_ref_sys") .assert_has_table("Geometry_columns"); } -// Reference for the tables created by PostGIS: https://postgis.net/docs/manual-1.4/ch04.html#id418599 +// Reference for the views created by PostGIS: https://postgis.net/docs/manual-1.4/ch04.html#id418599 #[test_connector(tags(Postgres))] fn existing_postgis_views_must_not_be_migrated(api: TestApi) { - let create_spatial_ref_sys_view = "CREATE VIEW \"spatial_ref_sys\" AS SELECT 1"; - // The capitalized Geometry is intentional here, because we want the matching to be case-insensitive. - let create_geometry_columns_view = "CREATE VIEW \"Geometry_columns\" AS SELECT 1"; - - api.raw_cmd(create_spatial_ref_sys_view); - api.raw_cmd(create_geometry_columns_view); + let create_views = r#" + CREATE VIEW "spatial_ref_sys" AS SELECT 1; + /* The capitalized Geometry is intentional here, because we want the matching to be case-insensitive. */ + CREATE VIEW "Geometry_columns" AS SELECT 1; + CREATE VIEW "PG_BUFFERCACHE" AS SELECT 1; + "#; - let schema = ""; + api.raw_cmd(create_views); - api.schema_push(schema).send().assert_green_bang().assert_no_steps(); + api.schema_push("").send().assert_green_bang().assert_no_steps(); } #[test_connector(tags(Postgres))]