BEGIN
SELECT migration_tools.production_tables(migration_schema) INTO STRICT production_tables;
PERFORM migration_tools.build_base_staging_tables(migration_schema,production_tables);
- EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_patron_barcode_key ON ' || migration_schema || '.actor_card ( barcode );';
- EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_patron_usrname_key ON ' || migration_schema || '.actor_usr ( usrname );';
- EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_copy_barcode_key ON ' || migration_schema || '.asset_copy ( barcode );';
- EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_copy_id_key ON ' || migration_schema || '.asset_copy ( id );';
- EXECUTE 'CREATE INDEX ' || migration_schema || '_callnum_record_idx ON ' || migration_schema || '.asset_call_number ( record );';
- EXECUTE 'CREATE INDEX ' || migration_schema || '_callnum_upper_label_id_lib_idx ON ' || migration_schema || '.asset_call_number ( UPPER(label),id,owning_lib );';
- EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_callnum_label_once_per_lib ON ' || migration_schema || '.asset_call_number ( record,owning_lib,label,prefix,suffix );';
+ EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_patron_barcode_key ON ' || migration_schema || '.m_actor_card ( barcode );';
+ EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_patron_usrname_key ON ' || migration_schema || '.m_actor_usr ( usrname );';
+ EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_copy_barcode_key ON ' || migration_schema || '.m_asset_copy ( barcode );';
+ EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_copy_id_key ON ' || migration_schema || '.m_asset_copy ( id );';
+ EXECUTE 'CREATE INDEX ' || migration_schema || '_callnum_record_idx ON ' || migration_schema || '.m_asset_call_number ( record );';
+ EXECUTE 'CREATE INDEX ' || migration_schema || '_callnum_upper_label_id_lib_idx ON ' || migration_schema || '.m_asset_call_number ( UPPER(label),id,owning_lib );';
+ EXECUTE 'CREATE UNIQUE INDEX ' || migration_schema || '_callnum_label_once_per_lib ON ' || migration_schema || '.m_asset_call_number ( record,owning_lib,label,prefix,suffix );';
END;
$$ LANGUAGE PLPGSQL STRICT VOLATILE;
base_staging_table TEXT;
columns RECORD;
BEGIN
- base_staging_table = REPLACE( production_table, '.', '_' );
+ base_staging_table = REPLACE( 'm_' || production_table, '.', '_' );
EXECUTE 'CREATE TABLE ' || migration_schema || '.' || base_staging_table || ' ( LIKE ' || production_table || ' INCLUDING DEFAULTS EXCLUDING CONSTRAINTS );';
FOR columns IN
SELECT table_schema, table_name, column_name, data_type
BEGIN
create_sql := 'CREATE TABLE ' || migration_schema || '.' || parent_table || '_legacy ( ';
FOR columns IN
- SELECT table_schema, table_name, column_name, data_type
+ SELECT table_schema, table_name, column_name, data_type, numeric_precision, numeric_scale
FROM information_schema.columns
WHERE table_schema = migration_schema AND table_name = source_table
LOOP
create_sql := create_sql || columns.column_name || ' ';
if columns.data_type = 'ARRAY' then
create_sql := create_sql || 'TEXT[]';
+ elsif columns.data_type = 'numeric' then
+ create_sql := create_sql || 'NUMERIC('||columns.numeric_precision||','||columns.numeric_scale||')';
else
create_sql := create_sql || columns.data_type;
end if;
$$ LANGUAGE PLPGSQL STRICT VOLATILE;
-- creates other child table so you can have more than one child table in a schema from a base table
-CREATE OR REPLACE FUNCTION build_variant_staging_table(text, text, text)
+CREATE OR REPLACE FUNCTION migration_tools.build_variant_staging_table(text, text, text)
RETURNS void
LANGUAGE plpgsql
STRICT