#!/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 <ben@esilibrary.com>
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 (<>) {
$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;
}
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";
}
if (defined $records[$u]{$f}) {
print $records[$u]{$f};
}
- print "\t";
+ print "\t";
}
print "\n";
}