modular price plans!
[freeside.git] / FS / bin / freeside-setup
index 21defa6..bc27c79 100755 (executable)
@@ -4,8 +4,12 @@
 BEGIN { $FS::Record::setup_hack = 1; }
 
 use strict;
+use vars qw($opt_s);
+use Getopt::Std;
+use Locale::Country;
+use Locale::SubCountry;
 use DBI;
-use DBIx::DBSchema 0.20;
+use DBIx::DBSchema 0.21;
 use DBIx::DBSchema::Table;
 use DBIx::DBSchema::Column;
 use DBIx::DBSchema::ColGroup::Unique;
@@ -21,6 +25,7 @@ die "Not running uid freeside!" unless checkeuid();
 my %attrib2db =
   map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib;
 
+getopts("s");
 my $user = shift or die &usage;
 getsecrets($user);
 
@@ -33,42 +38,46 @@ my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc;
 #my($username_len)=&getvalue;
 my $username_len = 32; #usernamemax config file
 
-print "\n\n", <<END, ":";
-Freeside tracks the RADIUS User-Name, check attribute Password and
-reply attribute Framed-IP-Address for each user.  You can specify additional
-check and reply attributes (or you can add them later with the
-fs-radius-add-check and fs-radius-add-reply programs).
-
-First enter any additional RADIUS check attributes you need to track for each 
-user, separated by whitespace.
-END
-my @check_attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
-                         split(" ",&getvalue);
-
-print "\n\n", <<END, ":";
-Now enter any additional reply attributes you need to track for each user,
-separated by whitespace.
-END
-my @attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
-                   split(" ",&getvalue);
-
-print "\n\n", <<END, ":";
-Do you wish to enable the tracking of a second, separate shipping/service
-address?
-END
-my $ship = &_yesno;
-
-sub getvalue {
-  my($x)=scalar(<STDIN>);
-  chop $x;
-  $x;
-}
+#print "\n\n", <<END, ":";
+#Freeside tracks the RADIUS User-Name, check attribute Password and
+#reply attribute Framed-IP-Address for each user.  You can specify additional
+#check and reply attributes (or you can add them later with the
+#fs-radius-add-check and fs-radius-add-reply programs).
+#
+#First enter any additional RADIUS check attributes you need to track for each 
+#user, separated by whitespace.
+#END
+#my @check_attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
+#                         split(" ",&getvalue);
+#
+#print "\n\n", <<END, ":";
+#Now enter any additional reply attributes you need to track for each user,
+#separated by whitespace.
+#END
+#my @attributes = map { $attrib2db{lc($_)} or die "unknown attribute $_"; }
+#                   split(" ",&getvalue);
+#
+#print "\n\n", <<END, ":";
+#Do you wish to enable the tracking of a second, separate shipping/service
+#address?
+#END
+#my $ship = &_yesno;
+#
+#sub getvalue {
+#  my($x)=scalar(<STDIN>);
+#  chop $x;
+#  $x;
+#}
+#
+#sub _yesno {
+#  print " [y/N]:";
+#  my $x = scalar(<STDIN>);
+#  $x =~ /^y/i;
+#}
 
-sub _yesno {
-  print " [y/N]:";
-  my $x = scalar(<STDIN>);
-  $x =~ /^y/i;
-}
+my @check_attributes = (); #add later
+my @attributes = (); #add later
+my $ship = $opt_s;
 
 ###
 
@@ -104,8 +113,9 @@ my($dbdef) = new DBIx::DBSchema ( map {
 my $cust_main = $dbdef->table('cust_main');
 unless ($ship) { #remove ship_ from cust_main
   $cust_main->delcolumn($_) foreach ( grep /^ship_/, $cust_main->columns );
-} else { #add indices on ship_last and ship_company
-  push @{$cust_main->index->lol_ref}, ( ['ship_last'], ['ship_company'] ) 
+} else { #add indices
+  push @{$cust_main->index->lol_ref},
+    map { [ "ship_$_" ] } qw( last company daytime night fax );
 }
 
 #add radius attributes to svc_acct
@@ -131,33 +141,6 @@ foreach $attribute (@check_attributes) {
   ));
 }
 
