File tree Expand file tree Collapse file tree
api/src/main/resources/marquez/db/migration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/* SPDX-License-Identifier: Apache-2.0 */
2- ALTER TABLE dataset_symlinks ALTER COLUMN name TYPE VARCHAR ;
2+
3+ DO
4+ $$
5+ DECLARE
6+ datasets_view_exists boolean ;
7+ datasets_view_definition text ;
8+ BEGIN
9+ SELECT EXISTS (
10+ SELECT * FROM information_schema .views
11+ WHERE table_schema= ' public' AND table_name= ' datasets_view'
12+ ) INTO datasets_view_exists;
13+
14+ IF datasets_view_exists THEN
15+ -- Altering is not allowed when the column is being used from views. So here,
16+ -- we temporarily drop the view before altering and recreate it.
17+ SELECT view_definition FROM information_schema .views
18+ WHERE table_schema= ' public' AND table_name= ' datasets_view'
19+ INTO datasets_view_definition;
20+
21+ DROP VIEW datasets_view;
22+ ALTER TABLE dataset_symlinks ALTER COLUMN name TYPE VARCHAR ;
23+ EXECUTE format(' CREATE VIEW datasets_view AS %s' , datasets_view_definition);
24+ ELSE
25+ ALTER TABLE dataset_symlinks ALTER COLUMN name TYPE VARCHAR ;
26+ END IF;
27+ END
28+ $$ LANGUAGE plpgsql;
You can’t perform that action at this time.
0 commit comments