update the tax class editor to enable taxclass adding, RT#2929
[freeside.git] / FS / FS / Schema.pm
index adc32a2..9548aa7 100644 (file)
@@ -65,13 +65,22 @@ assuming it is up-to-date).  See L<DBIx::DBSchema>.
 
 sub dbdef { $dbdef; }
 
-=item dbdef_dist [ OPTION => VALUE ... ]
+=item dbdef_dist [ DATASRC ]
 
 Returns the current canoical database definition as defined in this file.
 
+Optionally, pass a DBI data source to enable syntax specific to that database.
+Currently, this enables "TYPE=InnoDB" for MySQL databases.
+
 =cut
 
 sub dbdef_dist {
+  my $datasrc = @_ ? shift : '';
+  
+  my $local_options = '';
+  if ( $datasrc =~ /^dbi:mysql/i ) {
+    $local_options = 'TYPE=InnoDB';
+  }
 
   ###
   # create a dbdef object from the old data structure
@@ -79,7 +88,6 @@ sub dbdef_dist {
 
   my $tables_hashref = tables_hashref();
 
-
   #turn it into objects
   my $dbdef = new DBIx::DBSchema map {  
 
@@ -125,10 +133,11 @@ sub dbdef_dist {
                        @$index;
 
     DBIx::DBSchema::Table->new({
-      'name'        => $tablename,
-      'primary_key' => $tables_hashref->{$tablename}{'primary_key'},
-      'columns'     => \@columns,
-      'indices'     => \@indices,
+      'name'          => $tablename,
+      'primary_key'   => $tables_hashref->{$tablename}{'primary_key'},
+      'columns'       => \@columns,
+      'indices'       => \@indices,
+      'local_options' => $local_options,
     });
 
   } keys %$tables_hashref;
@@ -184,66 +193,104 @@ sub dbdef_dist {
                         keys %indices;
 
     my $h_tableobj = DBIx::DBSchema::Table->new( {
-      'name'        => "h_$table",
-      'primary_key' => 'historynum',
-      'indices'     => \%h_indices,
-      'columns'     => [
-                         DBIx::DBSchema::Column->new( {
-                           'name'    => 'historynum',
-                           'type'    => 'serial',
-                           'null'    => 'NOT NULL',
-                           'length'  => '',
-                           'default' => '',
-                           'local'   => '',
-                         } ),
-                         DBIx::DBSchema::Column->new( {
-                           'name'    => 'history_date',
-                           'type'    => 'int',
-                           'null'    => 'NULL',
-                           'length'  => '',
-                           'default' => '',
-                           'local'   => '',
-                         } ),
-                         DBIx::DBSchema::Column->new( {
-                           'name'    => 'history_user',
-                           'type'    => 'varchar',
-                           'null'    => 'NOT NULL',
-                           'length'  => '80',
-                           'default' => '',
-                           'local'   => '',
-                         } ),
-                         DBIx::DBSchema::Column->new( {
-                           'name'    => 'history_action',
-                           'type'    => 'varchar',
-                           'null'    => 'NOT NULL',
-                           'length'  => '80',
-                           'default' => '',
-                           'local'   => '',
-                         } ),
-                         map {
-                           my $column = $tableobj->column($_);
+      'name'          => "h_$table",
+      'primary_key'   => 'historynum',
+      'indices'       => \%h_indices,
+      'local_options' => $local_options,
+      'columns'       => [
+          DBIx::DBSchema::Column->new( {
+            'name'    => 'historynum',
+            'type'    => 'serial',
+            'null'    => 'NOT NULL',
+            'length'  => '',
+            'default' => '',
+            'local'   => '',
+          } ),
+          DBIx::DBSchema::Column->new( {
+            'name'    => 'history_date',
+            'type'    => 'int',
+            'null'    => 'NULL',
+            'length'  => '',
+            'default' => '',
+            'local'   => '',
+          } ),
+          DBIx::DBSchema::Column->new( {
+            'name'    => 'history_user',
+            'type'    => 'varchar',
+            'null'    => 'NOT NULL',
+            'length'  => '80',
+            'default' => '',
+            'local'   => '',
+          } ),
+          DBIx::DBSchema::Column->new( {
+            'name'    => 'history_action',
+            'type'    => 'varchar',
+            'null'    => 'NOT NULL',
+            'length'  => '80',
+            'default' => '',
+            'local'   => '',
+          } ),
+          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 )
-                           } );
+            #clone so as to not disturb the original
+            $column = DBIx::DBSchema::Column->new( {
+              map { $_ => $column->$_() }
+                qw( name type null length default local )
+            } );
     
-                           if ( $column->type eq 'serial' ) {
-                             $column->type('int');
-                             $column->null('NULL');
-                           }
-                           #$column->default('')
-                           #  if $column->default =~ /^nextval\(/i;
-                           #( my $local = $column->local ) =~ s/AUTO_INCREMENT//i;
-                           #$column->local($local);
-                           $column;
-                         } $tableobj->columns
-                     ],
+            if ( $column->type =~ /^(\w*)SERIAL$/i ) {
+              $column->type('int');
+              $column->null('NULL');
+            }
+            #$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);
   }
 
+  if ( $datasrc =~ /^dbi:mysql/i ) {
+
+    my $dup_lock_table = DBIx::DBSchema::Table->new( {
+      'name'          => 'duplicate_lock',
+      'primary_key'   => 'duplocknum',
+      'local_options' => $local_options,
+      'columns'       => [
+        DBIx::DBSchema::Column->new( {
+          'name'    => 'duplocknum',
+          'type'    => 'serial',
+          'null'    => 'NOT NULL',
+          'length'  => '',
+          'default' => '',
+          'local'   => '',
+        } ),
+        DBIx::DBSchema::Column->new( {
+          'name'    => 'lockname',
+          'type'    => 'varchar',
+          'null'    => 'NOT NULL',
+          'length'  => '80',
+          'default' => '',
+          'local'   => '',
+        } ),
+      ],
+      'indices' => { 'duplicate_lock1' =>
+                       DBIx::DBSchema::Index->new({
+                         'name'    => 'duplicate_lock1',
+                         'unique'  => 1,
+                         'columns' => [ 'lockname' ],
+                       })
+                   },
+    } );
+
+    $dbdef->addtable($dup_lock_table);
+
+  }
+
   $dbdef;
 
 }
@@ -465,11 +512,12 @@ sub tables_hashref {
         'amount',   @money_type, '', '', 
         'otaker',   'varchar', '', 32, '', '', 
         'reason',   'text', 'NULL', '', '', '', 
+        'reasonnum', 'int', 'NULL', '', '', '', 
         'closed',    'char', 'NULL', 1, '', '', 
       ],
       'primary_key' => 'crednum',
       'unique' => [],
-      'index' => [ ['custnum'] ],
+      'index' => [ ['custnum'], ['_date'] ],
     },
 
     'cust_credit_bill' => {
@@ -617,13 +665,39 @@ sub tables_hashref {
       'index' => [ [ 'county' ], [ 'state' ], [ 'country' ] ],
     },
 
+    'cust_pay_pending' => {
+      'columns' => [
+        'paypendingnum','serial',      '',  '', '', '',
+        'custnum',      'int',         '',  '', '', '', 
+        'paid',         @money_type,            '', '', 
+        '_date',        @date_type,             '', '', 
+        'payby',        'char',        '',   4, '', '', #CARD/BILL/COMP, should
+                                                        # be index into payby
+                                                        # table eventually
+        'payinfo',      'varchar', 'NULL', 512, '', '', #see cust_main above
+       'paymask',      'varchar', 'NULL', $char_d, '', '', 
+        'paydate',      'varchar', 'NULL', 10, '', '', 
+        #'paybatch',     'varchar', 'NULL', $char_d, '', '', #for auditing purposes.
+        'payunique',    'varchar', 'NULL', $char_d, '', '', #separate paybatch "unique" functions from current usage
+
+        'status',       'varchar',     '', $char_d, '', '', 
+        'statustext',   'text',    'NULL',  '', '', '', 
+        'gatewaynum',   'int',     'NULL',  '', '', '',
+        #'cust_balance', @money_type,            '', '',
+        'paynum',       'int',     'NULL',  '', '', '',
+      ],
+      'primary_key' => 'paypendingnum',
+      'unique'      => [ [ 'payunique' ] ],
+      'index'       => [ [ 'custnum' ], [ 'status' ], ],
+    },
+
     'cust_pay' => {
       'columns' => [
         'paynum',   'serial',    '',   '', '', '',
-        #now cust_bill_pay #'invnum',   'int',    '',   '', '', '', 
         'custnum',  'int',    '',   '', '', '', 
-        'paid',     @money_type, '', '', 
         '_date',    @date_type, '', '', 
+        'paid',     @money_type, '', '', 
+        'otaker',   'varchar', 'NULL', 32, '', '',  #NULL for the upgrade so we can create & populate the field
         'payby',    'char',   '',     4, '', '', # CARD/BILL/COMP, should be
                                                  # index into payby table
                                                  # eventually
@@ -635,7 +709,7 @@ sub tables_hashref {
         'closed',    'char', 'NULL', 1, '', '', 
       ],
       'primary_key' => 'paynum',
-      'unique' => [ [ 'payunique' ] ],
+      #i guess not now, with cust_pay_pending, if we actually make it here, we _do_ want to record it# 'unique' => [ [ 'payunique' ] ],
       'index' => [ [ 'custnum' ], [ 'paybatch' ], [ 'payby' ], [ '_date' ] ],
     },
 
@@ -746,24 +820,28 @@ sub tables_hashref {
 
     'cust_pkg' => {
       'columns' => [
-        'pkgnum',    'serial',    '',   '', '', '', 
-        'custnum',   'int',    '',   '', '', '', 
-        'pkgpart',   'int',    '',   '', '', '', 
-        'otaker',    'varchar', '', 32, '', '', 
-        'setup',     @date_type, '', '', 
-        'bill',      @date_type, '', '', 
-        'last_bill', @date_type, '', '', 
-        'susp',      @date_type, '', '', 
-        'adjourn',   @date_type, '', '', 
-        'cancel',    @date_type, '', '', 
-        'expire',    @date_type, '', '', 
-        'manual_flag', 'char', 'NULL', 1, '', '', 
+        'pkgnum',         'serial',    '',   '', '', '', 
+        'custnum',        'int',    '',   '', '', '', 
+        'pkgpart',        'int',    '',   '', '', '', 
+        'otaker',         'varchar', '', 32, '', '', 
+        'setup',          @date_type, '', '', 
+        'bill',           @date_type, '', '', 
+        'last_bill',      @date_type, '', '', 
+        'susp',           @date_type, '', '', 
+        'adjourn',        @date_type, '', '', 
+        'cancel',         @date_type, '', '', 
+        'expire',         @date_type, '', '', 
+        'change_date',    @date_type, '', '',
+        'change_pkgnum',  'int', 'NULL', '', '', '',
+        'change_pkgpart', 'int', 'NULL', '', '', '',
+        'manual_flag',    'char', 'NULL', 1, '', '', 
       ],
       'primary_key' => 'pkgnum',
       'unique' => [],
       'index' => [ ['custnum'], ['pkgpart'],
                    ['setup'], ['last_bill'], ['bill'], ['susp'], ['adjourn'],
-                   ['expire'], ['cancel']
+                   ['expire'], ['cancel'],
+                   ['change_date'],
                  ],
     },
 
@@ -795,7 +873,6 @@ sub tables_hashref {
     'cust_refund' => {
       'columns' => [
         'refundnum',    'serial',    '',   '', '', '', 
-        #now cust_credit_refund #'crednum',      'int',    '',   '', '', '',
         'custnum',  'int',    '',   '', '', '', 
         '_date',        @date_type, '', '', 
         'refund',       @money_type, '', '', 
@@ -811,7 +888,7 @@ sub tables_hashref {
       ],
       'primary_key' => 'refundnum',
       'unique' => [],
-      'index' => [ [ 'custnum' ] ],
+      'index' => [ ['custnum'], ['_date'] ],
     },
 
     'cust_credit_refund' => {
@@ -824,7 +901,7 @@ sub tables_hashref {
       ],
       'primary_key' => 'creditrefundnum',
       'unique' => [],
-      'index' => [ [ 'crednum', 'refundnum' ] ],
+      'index' => [ ['crednum'], ['refundnum'] ],
     },
 
 
@@ -858,10 +935,22 @@ sub tables_hashref {
         'classnum',      'int',     'NULL', '', '', '', 
         'pay_weight',    'real',    'NULL', '', '', '',
         'credit_weight', 'real',    'NULL', '', '', '',
+        'agentnum',      'int',     'NULL', '', '', '', 
+
       ],
       'primary_key' => 'pkgpart',
       'unique' => [],
-      'index' => [ [ 'promo_code' ], [ 'disabled' ] ],
+      'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ],
+    },
+
+    'part_pkg_taxclass' => {
+      'columns' => [
+        'taxclassnum',  'serial', '',       '', '', '',
+        'taxclass',     'varchar', '', $char_d, '', '', 
+      ],
+      'primary_key' => 'taxclassnum',
+      'unique'      => [ [ 'taxclass' ] ],
+      'index'       => [],
     },
 
 #    'part_title' => {
@@ -896,7 +985,7 @@ sub tables_hashref {
       ],
       'primary_key' => 'refnum',
       'unique' => [],
-      'index' => [ ['disabled'] ],
+      'index' => [ ['disabled'], ['agentnum'], ],
     },
 
     'part_svc' => {
@@ -977,6 +1066,8 @@ sub tables_hashref {
         'totalbytes','bigint', 'NULL',   '', '', '',
         'totalbytes_threshold',   'bigint', 'NULL',   '', '', '',
         'domsvc',    'int', '',   '', '', '', 
+        'last_login',  @date_type, '', '', 
+        'last_logout', @date_type, '', '', 
       ],
       'primary_key' => 'svcnum',
       #'unique' => [ [ 'username', 'domsvc' ] ],
@@ -984,6 +1075,20 @@ sub tables_hashref {
       'index' => [ ['username'], ['domsvc'] ],
     },
 
+    'acct_rt_transaction' => {
+      'columns' => [
+        'svcrtid',   'int',    '',   '', '', '', 
+        'svcnum',    'int',    '',   '', '', '', 
+        'transaction_id',       'int', '',   '', '', '', 
+        '_date',   @date_type, '', '',
+        'seconds',   'int', '',   '', '', '', #uhhhh
+        'support',   'int', '',   '', '', '',
+      ],
+      'primary_key' => 'svcrtid',
+      'unique' => [],
+      'index' => [ ['svcnum', 'transaction_id'] ],
+    },
+
     #'svc_charge' => {
     #  'columns' => [
     #    'svcnum',    'int',    '',   '',
@@ -1002,7 +1107,7 @@ sub tables_hashref {
         'catchall',         'int', 'NULL',       '', '', '',
        'parent_svcnum',    'int', 'NULL',       '', '', '',
        'registrarnum',     'int', 'NULL',       '', '', '',
-       'registrarkey', 'varchar', 'NULL',       '', '', '',
+       'registrarkey', 'varchar', 'NULL',      512, '', '',
        'setup_date',  @date_type, '', '',
        'renewal_interval', 'int', 'NULL',       '', '', '',
        'expiration_date', @date_type, '', '',
@@ -1136,6 +1241,8 @@ sub tables_hashref {
         'status', 'varchar', '', $char_d, '', '', 
         'statustext', 'text', 'NULL', '', '', '', 
         'svcnum', 'int', 'NULL', '', '', '', 
+        'secure',  'char', 'NULL', 1, '', '', # Y = needs to be run on machine
+                                              #     w/private key
       ],
       'primary_key' => 'jobnum',
       'unique'      => [],
@@ -1554,7 +1661,8 @@ sub tables_hashref {
         ###
 
         'acctid',   'bigserial',  '', '', '', '', 
-        'calldate', 'TIMESTAMP with time zone', '', '', \'now()', '',
+        #'calldate', 'TIMESTAMP with time zone', '', '', \'now()', '',
+        'calldate', 'timestamp',   '',      '', \'now()', '',
         'clid',        'varchar',  '', $char_d, \"''", '', 
         'src',         'varchar',  '', $char_d, \"''", '', 
         'dst',         'varchar',  '', $char_d, \"''", '', 
@@ -1646,7 +1754,7 @@ sub tables_hashref {
     'cdr_type' => {
       'columns' => [
         'cdrtypenum'  => 'serial',  '', '', '', '',
-        'cdrtypename' => 'varchar', '', '', '', '',
+        'cdrtypename' => 'varchar', '', $char_d, '', '',
       ],
       'primary_key' => 'cdrtypenum',
       'unique'      => [],
@@ -1656,7 +1764,7 @@ sub tables_hashref {
     'cdr_carrier' => {
       'columns' => [
         'carrierid'   => 'serial',  '', '', '', '',
-        'carriername' => 'varchar', '', '', '', '',
+        'carriername' => 'varchar', '', $char_d, '', '',
       ],
       'primary_key' => 'carrierid',
       'unique'      => [],
@@ -1717,6 +1825,7 @@ sub tables_hashref {
         'usernum',     'int',       '', '', '', '',
         'prefname', 'varchar', '', $char_d, '', '', 
         'prefvalue', 'text', 'NULL', '', '', '', 
+        'expiration', @date_type, '', '',
       ],
       'primary_key' => 'prefnum',
       'unique' => [],
@@ -1760,7 +1869,7 @@ sub tables_hashref {
         'rightnum',   'serial', '',      '', '', '',
         'righttype', 'varchar', '', $char_d, '', '',
         'rightobjnum',   'int', '',      '', '', '',
-        'rightname', 'varchar', '',      '', '', '',
+        'rightname', 'varchar', '', $char_d, '', '',
       ],
       'primary_key' => 'rightnum',
       'unique' => [ [ 'righttype', 'rightobjnum', 'rightname' ] ],
@@ -1794,7 +1903,7 @@ sub tables_hashref {
       'columns' => [
         'reasonnum',     'serial',  '', '', '', '', 
         'reason_type',   'int',  '', '', '', '', 
-        'reason',        'varchar', '', $char_d, '', '', 
+        'reason',        'text', '', '', '', '', 
         'disabled',      'char',    'NULL', 1, '', '', 
       ],
       'primary_key' => 'reasonnum',
@@ -1807,7 +1916,7 @@ sub tables_hashref {
         'confnum',  'serial',  '', '', '', '', 
         'agentnum', 'int',  'NULL', '', '', '', 
         'name',     'varchar', '', $char_d, '', '', 
-        'value',    'varchar', 'NULL', '', '', '',       # Pg specific
+        'value',    'text', 'NULL', '', '', '',
       ],
       'primary_key' => 'confnum',
       'unique' => [ [ 'agentnum', 'name' ]],