X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=blobdiff_plain;f=unicorn%2Funicorn_bills_to_tsv.pl;h=70b5db64709c18dff06a32648e6cf14f7eb9604b;hp=0092288587308540426b4697f732d3a7ff432e29;hb=0cefde660c085b23bc9a6120762ae221cec32bbb;hpb=6678992140e18e48ee505d7adc7b077cd447fb57 diff --git a/unicorn/unicorn_bills_to_tsv.pl b/unicorn/unicorn_bills_to_tsv.pl index 0092288..70b5db6 100755 --- a/unicorn/unicorn_bills_to_tsv.pl +++ b/unicorn/unicorn_bills_to_tsv.pl @@ -1,5 +1,22 @@ #!/usr/bin/perl -w +# Copyright 2009-2012, Equinox Software, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + # Converts a Unicorn users.data, bill.data, or charge.data file to a tab-separated file. # 2009-08-10 Ben Ostrowsky @@ -9,7 +26,7 @@ my $line = 0; my $section = ''; my $field = ''; my %unique_fields; -my @output_fields = qw( l_form l_user_id l_item_id l_billing_lib l_bill_date l_bill_amt l_bill_reason ); +my @output_fields = qw( l_form l_user_id l_item_id l_billing_lib l_bill_date l_bill_amt l_bill_reason ); # in that order # Load each record while (<>) { @@ -63,10 +80,13 @@ while (<>) { $field .= $1; # Now we can actually store this line of data! -#FIXME: Assign it manually to one of the l_fields in the SQL comment below. - $records[$serial]{$field} = $3; - # print STDERR "Data extracted: \$records[$serial]{'$field'} = '$3'\n"; + if ($field eq 'USER_ID') { $records[$serial]{'l_user_id'} = $3; } + if ($field eq 'ITEM_ID') { $records[$serial]{'l_item_id'} = $3; } + if ($field eq 'BILL_DB') { $records[$serial]{'l_bill_date'} = $3; } + if ($field eq 'BILL_AMOUNT') { $records[$serial]{'l_bill_amt'} = $3; } + if ($field eq 'BILL_LIBRARY') { $records[$serial]{'l_billing_lib'} = $3; } + if ($field eq 'BILL_REASON') { $records[$serial]{'l_bill_reason'} = $3; } next; } @@ -82,26 +102,7 @@ while (<>) { print STDERR "Loaded " . scalar(@records) . " records.\n"; - -#CREATE OR REPLACE FUNCTION migration_tools.unicorn_create_money_table (TEXT) RETURNS VOID AS $$ -# DECLARE -# migration_schema ALIAS FOR $1; -# BEGIN -# PERFORM migration_tools.exec( $1, 'CREATE TABLE ' || migration_schema || '.money_grocery_unicorn ( -# l_form TEXT NOT NULL CHECK ( l_form = ''LDBILL'' ), -# l_user_id TEXT, -# l_item_id TEXT, -# l_billing_lib TEXT, -# l_bill_date TEXT, -# l_bill_amt TEXT, -# l_bill_reason TEXT -# ) INHERITS ( ' || migration_schema || '.money_grocery);' ); -# END; -#$$ LANGUAGE PLPGSQL STRICT STABLE; - - # Print a header line -print "SERIAL\t"; foreach $i (@output_fields) { print "$i\t"; } @@ -114,7 +115,7 @@ for (my $u = 0; $u < @records; $u++) { if (defined $records[$u]{$f}) { print $records[$u]{$f}; } - print "\t"; + print "\t"; } print "\n"; }