From 4f9667b55363ecca24ec7c57fb52437b2dddd267 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sat, 9 Apr 2022 02:27:35 -0400 Subject: [PATCH] build a volume column if it's missing --- setup_sql/build_master_tables.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/setup_sql/build_master_tables.sql b/setup_sql/build_master_tables.sql index ab8cceb..43bdb2a 100644 --- a/setup_sql/build_master_tables.sql +++ b/setup_sql/build_master_tables.sql @@ -40,6 +40,21 @@ BEGIN EXECUTE format('%s',f.pop); EXECUTE format('%s',f.fk); END LOOP; + -------add a units column if one doesn't exist-------------------------------- + IF (SELECT COUNT(*) FROM fc.target_meta WHERE appcol = 'units') = 0 THEN + SELECT 'ALTER TABLE '||_target_table||' ADD COLUMN app_units numeric DEFAULT 0' INTO _sql; + EXECUTE format('%s',_sql); + --insert the newly created row meta into target_meta + INSERT INTO + fc.target_meta + SELECT + table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, data_type, 'units', null::text + FROM + information_schema.columns + WHERE + format('%I',table_schema)||'.'||format('%I',table_name) = _target_table + AND column_name = 'app_units'; + END IF; -------add a version column if one doesn't exist-------------------------------- IF (SELECT COUNT(*) FROM fc.target_meta WHERE appcol = 'version') = 0 THEN SELECT 'ALTER TABLE '||_target_table||' ADD COLUMN app_version text' INTO _sql;