Skip to content

Commit d1540f4

Browse files
committed
Stop creating views
Fixes #1950
1 parent 32da1ff commit d1540f4

File tree

2 files changed

+12
-55
lines changed

2 files changed

+12
-55
lines changed

schema/migration-1-0002-20190912.sql

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
1-
-- Drop all VIEWs linked to the 'cexplorer' table.
21

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;
102

3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
DECLARE
5+
next_version int ;
116
BEGIN
12-
SELECT stage_one + 1 INTO next_version FROM "schema_version";
7+
SELECT stage_one + 1 INTO next_version FROM "schema_version" ;
138
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
1810

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 ;
3116

32-
SELECT drop_cexplorer_views () ;
17+
SELECT migrate() ;
3318

34-
DROP FUNCTION drop_cexplorer_views () ;
19+
DROP FUNCTION migrate() ;

schema/migration-3-0001-20190816.sql

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +0,0 @@
1-
-- Create all the views.
2-
3-
-- The views are always created because all views are deleted at the start ot the
4-
-- migration process.
5-
6-
-- Conventions:
7-
-- * Views use `_view` as a suffix to show they are views rather than table.
8-
9-
-- A utxo view which shows all unspent transaction outputs including the un-redeemed redeem
10-
-- addresses.
11-
create or replace view utxo_byron_view as select
12-
tx_out.*
13-
from tx_out left outer join tx_in
14-
on tx_out.tx_id = tx_in.tx_out_id and tx_out.index = tx_in.tx_out_index
15-
where tx_in.tx_in_id is null ;
16-
17-
18-
-- A utxo view which shows all unspent transaction outputs *excluding* the un-redeemed redeem
19-
-- addresses.
20-
-- This should produce the same query results as the above `utxo_byron_view` for Shelley addresses
21-
-- and non-redeem Byron addresses.
22-
create or replace view utxo_view as select
23-
tx_out.*
24-
from tx_out
25-
left outer join tx_in on tx_out.tx_id = tx_in.tx_out_id and tx_out.index = tx_in.tx_out_index
26-
left outer join tx on tx.id = tx_out.tx_id
27-
left outer join block on tx.block_id = block.id
28-
where tx_in.tx_in_id is null and block.epoch_no is not null ;

0 commit comments

Comments
 (0)