From 94ad770eb806300c3b304b1ecb61f6341ec42947 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 20 Mar 2009 19:10:17 +0000 Subject: [PATCH] --- sql/base/base.sql | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sql/base/base.sql b/sql/base/base.sql index 0882711..b9d4121 100644 --- a/sql/base/base.sql +++ b/sql/base/base.sql @@ -9,7 +9,7 @@ -- \d foo.actor_usr -- create some incoming ILS specific staging tables, like CREATE foo.legacy_items ( l_barcode TEXT, .. ) INHERITS foo.asset_copy; -- Do some mapping, like UPDATE foo.legacy_items SET barcode = TRIM(BOTH ' ' FROM l_barcode); --- Then, to move into production, do: select migration_tools.insert_default_into_production('foo') +-- Then, to move into production, do: select migration_tools.insert_base_into_production('foo') CREATE SCHEMA migration_tools; @@ -30,11 +30,16 @@ CREATE OR REPLACE FUNCTION migration_tools.init (TEXT) RETURNS VOID AS $$ DECLARE migration_schema ALIAS FOR $1; BEGIN - EXECUTE 'CREATE SCHEMA ' || migration_schema || ';'; + EXECUTE 'DROP TABLE IF EXISTS ' || migration_schema || '.config;'; EXECUTE 'CREATE TABLE ' || migration_schema || '.config ( key TEXT UNIQUE, value TEXT);'; EXECUTE 'INSERT INTO ' || migration_schema || '.config (key,value) VALUES ( ''production_tables'', ''asset.call_number,asset.copy_location,asset.copy,asset.stat_cat,asset.stat_cat_entry,asset.stat_cat_entry_copy_map,asset.copy_note,actor.usr,actor.card,actor.usr_address,actor.stat_cat,actor.stat_cat_entry,actor.stat_cat_entry_usr_map,actor.usr_note,action.circulation,action.hold_request,money.grocery,money.billing,money.cash_payment,money.forgive_payment'' );'; EXECUTE 'DROP TABLE IF EXISTS ' || migration_schema || '.fields_requiring_mapping;'; EXECUTE 'CREATE TABLE ' || migration_schema || '.fields_requiring_mapping( table_schema TEXT, table_name TEXT, column_name TEXT, data_type TEXT);'; + BEGIN + EXECUTE 'INSERT INTO ' || migration_schema || '.config (key,value) VALUES ( ''last_init'', now() );'; + EXCEPTION + WHEN OTHERS THEN EXECUTE 'UPDATE ' || migration_schema || '.config SET value = now() WHERE key = ''last_init'';'; + END; END; $$ LANGUAGE PLPGSQL STRICT VOLATILE; @@ -87,7 +92,7 @@ CREATE OR REPLACE FUNCTION migration_tools.build_specific_base_staging_table (TE END; $$ LANGUAGE PLPGSQL STRICT VOLATILE; -CREATE OR REPLACE FUNCTION migration_tools.insert_default_into_production (TEXT) RETURNS VOID AS $$ +CREATE OR REPLACE FUNCTION migration_tools.insert_base_into_production (TEXT) RETURNS VOID AS $$ DECLARE migration_schema ALIAS FOR $1; production_tables TEXT[]; -- 1.7.2.5