Skip to content

Commit dcadb15

Browse files
committed
Move the CREATE VIEW statements from oconnor-0.000-23.000.sql into oconnor-create.sql. Add a drop script.
1 parent aa24037 commit dcadb15

4 files changed

Lines changed: 42 additions & 54 deletions

File tree

OConnor/resources/schemas/dbscripts/postgresql/oconnor-0.000-23.000.sql

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -194,22 +194,6 @@ CREATE TABLE oconnor.grants (
194194
);
195195

196196

197-
--
198-
-- Name: active_grants; Type: VIEW; Schema: oconnor; Owner: oconnor
199-
--
200-
201-
CREATE VIEW oconnor.active_grants AS
202-
SELECT g.id, g.container, (((g.id)::text || ' - '::text) || g.title) AS displaytitle FROM oconnor.grants g WHERE ((g.enabled = true) AND (now() < g.expiration_date));
203-
204-
205-
--
206-
-- Name: active_quotes; Type: VIEW; Schema: oconnor; Owner: oconnor
207-
--
208-
209-
CREATE VIEW oconnor.active_quotes AS
210-
SELECT g.id, g.container, (((g.id)::text || ' - '::text) || g.title) AS displaytitle FROM oconnor.grants g WHERE ((g.enabled = true) AND (now() < g.expiration_date));
211-
212-
213197
--
214198
-- Name: oc_sequence; Type: SEQUENCE; Schema: oconnor; Owner: oconnor
215199
--
@@ -807,14 +791,6 @@ CREATE TABLE oconnor.virus_challenges (
807791
);
808792

809793

810-
--
811-
-- Name: max_virus_challenge_date; Type: VIEW; Schema: oconnor; Owner: oconnor
812-
--
813-
814-
CREATE VIEW oconnor.max_virus_challenge_date AS
815-
SELECT v.id, max(v.challenge_date) AS challenge_date FROM oconnor.virus_challenges v WHERE ((v.challenge_type)::text ~~ '%SIV%'::text) GROUP BY v.id;
816-
817-
818794
--
819795
-- Name: mcm_cd8_tcell_epitopes; Type: TABLE; Schema: oconnor; Owner: oconnor; Tablespace:
820796
--

OConnor/resources/schemas/dbscripts/postgresql/oconnor-26.000-26.001.sql

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BEGIN
55
FOR rec IN
66
SELECT c.table_name, c.column_name
77
FROM information_schema.columns c
8-
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
8+
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
99
WHERE c.table_schema = 'oconnor'
1010
AND t.table_type = 'BASE TABLE'
1111
AND lower(c.column_name) IN ('createdby',
@@ -23,43 +23,20 @@ END $$;
2323
DO $$
2424
DECLARE
2525
rec RECORD;
26-
view_rec RECORD;
2726
BEGIN
28-
-- Save view definitions and drop all views in oconnor schema to clear dependencies
29-
CREATE TEMP TABLE _oconnor_view_defs (viewname text, definition text);
30-
31-
FOR view_rec IN
32-
SELECT viewname, definition
33-
FROM pg_views
34-
WHERE schemaname = 'oconnor'
35-
LOOP
36-
INSERT INTO _oconnor_view_defs VALUES (view_rec.viewname, view_rec.definition);
37-
EXECUTE format('DROP VIEW IF EXISTS oconnor.%I CASCADE', view_rec.viewname);
38-
END LOOP;
39-
40-
-- Alter container columns on base tables
4127
FOR rec IN
4228
SELECT c.table_name, c.column_name
4329
FROM information_schema.columns c
44-
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
30+
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
4531
WHERE c.table_schema = 'oconnor'
4632
AND t.table_type = 'BASE TABLE'
4733
AND lower(c.column_name) = 'container'
4834
AND c.data_type = 'character varying'
4935
LOOP
50-
EXECUTE format(
51-
'ALTER TABLE oconnor.%I ALTER COLUMN %I
36+
EXECUTE format(
37+
'ALTER TABLE oconnor.%I ALTER COLUMN %I
5238
TYPE entityid',
53-
rec.table_name, rec.column_name
54-
);
55-
END LOOP;
56-
57-
-- Recreate views from saved definitions
58-
FOR view_rec IN
59-
SELECT viewname, definition FROM _oconnor_view_defs
60-
LOOP
61-
EXECUTE format('CREATE OR REPLACE VIEW oconnor.%I AS %s', view_rec.viewname, view_rec.definition);
39+
rec.table_name, rec.column_name
40+
);
6241
END LOOP;
63-
64-
DROP TABLE _oconnor_view_defs;
65-
END $$;
42+
END $$;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2026 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
CREATE VIEW oconnor.active_grants AS
8+
SELECT g.id, g.container, (g.id::text || ' - ' || g.title) AS displaytitle
9+
FROM oconnor.grants g
10+
WHERE g.enabled = true AND now() < g.expiration_date;
11+
12+
CREATE VIEW oconnor.active_quotes AS
13+
SELECT g.id, g.container, (g.id::text || ' - ' || g.title) AS displaytitle
14+
FROM oconnor.grants g
15+
WHERE g.enabled = true AND now() < g.expiration_date;
16+
17+
CREATE VIEW oconnor.max_virus_challenge_date AS
18+
SELECT v.id, max(v.challenge_date) AS challenge_date
19+
FROM oconnor.virus_challenges v
20+
WHERE v.challenge_type::text LIKE '%SIV%'
21+
GROUP BY v.id;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2026 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
-- DROP all views (current and obsolete)
8+
9+
-- NOTE: Don't remove any of these drop statements, even if we stop re-creating the view in *-create.sql. Drop statements must
10+
-- remain in place so we can correctly upgrade from older versions, which we commit to for two years after each release.
11+
12+
SELECT core.fn_dropifexists('max_virus_challenge_date', 'oconnor', 'VIEW', NULL);
13+
SELECT core.fn_dropifexists('active_quotes', 'oconnor', 'VIEW', NULL);
14+
SELECT core.fn_dropifexists('active_grants', 'oconnor', 'VIEW', NULL);

0 commit comments

Comments
 (0)