fix agent username and password nullability
[freeside.git] / FS / bin / freeside-setup
index e8bb7ec..b7b45dc 100755 (executable)
@@ -111,8 +111,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
@@ -189,7 +190,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);
@@ -274,6 +291,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({
@@ -317,6 +336,9 @@ sub tables_hash_hack {
         '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' => [],
@@ -354,7 +376,7 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'invnum',
       'unique' => [],
-      'index' => [ ['custnum'] ],
+      'index' => [ ['custnum'], ['_date'] ],
     },
 
     'cust_bill_event' => {
@@ -397,12 +419,25 @@ 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',  'serial', '', '',
@@ -439,7 +474,7 @@ sub tables_hash_hack {
         '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,
@@ -479,7 +514,9 @@ sub tables_hash_hack {
       'primary_key' => 'custnum',
       'unique' => [],
       #'index' => [ ['last'], ['company'] ],
-      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ] ],
+      'index' => [ ['last'], [ 'company' ], [ 'referral_custnum' ],
+                   [ 'daytime' ], [ 'night' ], [ 'fax' ],
+                 ],
     },
 
     'cust_main_invoice' => {
@@ -504,6 +541,9 @@ sub tables_hash_hack {
         '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' => [],
@@ -520,7 +560,7 @@ sub tables_hash_hack {
         '_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,
       ],
@@ -576,6 +616,7 @@ sub tables_hash_hack {
         'otaker',    'varchar', '', 32,
         'setup',     @date_type,
         'bill',      @date_type,
+        'last_bill', @date_type,
         'susp',      @date_type,
         'cancel',    @date_type,
         'expire',    @date_type,
@@ -597,7 +638,7 @@ sub tables_hash_hack {
         '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,
       ],
@@ -648,7 +689,7 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
-      'index' => [],
+      'index' => [ [ 'disabled' ], ],
     },
 
 #    'part_title' => {
@@ -691,7 +732,7 @@ sub tables_hash_hack {
       ],
       'primary_key' => 'svcpart',
       'unique' => [],
-      'index' => [],
+      'index' => [ [ 'disabled' ] ],
     },
 
     'part_svc_column' => {
@@ -740,7 +781,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',   '',
@@ -784,10 +825,12 @@ sub tables_hash_hack {
       'columns' => [
         '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'      => [],
@@ -989,76 +1032,90 @@ sub tables_hash_hack {
       'index'       => [],
     },
 
-    'ac_type' => {
+    'router' => {
       'columns' => [
-        'actypenum', 'serial', '', '',
-        'actypename', 'varchar', '', $char_d,
+        'routernum', 'serial', '', '',
+        'routername', 'varchar', '', $char_d,
+        'svcnum', 'int', 'NULL', '',
       ],
-      'primary_key' => 'actypenum',
+      'primary_key' => 'routernum',
       'unique'      => [],
       'index'       => [],
     },
 
-    'ac' => {
+    'part_svc_router' => {
       'columns' => [
-        'acnum', 'serial', '', '',
-        'actypenum', 'int', '', '',
-        'acname', 'varchar', '', $char_d,
+        'svcpart', 'int', '', '',
+       'routernum', 'int', '', '',
       ],
-      'primary_key' => 'acnum',
+      'primary_key' => '',
       'unique'      => [],
-      'index'       => [ [ 'actypenum' ] ],
+      'index'       => [],
     },
 
-    'part_ac_field' => {
+    'addr_block' => {
       'columns' => [
-        'acfieldpart', 'serial', '', '',
-        'actypenum', 'int', '', '',
-        'name', 'varchar', '', $char_d,
-        'ut_type', 'varchar', '', $char_d,
+        'blocknum', 'serial', '', '',
+       'routernum', 'int', '', '',
+        'ip_gateway', 'varchar', '', 15,
+        'ip_netmask', 'int', '', '',
       ],
-      'primary_key' => 'acfieldpart',
+      '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'       => [ [ 'actypenum' ] ],
+      'index'       => [],
     },
 
-    'ac_field' => {
+    'part_virtual_field' => {
       'columns' => [
-        'acfieldpart', 'int', '', '',
-        'acnum', 'int', '', '',
-        'value', 'text', '', '',
+        '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' => '',
-      'unique'      => [ [ 'acfieldpart', 'acnum' ] ],
-      'index'       => [ [ 'acnum' ] ],
+      'primary_key' => 'vfieldpart',
+      'unique' => [],
+      'index' => [],
     },
 
-    'ac_block' => {
+    'virtual_field' => {
       'columns' => [
-        'acnum', 'int', '', '',
-        'ip_gateway', 'varchar', '', 15,
-        'ip_netmask', 'int', '', '',
+        'recnum', 'int', '', '',
+        'vfieldpart', 'int', '', '',
+        'value', 'varchar', '', 128,
       ],
       'primary_key' => '',
-      'unique'      => [],
-      'index'       => [ [ 'acnum' ] ],
+      'unique' => [ [ 'vfieldpart', 'recnum' ] ],
+      'index' => [],
     },
 
-    'svc_broadband' => {
+    'acct_snarf' => {
       'columns' => [
-        'svcnum', 'int', '', '',
-        'actypenum', 'int', '', '',
-        'speed_up', 'int', '', '',
-        'speed_down', 'int', '', '',
-        'acnum', 'int', '', '',
-        'ip_addr', 'varchar', '', 15,
-        'ip_netmask', 'int', '', '',
-        'mac_addr', 'char', '', 17,
-        'location', 'varchar', '', $char_d,
+        'snarfnum',  'int', '', '',
+        'svcnum',    'int', '', '',
+        'machine',   'varchar', '', 255,
+        'protocol',  'varchar', '', $char_d,
+        'username',  'varchar', '', $char_d,
+        '_password', 'varchar', '', $char_d,
       ],
-      'primary_key' => 'svcnum',
-      'unique'      => [],
-      'index'       => [ [ 'actypenum' ] ],
+      'primary_key' => 'snarfnum',
+      'unique' => [],
+      'index'  => [ [ 'svcnum' ] ],
     },
 
   );