-##make part_svc table (but now as object)
-#
-#my($part_svc)=$dbdef->table('part_svc');
-#
-##because of svc_acct_pop
-##foreach (grep /^svc_/, $dbdef->tables) { 
-##foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
-#foreach (qw(svc_acct svc_domain svc_forward svc_www)) {
-#  my($table)=$dbdef->table($_);
-#  my($col);
-#  foreach $col ( $table->columns ) {
-#    next if $col =~ /^svcnum$/;
-#    $part_svc->addcolumn( new DBIx::DBSchema::Column (
-#      $table->name. '__' . $table->column($col)->name,
-#      'varchar', #$table->column($col)->type, 
-#      'NULL',
-#      $char_d, #$table->column($col)->length,
-#    ));
-#    $part_svc->addcolumn ( new DBIx::DBSchema::Column (
-#      $table->name. '__'. $table->column($col)->name . "_flag",
-#      'char',
-#      'NULL',
-#      1,
-#    ));
-#  }
-#}
-
 #create history tables (false laziness w/create-history-tables)
 foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) {
   my $tableobj = $dbdef->table($table)
@@ -209,7 +192,23 @@ foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) {
                        'default' => '',
                        'local'   => '',
                      } ),
-                     map { $tableobj->column($_) } $tableobj->columns
+                     map {
+                       my $column = $tableobj->column($_);
+
+                       #clone so as to not disturb the original
+                       $column = DBIx::DBSchema::Column->new( {
+                         map { $_ => $column->$_() }
+                           qw( name type null length default local )
+                       } );
+
+                       $column->type('int')
+                         if $column->type eq 'serial';
+                       #$column->default('')
+                       #  if $column->default =~ /^nextval\(/i;
+                       #( my $local = $column->local ) =~ s/AUTO_INCREMENT//i;
+                       #$column->local($local);
+                       $column;
+                     } $tableobj->columns
                    ],
   } );
   $dbdef->addtable($h_tableobj);
@@ -233,60 +232,40 @@ foreach my $statement ( $dbdef->sql($dbh) ) {
     or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement";
 }
 
-#not really sample data (and shouldn't default to US)
-
 #cust_main_county
