Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OConnor/module.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Name: OConnor
SchemaVersion: 25.001
SchemaVersion: 26.001
RequiredServerVersion: 16.30
ManageVersion: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
DO $$
DECLARE
rec RECORD;
BEGIN
FOR rec IN
SELECT c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
WHERE c.table_schema = 'oconnor'
AND t.table_type = 'BASE TABLE'
AND lower(c.column_name) IN ('createdby',
'modifiedby')
AND c.data_type = 'smallint'
LOOP
EXECUTE format(
'ALTER TABLE oconnor.%I ALTER COLUMN %I
TYPE userid',
rec.table_name, rec.column_name
);
END LOOP;
END $$;

DO $$
DECLARE
rec RECORD;
view_rec RECORD;
BEGIN
-- Save view definitions and drop all views in oconnor schema to clear dependencies
Comment thread
labkey-bpatel marked this conversation as resolved.
Outdated
CREATE TEMP TABLE _oconnor_view_defs (viewname text, definition text);

FOR view_rec IN
SELECT viewname, definition
FROM pg_views
WHERE schemaname = 'oconnor'
LOOP
INSERT INTO _oconnor_view_defs VALUES (view_rec.viewname, view_rec.definition);
EXECUTE format('DROP VIEW IF EXISTS oconnor.%I CASCADE', view_rec.viewname);
END LOOP;

-- Alter container columns on base tables
FOR rec IN
SELECT c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON t.table_schema = c.table_schema AND t.table_name = c.table_name
WHERE c.table_schema = 'oconnor'
AND t.table_type = 'BASE TABLE'
AND lower(c.column_name) = 'container'
AND c.data_type = 'character varying'
LOOP
EXECUTE format(
'ALTER TABLE oconnor.%I ALTER COLUMN %I
TYPE entityid',
rec.table_name, rec.column_name
);
END LOOP;

-- Recreate views from saved definitions
FOR view_rec IN
SELECT viewname, definition FROM _oconnor_view_defs
LOOP
EXECUTE format('CREATE OR REPLACE VIEW oconnor.%I AS %s', view_rec.viewname, view_rec.definition);
END LOOP;

DROP TABLE _oconnor_view_defs;
END $$;