|
| 1 | +/* Sprint 12 Master Database Migration Script -- must be run from psql using the following command: \i '<folder>/<script>' (must use / rather than \) */ |
| 2 | +\conninfo |
| 3 | +\encoding UTF8 |
| 4 | +\set VERBOSITY terse |
| 5 | +\set ECHO none |
| 6 | +\set QUIET on |
| 7 | +\set AUTOCOMMIT off |
| 8 | +START TRANSACTION; |
| 9 | +SET search_path TO dss,public; /*schema name dss ignored if it does not exist*/ |
| 10 | +SELECT current_schema() as dflt_schema |
| 11 | +\gset |
| 12 | +select exists( |
| 13 | +select 1 from information_schema.tables where table_name like 'dss%') |
| 14 | +as db_has_dss_tab |
| 15 | +\gset |
| 16 | +select exists( |
| 17 | +select 1 from information_schema.columns where column_name='governing_business_licence_id' and table_name='dss_rental_listing' and table_schema=:'dflt_schema') |
| 18 | +as list_has_bl_id |
| 19 | +\gset |
| 20 | +select exists( |
| 21 | +select 1 from information_schema.columns where column_name='local_government_type' and table_name='dss_organization' and table_schema=:'dflt_schema') |
| 22 | +as org_has_lg_type |
| 23 | +\gset |
| 24 | +\if :list_has_bl_id |
| 25 | + \echo 'Sprint 12 migration appears complete - Exiting without changes' |
| 26 | +\elif :org_has_lg_type |
| 27 | + \echo 'Sprint 11 migration appears complete - Beginning upgrade to Sprint 12' |
| 28 | + \echo 'Calling STR_DSS_Incremental_DB_DDL_Sprint_12.sql' |
| 29 | + \ir '../ddl/STR_DSS_Incremental_DB_DDL_Sprint_12.sql' |
| 30 | + \echo 'Replacing views' |
| 31 | + \ir '../ddl/STR_DSS_Views_Sprint_9.sql' |
| 32 | + \echo 'Calling STR_DSS_Data_Seeding_Sprint_12.sql' |
| 33 | + \ir '../seeding/STR_DSS_Data_Seeding_Sprint_12.sql' |
| 34 | +\elif :db_has_dss_tab |
| 35 | + \echo 'Database migration state is unknown - Exiting without changes' |
| 36 | +\else |
| 37 | + \echo 'Database has no DSS tables - Beginning complete build to Sprint 12' |
| 38 | + \echo 'Calling STR_DSS_Physical_DB_DDL_Sprint_12.sql' |
| 39 | + \ir '../ddl/STR_DSS_Physical_DB_DDL_Sprint_12.sql' |
| 40 | + \echo 'Calling STR_DSS_Data_Seeding_Sprint_12.sql' |
| 41 | + \ir '../seeding/STR_DSS_Data_Seeding_Sprint_12.sql' |
| 42 | + \echo 'Calling STR_DSS_Data_Seeding_Platforms_Sprint_10.sql' |
| 43 | + \ir '../seeding/STR_DSS_Data_Seeding_Platforms_Sprint_10.sql' |
| 44 | + \echo 'Platform contacts must be set manually' |
| 45 | + \echo 'Calling STR_DSS_Data_Seeding_LGs_Sprint_11.sql' |
| 46 | + \ir '../seeding/STR_DSS_Data_Seeding_LGs_Sprint_11.sql' |
| 47 | + \echo 'Calling STR_DSS_Data_Seeding_Geometry_Sprint_9.sql' |
| 48 | + \ir '../seeding/STR_DSS_Data_Seeding_Geometry_Sprint_9.sql' |
| 49 | +\endif |
| 50 | +\if :ERROR |
| 51 | + /*commit cannot succeed because transaction was aborted due to an error*/ |
| 52 | + \echo 'Undoing transaction' |
| 53 | + ROLLBACK; |
| 54 | +\else |
| 55 | + \echo 'Committing transaction' |
| 56 | + COMMIT; |
| 57 | +\endif |
| 58 | +\echo done! |
0 commit comments