+foreach my $country ( sort map uc($_), all_country_codes ) {
 
-#USPS state codes
-foreach ( qw(
-AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA
-ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI 
-SC SD TN TX UT VT VI VA WA WV WI WY AE AA AP
-) ) {
-  my($cust_main_county)=new FS::cust_main_county({
-    'state' => $_,
-    'tax'   => 0,
-    'country' => 'US',
-  });  
-  my($error);
-  $error=$cust_main_county->insert;
-  die $error if $error;
-}
+  my $subcountry = eval { new Locale::SubCountry($country) };
+  my @states = $subcountry ? $subcountry->all_codes : undef;
 
-#AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson)
-foreach ( qw(
-VIC NSW NT QLD TAS ACT WA SA
-) ) {
-  my($cust_main_county)=new FS::cust_main_county({
-    'state' => $_,
-    'tax'   => 0,
-    'country' => 'AU',
-  });  
-  my($error);
-  $error=$cust_main_county->insert;
-  die $error if $error;
-}
+  if ( !scalar(@states) || ( scalar(@states) == 1 && !defined($states[0]) ) ) {
 
-#ISO 2-letter country codes (same as country TLDs) except US and AU
-foreach ( qw(
-AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO
-BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI
-HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA
-GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL
-IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV
-ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG
-NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM
-ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ
-TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH
-YE YU ZR ZM ZW
-) ) {
-  my($cust_main_county)=new FS::cust_main_county({
-    'tax'   => 0,
-    'country' => $_,
-  });  
-  my($error);
-  $error=$cust_main_county->insert;
-  die $error if $error;
+    my $cust_main_county = new FS::cust_main_county({
+      'tax'   => 0,
+      'country' => $country,
+    });  
+    my $error = $cust_main_county->insert;
+    die $error if $error;
+
+  } else {
+
+    if ( $states[0] =~ /^(\d+|\w)$/ ) {
+      @states = map $subcountry->full_name($_), @states
+    }
+
+    foreach my $state ( @states ) {
+
+      my $cust_main_county = new FS::cust_main_county({
+        'state' => $state,
+        'tax'   => 0,
+        'country' => $country,
+      });  
+      my $error = $cust_main_county->insert;
+      die $error if $error;
+
+    }
+  
+  }
 }
 
 #billing events
@@ -294,6 +273,8 @@ foreach my $aref (
   [ 'COMP', 'Comp invoice', '$cust_bill->comp();', 30, 'comp' ],
   [ 'CARD', 'Batch card', '$cust_bill->batch_card();', 40, 'batch-card' ],
   [ 'BILL', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
+  [ 'DCRD', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
+  [ 'DCHK', 'Send invoice', '$cust_bill->send();', 50, 'send' ],
 ) {
 
   my $part_bill_event = new FS::part_bill_event({
@@ -313,10 +294,10 @@ foreach my $aref (
 $dbh->commit or die $dbh->errstr;
 $dbh->disconnect or die $dbh->errstr;
 
-print "Freeside database initialized sucessfully\n";
+#print "Freeside database initialized sucessfully\n";
 
 sub usage {
-  die "Usage:\n  fs-setup user\n"; 
+  die "Usage:\n  freeside-setup [ -s ] user\n"; 
 }
 
 ###
@@ -332,20 +313,23 @@ sub tables_hash_hack {
 
     'agent' => {
       'columns' => [
-        'agentnum', 'int',            '',     '',
+        'agentnum', 'serial',            '',     '',
         'agent',    'varchar',           '',     $char_d,
         'typenum',  'int',            '',     '',
         'freq',     'int',       'NULL', '',
         'prog',     @perl_type,
+        'disabled',     'char', 'NULL', 1,
+        'username', 'varchar',       'NULL',     $char_d,
+        '_password','varchar',       'NULL',     $char_d,
       ],
       'primary_key' => 'agentnum',
       'unique' => [],
-      'index' => [ ['typenum'] ],
+      'index' => [ ['typenum'], ['disabled'] ],
     },
 
     'agent_type' => {
       'columns' => [
-        'typenum',   'int',  '', '',
+        'typenum',   'serial',  '', '',
         'atype',     'varchar', '', $char_d,
       ],
       'primary_key' => 'typenum',
@@ -365,7 +349,7 @@ sub tables_hash_hack {
 
     'cust_bill' => {
       'columns' => [
-        'invnum',    'int',  '', '',
+        'invnum',    'serial',  '', '',
         'custnum',   'int',  '', '',
         '_date',     @date_type,
         'charged',   @money_type,
@@ -374,12 +358,12 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'invnum',
       'unique' => [],
-      'index' => [ ['custnum'] ],
+      'index' => [ ['custnum'], ['_date'] ],
     },
 
     'cust_bill_event' => {
       'columns' => [
-        'eventnum',    'int',  '', '',
+        'eventnum',    'serial',  '', '',
         'invnum',   'int',  '', '',
         'eventpart',   'int',  '', '',
         '_date',     @date_type,
@@ -394,7 +378,7 @@ sub tables_hash_hack {
 
     'part_bill_event' => {
       'columns' => [
-        'eventpart',    'int',  '', '',
+        'eventpart',    'serial',  '', '',
         'payby',       'char',  '', 4,
         'event',       'varchar',           '',     $char_d,
         'eventcode',    @perl_type,
@@ -406,7 +390,7 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'eventpart',
       'unique' => [],
-      'index' => [ ['payby'] ],
+      'index' => [ ['payby'], ['disabled'], ],
     },
 
     'cust_bill_pkg' => {
@@ -417,19 +401,32 @@ sub tables_hash_hack {
         'recur',   @money_type,
         'sdate',   @date_type,
         'edate',   @date_type,
+        'itemdesc', 'varchar', 'NULL', $char_d,
       ],
       'primary_key' => '',
-      'unique' => [ ['pkgnum', 'invnum'] ],
+      'unique' => [],
       'index' => [ ['invnum'] ],
     },
 
+    'cust_bill_pkg_detail' => {
+      'columns' => [
+        'detailnum', 'serial', '', '',
+        'pkgnum',  'int', '', '',
+        'invnum',  'int', '', '',
+        'detail',  'varchar', '', $char_d,
+      ],
+      'primary_key' => 'detailnum',
+      'unique' => [],
+      'index' => [ [ 'pkgnum', 'invnum' ] ],
+    },
+
     'cust_credit' => {
       'columns' => [
-        'crednum',  'int', '', '',
+        'crednum',  'serial', '', '',
         'custnum',  'int', '', '',
         '_date',    @date_type,
         'amount',   @money_type,
-        'otaker',   'varchar', '', 8,
+        'otaker',   'varchar', '', 32,
         'reason',   'text', 'NULL', '',
         'closed',    'char', 'NULL', 1,
       ],
@@ -440,7 +437,7 @@ sub tables_hash_hack {
 
     'cust_credit_bill' => {
       'columns' => [
-        'creditbillnum', 'int', '', '',
+        'creditbillnum', 'serial', '', '',
         'crednum',  'int', '', '',
         'invnum',  'int', '', '',
         '_date',    @date_type,
@@ -453,13 +450,13 @@ sub tables_hash_hack {
 
     'cust_main' => {
       'columns' => [
-        'custnum',  'int',  '',     '',
+        'custnum',  'serial',  '',     '',
         'agentnum', 'int',  '',     '',
 #        'titlenum', 'int',  'NULL',   '',
         'last',     'varchar', '',     $char_d,
 #        'middle',   'varchar', 'NULL', $char_d,
         'first',    'varchar', '',     $char_d,
-        'ss',       'char', 'NULL', 11,
+        'ss',       'varchar', 'NULL', 11,
         'company',  'varchar', 'NULL', $char_d,
         'address1', 'varchar', '',     $char_d,
         'address2', 'varchar', 'NULL', $char_d,
@@ -487,11 +484,12 @@ sub tables_hash_hack {
         'ship_fax',      'varchar', 'NULL', 12,
         'payby',    'char', '',     4,
         'payinfo',  'varchar', 'NULL', $char_d,
+        'paycvv',   'varchar', 'NULL', 4,
         #'paydate',  @date_type,
         'paydate',  'varchar', 'NULL', 10,
         'payname',  'varchar', 'NULL', $char_d,
         'tax',      'char', 'NULL', 1,
-        'otaker',   'varchar', '',     8,
+        'otaker',   'varchar', '',    32,
         'refnum',   'int',  '',     '',
         'referral_custnum', 'int',  'NULL', '',
         'comments', 'text', 'NULL', '',
@@ -499,12 +497,14 @@ sub tables_hash_hack {
       'primary_key' => 'custnum',
       'unique' => [],
       #'index' => [ ['last'], ['company'] ],
-      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ],
+      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
+                   [ 'daytime' ], [ 'night' ], [ 'fax' ], [ 'refnum' ],
+                 ],
     },
 
     'cust_main_invoice' => {
       'columns' => [
-        'destnum',  'int',  '',     '',
+        'destnum',  'serial',  '',     '',
         'custnum',  'int',  '',     '',
         'dest',     'varchar', '',  $char_d,
       ],
@@ -517,13 +517,16 @@ sub tables_hash_hack {
                             #cust_main_county for validation and to provide
                             # a tax rate.
       'columns' => [
-        'taxnum',   'int',   '',    '',
+        'taxnum',   'serial',   '',    '',
         'state',    'varchar',  'NULL',    $char_d,
         'county',   'varchar',  'NULL',    $char_d,
         'country',  'char',  '', 2, 
         'taxclass',   'varchar', 'NULL', $char_d,
         'exempt_amount', @money_type,
         'tax',      'real',  '',    '', #tax %
+        'taxname',  'varchar',  'NULL',    $char_d,
+        'setuptax',  'char', 'NULL', 1, # Y = setup tax exempt
+        'recurtax',  'char', 'NULL', 1, # Y = recur tax exempt
       ],
       'primary_key' => 'taxnum',
       'unique' => [],
@@ -533,25 +536,45 @@ sub tables_hash_hack {
 
     'cust_pay' => {
       'columns' => [
-        'paynum',   'int',    '',   '',
+        'paynum',   'serial',    '',   '',
         #now cust_bill_pay #'invnum',   'int',    '',   '',
         'custnum',  'int',    '',   '',
         'paid',     @money_type,
         '_date',    @date_type,
         'payby',    'char',   '',     4, # CARD/BILL/COMP, should be index into
                                          # payment type table.
-        'payinfo',  'varchar',   'NULL', 16,  #see cust_main above
+        'payinfo',  'varchar',   'NULL', $char_d,  #see cust_main above
         'paybatch', 'varchar',   'NULL', $char_d, #for auditing purposes.
         'closed',    'char', 'NULL', 1,
       ],
       'primary_key' => 'paynum',
       'unique' => [],
-      'index' => [ [ 'custnum' ], [ 'paybatch' ] ],
+      'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ],
+    },
+
+    'cust_pay_void' => {
+      'columns' => [
+        'paynum',    'int',    '',   '',
+        'custnum',   'int',    '',   '',
+        'paid',      @money_type,
+        '_date',     @date_type,
+        'payby',     'char',   '',     4, # CARD/BILL/COMP, should be index into
+                                          # payment type table.
+        'payinfo',   'varchar',   'NULL', $char_d,  #see cust_main above
+        'paybatch',  'varchar',   'NULL', $char_d, #for auditing purposes.
+        'closed',    'char', 'NULL', 1,
+        'void_date', @date_type,
+        'reason',    'varchar',   'NULL', $char_d,
+        'otaker',   'varchar', '', 32,
+      ],
+      'primary_key' => 'paynum',
+      'unique' => [],
+      'index' => [ [ 'custnum' ] ],
     },
 
     'cust_bill_pay' => {
       'columns' => [
-        'billpaynum', 'int',     '',   '',
+        'billpaynum', 'serial',     '',   '',
         'invnum',  'int',     '',   '',
         'paynum',  'int',     '',   '',
         'amount',  @money_type,
@@ -565,7 +588,7 @@ sub tables_hash_hack {
     'cust_pay_batch' => { #what's this used for again?  list of customers
                           #in current CARD batch? (necessarily CARD?)
       'columns' => [
-        'paybatchnum',   'int',    '',   '',
+        'paybatchnum',   'serial',    '',   '',
         'invnum',   'int',    '',   '',
         'custnum',   'int',    '',   '',
         'last',     'varchar', '',     $char_d,
@@ -590,12 +613,13 @@ sub tables_hash_hack {
 
     'cust_pkg' => {
       'columns' => [
-        'pkgnum',    'int',    '',   '',
+        'pkgnum',    'serial',    '',   '',
         'custnum',   'int',    '',   '',
         'pkgpart',   'int',    '',   '',
-        'otaker',    'varchar', '', 8,
+        'otaker',    'varchar', '', 32,
         'setup',     @date_type,
         'bill',      @date_type,
+        'last_bill', @date_type,
         'susp',      @date_type,
         'cancel',    @date_type,
         'expire',    @date_type,
@@ -608,16 +632,16 @@ sub tables_hash_hack {
 
     'cust_refund' => {
       'columns' => [
-        'refundnum',    'int',    '',   '',
+        'refundnum',    'serial',    '',   '',
         #now cust_credit_refund #'crednum',      'int',    '',   '',
         'custnum',  'int',    '',   '',
         '_date',        @date_type,
         'refund',       @money_type,
-        'otaker',       'varchar',   '',   8,
+        'otaker',       'varchar',   '',   32,
         'reason',       'varchar',   '',   $char_d,
         'payby',        'char',   '',     4, # CARD/BILL/COMP, should be index
                                              # into payment type table.
-        'payinfo',      'varchar',   'NULL', 16,  #see cust_main above
+        'payinfo',      'varchar',   'NULL', $char_d,  #see cust_main above
         'paybatch',     'varchar',   'NULL', $char_d,
         'closed',    'char', 'NULL', 1,
       ],
@@ -628,7 +652,7 @@ sub tables_hash_hack {
 
     'cust_credit_refund' => {
       'columns' => [
-        'creditrefundnum', 'int',     '',   '',
+        'creditrefundnum', 'serial',     '',   '',
         'crednum',  'int',     '',   '',
         'refundnum',  'int',     '',   '',
         'amount',  @money_type,
@@ -642,7 +666,7 @@ sub tables_hash_hack {
 
     'cust_svc' => {
       'columns' => [
-        'svcnum',    'int',    '',   '',
+        'svcnum',    'serial',    '',   '',
         'pkgnum',    'int',    'NULL',   '',
         'svcpart',   'int',    '',   '',
       ],
@@ -653,11 +677,11 @@ sub tables_hash_hack {
 
     'part_pkg' => {
       'columns' => [
-        'pkgpart',    'int',    '',   '',
+        'pkgpart',    'serial',    '',   '',
         'pkg',        'varchar',   '',   $char_d,
         'comment',    'varchar',   '',   $char_d,
         'setup',      @perl_type,
-        'freq',       'int', '', '',  #billing frequency (months)
+        'freq',       'varchar',   '',   $char_d,  #billing frequency
         'recur',      @perl_type,
         'setuptax',  'char', 'NULL', 1,
         'recurtax',  'char', 'NULL', 1,
@@ -668,7 +692,7 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
-      'index' => [],
+      'index' => [ [ 'disabled' ], ],
     },
 
 #    'part_title' => {
@@ -686,6 +710,7 @@ sub tables_hash_hack {
         'pkgpart',    'int',    '',   '',
         'svcpart',    'int',    '',   '',
         'quantity',   'int',    '',   '',
+        'primary_svc','char', 'NULL',  1,
       ],
       'primary_key' => '',
       'unique' => [ ['pkgpart', 'svcpart'] ],
@@ -694,29 +719,30 @@ sub tables_hash_hack {
 
     'part_referral' => {
       'columns' => [
-        'refnum',   'int',    '',   '',
+        'refnum',   'serial',    '',   '',
         'referral', 'varchar',   '',   $char_d,
+        'disabled',     'char', 'NULL', 1,
       ],
       'primary_key' => 'refnum',
       'unique' => [],
-      'index' => [],
+      'index' => [ ['disabled'] ],
     },
 
     'part_svc' => {
       'columns' => [
-        'svcpart',    'int',    '',   '',
+        'svcpart',    'serial',    '',   '',
         'svc',        'varchar',   '',   $char_d,
         'svcdb',      'varchar',   '',   $char_d,
         'disabled',   'char',  'NULL',   1,
       ],
       'primary_key' => 'svcpart',
       'unique' => [],
-      'index' => [],
+      'index' => [ [ 'disabled' ] ],
     },
 
     'part_svc_column' => {
       'columns' => [
-        'columnnum',   'int',         '', '',
+        'columnnum',   'serial',         '', '',
         'svcpart',     'int',         '', '',
         'columnname',  'varchar',     '', 64,
         'columnvalue', 'varchar', 'NULL', $char_d,
@@ -730,7 +756,7 @@ sub tables_hash_hack {
     #(this should be renamed to part_pop)
     'svc_acct_pop' => {
       'columns' => [
-        'popnum',    'int',    '',   '',
+        'popnum',    'serial',    '',   '',
         'city',      'varchar',   '',   $char_d,
         'state',     'varchar',   '',   $char_d,
         'ac',        'char',   '',   3,
@@ -744,7 +770,7 @@ sub tables_hash_hack {
 
     'part_pop_local' => {
       'columns' => [
-        'localnum',  'int',     '',     '',
+        'localnum',  'serial',     '',     '',
         'popnum',    'int',     '',     '',
         'city',      'varchar', 'NULL', $char_d,
         'state',     'char',    'NULL', 2,
@@ -760,7 +786,7 @@ sub tables_hash_hack {
       'columns' => [
         'svcnum',    'int',    '',   '',
         'username',  'varchar',   '',   $username_len, #unique (& remove dup code)
-        '_password', 'varchar',   '',   50, #13 for encryped pw's plus ' *SUSPENDED* (mp5 passwords can be 34)
+        '_password', 'varchar',   '',   72, #13 for encryped pw's plus ' *SUSPENDED* (md5 passwords can be 34, blowfish 60)
         'sec_phrase', 'varchar',  'NULL',   $char_d,
         'popnum',    'int',    'NULL',   '',
         'uid',       'int', 'NULL',   '',
@@ -779,18 +805,6 @@ sub tables_hash_hack {
       'index' => [ ['username'], ['domsvc'] ],
     },
 
-#    'svc_acct_sm' => {
-#      'columns' => [
-#        'svcnum',    'int',    '',   '',
-#        'domsvc',    'int',    '',   '',
-#        'domuid',    'int', '',   '',
-#        'domuser',   'varchar',   '',   $char_d,
-#      ],
-#      'primary_key' => 'svcnum',
-#      'unique' => [ [] ],
-#      'index' => [ ['domsvc'], ['domuid'] ], 
-#    },
-
     #'svc_charge' => {
     #  'columns' => [
     #    'svcnum',    'int',    '',   '',
@@ -814,12 +828,14 @@ sub tables_hash_hack {
 
     'domain_record' => {
       'columns' => [
-        'recnum',    'int',     '',  '',
+        'recnum',    'serial',     '',  '',
         'svcnum',    'int',     '',  '',
-        'reczone',   'varchar', '',  $char_d,
+        #'reczone',   'varchar', '',  $char_d,
+        'reczone',   'varchar', '',  255,
         'recaf',     'char',    '',  2,
-        'rectype',   'char',    '',  5,
-        'recdata',   'varchar', '',  $char_d,
+        'rectype',   'varchar',    '',  5,
+        #'recdata',   'varchar', '',  $char_d,
+        'recdata',   'varchar', '',  255,
       ],
       'primary_key' => 'recnum',
       'unique'      => [],
@@ -828,10 +844,11 @@ sub tables_hash_hack {
 
     'svc_forward' => {
       'columns' => [
-        'svcnum',   'int',    '',  '',
-        'srcsvc',   'int',    '',  '',
-        'dstsvc',   'int',    '',  '',
-        'dst',      'varchar',    'NULL',  $char_d,
+        'svcnum',   'int',            '',   '',
+        'srcsvc',   'int',        'NULL',   '',
+        'src',      'varchar',    'NULL',  255,
+        'dstsvc',   'int',        'NULL',   '',
+        'dst',      'varchar',    'NULL',  255,
       ],
       'primary_key' => 'svcnum',
       'unique'      => [],
@@ -864,7 +881,7 @@ sub tables_hash_hack {
 
     'prepay_credit' => {
       'columns' => [
-        'prepaynum',   'int',     '',   '',
+        'prepaynum',   'serial',     '',   '',
         'identifier',  'varchar', '', $char_d,
         'amount',      @money_type,
         'seconds',     'int',     'NULL', '',
@@ -876,7 +893,7 @@ sub tables_hash_hack {
 
     'port' => {
       'columns' => [
-        'portnum',  'int',     '',   '',
+        'portnum',  'serial',     '',   '',
         'ip',       'varchar', 'NULL', 15,
         'nasport',  'int',     'NULL', '',
         'nasnum',   'int',     '',   '',
@@ -888,7 +905,7 @@ sub tables_hash_hack {
 
     'nas' => {
       'columns' => [
-        'nasnum',   'int',     '',    '',
+        'nasnum',   'serial',     '',    '',
         'nas',      'varchar', '',    $char_d,
         'nasip',    'varchar', '',    15,
         'nasfqdn',  'varchar', '',    $char_d,
@@ -901,7 +918,7 @@ sub tables_hash_hack {
 
     'session' => {
       'columns' => [
-        'sessionnum', 'int',       '',   '',
+        'sessionnum', 'serial',       '',   '',
         'portnum',    'int',       '',   '',
         'svcnum',     'int',       '',   '',
         'login',      @date_type,
@@ -914,7 +931,7 @@ sub tables_hash_hack {
 
     'queue' => {
       'columns' => [
-        'jobnum', 'int', '', '',
+        'jobnum', 'serial', '', '',
         'job', 'text', '', '',
         '_date', 'int', '', '',
         'status', 'varchar', '', $char_d,
@@ -928,7 +945,7 @@ sub tables_hash_hack {
 
     'queue_arg' => {
       'columns' => [
-        'argnum', 'int', '', '',
+        'argnum', 'serial', '', '',
         'jobnum', 'int', '', '',
         'arg', 'text', 'NULL', '',
       ],
@@ -939,7 +956,7 @@ sub tables_hash_hack {
 
     'queue_depend' => {
       'columns' => [
-        'dependnum', 'int', '', '',
+        'dependnum', 'serial', '', '',
         'jobnum', 'int', '', '',
         'depend_jobnum', 'int', '', '',
       ],
@@ -950,7 +967,7 @@ sub tables_hash_hack {
 
     'export_svc' => {
       'columns' => [
-        'exportsvcnum' => 'int', '', '',
+        'exportsvcnum' => 'serial', '', '',
         'exportnum'    => 'int', '', '',
         'svcpart'      => 'int', '', '',
       ],
@@ -961,7 +978,7 @@ sub tables_hash_hack {
 
     'part_export' => {
       'columns' => [
-        'exportnum', 'int', '', '',
+        'exportnum', 'serial', '', '',
         #'svcpart',   'int', '', '',
         'machine', 'varchar', '', $char_d,
         'exporttype', 'varchar', '', $char_d,
@@ -974,7 +991,7 @@ sub tables_hash_hack {
 
     'part_export_option' => {
       'columns' => [
-        'optionnum', 'int', '', '',
+        'optionnum', 'serial', '', '',
         'exportnum', 'int', '', '',
         'optionname', 'varchar', '', $char_d,
         'optionvalue', 'text', 'NULL', '',
@@ -986,7 +1003,7 @@ sub tables_hash_hack {
 
     'radius_usergroup' => {
       'columns' => [
-        'usergroupnum', 'int', '', '',
+        'usergroupnum', 'serial', '', '',
         'svcnum',       'int', '', '',
         'groupname',    'varchar', '', $char_d,
       ],
@@ -997,7 +1014,7 @@ sub tables_hash_hack {
 
     'msgcat' => {
       'columns' => [
-        'msgnum', 'int', '', '',
+        'msgnum', 'serial', '', '',
         'msgcode', 'varchar', '', $char_d,
         'locale', 'varchar', '', 16,
         'msg', 'text', '', '',
@@ -1009,7 +1026,7 @@ sub tables_hash_hack {
 
     'cust_tax_exempt' => {
       'columns' => [
-        'exemptnum', 'int', '', '',
+        'exemptnum', 'serial', '', '',
         'custnum',   'int', '', '',
         'taxnum',    'int', '', '',
         'year',      'int', '', '',
@@ -1021,7 +1038,127 @@ sub tables_hash_hack {
       'index'       => [],
     },
 
+    'router' => {
+      'columns' => [
+        'routernum', 'serial', '', '',
+        'routername', 'varchar', '', $char_d,
+        'svcnum', 'int', 'NULL', '',
+      ],
+      'primary_key' => 'routernum',
+      'unique'      => [],
+      'index'       => [],
+    },
+
+    'part_svc_router' => {
+      'columns' => [
+        'svcpart', 'int', '', '',
+       'routernum', 'int', '', '',
+      ],
+      'primary_key' => '',
+      'unique'      => [],
+      'index'       => [],
+    },
+
+    'addr_block' => {
+      'columns' => [
+        'blocknum', 'serial', '', '',
+       'routernum', 'int', '', '',
+        'ip_gateway', 'varchar', '', 15,
+        'ip_netmask', 'int', '', '',
+      ],
+      'primary_key' => 'blocknum',
+      'unique'      => [ [ 'blocknum', 'routernum' ] ],
+      'index'       => [],
+    },
+
+    'svc_broadband' => {
+      'columns' => [
+        'svcnum', 'int', '', '',
+        'blocknum', 'int', '', '',
+        'speed_up', 'int', '', '',
+        'speed_down', 'int', '', '',
+        'ip_addr', 'varchar', '', 15,
+      ],
+      'primary_key' => 'svcnum',
+      'unique'      => [],
+      'index'       => [],
+    },
+
+    'part_virtual_field' => {
+      'columns' => [
+        'vfieldpart', 'int', '', '',
+        'dbtable', 'varchar', '', 32,
+        'name', 'varchar', '', 32,
+        'check_block', 'text', 'NULL', '',
+        'length', 'int', 'NULL', '',
+        'list_source', 'text', 'NULL', '',
+        'label', 'varchar', 'NULL', 80,
+      ],
+      'primary_key' => 'vfieldpart',
+      'unique' => [],
+      'index' => [],
+    },
+
+    'virtual_field' => {
+      'columns' => [
+        'recnum', 'int', '', '',
+        'vfieldpart', 'int', '', '',
+        'value', 'varchar', '', 128,
+      ],
+      'primary_key' => '',
+      'unique' => [ [ 'vfieldpart', 'recnum' ] ],
+      'index' => [],
+    },
+
+    'acct_snarf' => {
+      'columns' => [
+        'snarfnum',  'int', '', '',
+        'svcnum',    'int', '', '',
+        'machine',   'varchar', '', 255,
+        'protocol',  'varchar', '', $char_d,
+        'username',  'varchar', '', $char_d,
+        '_password', 'varchar', '', $char_d,
+      ],
+      'primary_key' => 'snarfnum',
+      'unique' => [],
+      'index'  => [ [ 'svcnum' ] ],
+    },
+
+    'svc_external' => {
+      'columns' => [
+        'svcnum', 'int', '', '',
+        'id',     'int', 'NULL', '',
+        'title',  'varchar', 'NULL', $char_d,
+      ],
+      'primary_key' => 'svcnum',
+      'unique'      => [],
+      'index'       => [],
+    },
+
+    'cust_pay_refund' => {
+      'columns' => [
+        'payrefundnum', 'serial', '', '',
+        'paynum',  'int', '', '',
+        'refundnum',  'int', '', '',
+        '_date',    @date_type,
+        'amount',   @money_type,
+      ],
+      'primary_key' => 'payrefundnum',
+      'unique' => [],
+      'index' => [ ['paynum'], ['refundnum'] ],
+    },
 
+    'part_pkg_option' => {
+      'columns' => [
+        'optionnum', 'serial', '', '',
+        'pkgpart', 'int', '', '',
+        'optionname', 'varchar', '', $char_d,
+        'optionvalue', 'text', 'NULL', '',
+      ],
+      'primary_key' => 'optionnum',
+      'unique'      => [],
+      'index'       => [ [ 'pkgpart' ], [ 'optionname' ] ],
+    },
 
   );