|
1 |
| --- Drop all VIEWs linked to the 'cexplorer' table. |
2 | 1 |
|
3 |
| --- Many schema migration changes will fail if they operate on a table that is part of a VIEW. |
4 |
| --- So we drop all VIEWs here and recreate them later. |
5 |
| - |
6 |
| -CREATE FUNCTION drop_cexplorer_views () RETURNS void language plpgsql as $$ |
7 |
| - |
8 |
| -DECLARE vname text; |
9 |
| -DECLARE next_version int; |
10 | 2 |
|
| 3 | +CREATE FUNCTION migrate() RETURNS void AS $$ |
| 4 | +DECLARE |
| 5 | + next_version int ; |
11 | 6 | BEGIN
|
12 |
| - SELECT stage_one + 1 INTO next_version FROM "schema_version"; |
| 7 | + SELECT stage_one + 1 INTO next_version FROM "schema_version" ; |
13 | 8 | IF next_version = 2 THEN
|
14 |
| - -- Only update the schema version if the versions are as expected. |
15 |
| - UPDATE "schema_version" SET stage_one = next_version; |
16 |
| - RAISE NOTICE 'DB has been migrated to stage_one version %', next_version; |
17 |
| - END IF; |
| 9 | + -- Empty migration file just to raise the version |
18 | 10 |
|
19 |
| - -- Always run the following. |
20 |
| - for vname in |
21 |
| - select '"' || table_name || '"' |
22 |
| - from information_schema.views |
23 |
| - where table_catalog = current_database () |
24 |
| - and table_schema = 'public' |
25 |
| - and table_name !~* 'pg_stat_.*' |
26 |
| - loop |
27 |
| - execute format ('drop view if exists %s cascade ;', vname) ; |
28 |
| - raise notice 'Dropping view : %', vname ; |
29 |
| - end loop ; |
30 |
| -end $$ ; |
| 11 | + UPDATE schema_version SET stage_one = next_version ; |
| 12 | + RAISE NOTICE 'DB has been migrated to stage_one version %', next_version ; |
| 13 | + END IF ; |
| 14 | +END ; |
| 15 | +$$ LANGUAGE plpgsql ; |
31 | 16 |
|
32 |
| -SELECT drop_cexplorer_views () ; |
| 17 | +SELECT migrate() ; |
33 | 18 |
|
34 |
| -DROP FUNCTION drop_cexplorer_views () ; |
| 19 | +DROP FUNCTION migrate() ; |
0 commit comments