From: Rogan Hamby Date: Fri, 23 Aug 2019 18:14:29 +0000 (-0400) Subject: adding a function to allow createing more than one child table off a base evergreen... X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=739ab29d9f2b1b368b0f3e62cc02fd4de5f89b8f adding a function to allow createing more than one child table off a base evergreen table --- diff --git a/mig-bin/mig-clean b/mig-bin/mig-clean index b9cb013..1ad21c0 100755 --- a/mig-bin/mig-clean +++ b/mig-bin/mig-clean @@ -105,7 +105,7 @@ sub call_clean_csv { } print join(' ',@args) . "\n"; - system('clean_csv', @args, $utf8_file); + system('/home/rhamby/git/migration-tools/text/clean_csv', @args, $utf8_file); my $dbh = Mig::db_connect(); my $clean_file = $dbh->quote($utf8_file . '.clean'); diff --git a/mig-bin/mig-convert b/mig-bin/mig-convert index 6fe2172..a0d5a12 100755 --- a/mig-bin/mig-convert +++ b/mig-bin/mig-convert @@ -110,7 +110,7 @@ sub call_convert_csv { push @args, $stage_sql_filename; print "args: " . join(',',@args) . "\n"; - system('csv2sql', @args, $clean_file); + system('/home/rhamby/git/migration-tools/text/csv2sql', @args, $clean_file); my $dbh = Mig::db_connect(); if (! -e $stage_sql_filename) { diff --git a/sql/base/base.sql b/sql/base/base.sql index 9f3c6c9..60ef86c 100644 --- a/sql/base/base.sql +++ b/sql/base/base.sql @@ -261,6 +261,36 @@ CREATE OR REPLACE FUNCTION migration_tools.build_specific_base_staging_table (TE END; $$ 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) + RETURNS void + LANGUAGE plpgsql + STRICT +AS $function$ + DECLARE + migration_schema ALIAS FOR $1; + production_table ALIAS FOR $2; + base_staging_table ALIAS FOR $3; + columns RECORD; + BEGIN + --RAISE INFO 'In migration_tools.build_specific_base_staging_table(%,%) -> %', migration_schema, production_table, base_staging_table; + PERFORM migration_tools.exec( $1, 'CREATE TABLE ' || migration_schema || '.' || base_staging_table || ' ( LIKE ' || production_table || ' INCLUDING DEFAULTS EXCLUDING CONSTRAINTS );' ); + PERFORM migration_tools.exec( $1, ' + INSERT INTO ' || migration_schema || '.fields_requiring_mapping + SELECT table_schema, table_name, column_name, data_type + FROM information_schema.columns + WHERE table_schema = ''' || migration_schema || ''' AND table_name = ''' || base_staging_table || ''' AND is_nullable = ''NO'' AND column_default IS NULL; + ' ); + FOR columns IN + SELECT table_schema, table_name, column_name, data_type + FROM information_schema.columns + WHERE table_schema = migration_schema AND table_name = base_staging_table AND is_nullable = 'NO' AND column_default IS NULL + LOOP + PERFORM migration_tools.exec( $1, 'ALTER TABLE ' || columns.table_schema || '.' || columns.table_name || ' ALTER COLUMN ' || columns.column_name || ' DROP NOT NULL;' ); + END LOOP; + END; +$function$ + CREATE OR REPLACE FUNCTION migration_tools.create_linked_legacy_table_from (TEXT,TEXT,TEXT) RETURNS VOID AS $$ DECLARE migration_schema ALIAS FOR $1;