enhance contacts: contact classes, RT#16819
[freeside.git] / FS / FS / Schema.pm
index 32f6a73..67b6823 100644 (file)
@@ -3,9 +3,9 @@ package FS::Schema;
 use vars qw(@ISA @EXPORT_OK $DEBUG $setup_hack %dbdef_cache);
 use subs qw(reload_dbdef);
 use Exporter;
-use DBIx::DBSchema 0.33;
+use DBIx::DBSchema 0.40; #0.40 for mysql upgrade fixes
 use DBIx::DBSchema::Table;
-use DBIx::DBSchema::Column 0.06;
+use DBIx::DBSchema::Column;
 use DBIx::DBSchema::Index;
 
 @ISA = qw(Exporter);
@@ -70,7 +70,7 @@ sub dbdef { $dbdef; }
 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.
+Currently, this enables "ENGINE=InnoDB" for MySQL databases.
 
 =cut
 
@@ -79,7 +79,7 @@ sub dbdef_dist {
   
   my $local_options = '';
   if ( $datasrc =~ /^dbi:mysql/i ) {
-    $local_options = 'TYPE=InnoDB';
+    $local_options = 'ENGINE=InnoDB';
   }
 
   ###
@@ -895,6 +895,8 @@ sub tables_hashref {
         'payip',    'varchar', 'NULL', 15, '', '', 
         'geocode',  'varchar', 'NULL', 20,  '', '',
         'censustract', 'varchar', 'NULL', 20,  '', '', # 7 to save space?
+        'censusyear', 'char', 'NULL', 4, '', '',
+        'district', 'varchar', 'NULL', 20, '', '',
         'tax',      'char', 'NULL', 1, '', '', 
         'otaker',   'varchar', 'NULL',    32, '', '', 
         'usernum',   'int', 'NULL', '', '', '',
@@ -936,7 +938,7 @@ sub tables_hashref {
                  ],
     },
 
-    'cust_recon' => {  # what purpose does this serve?
+    'cust_recon' => {  # (some sort of not-well understood thing for OnPac)
       'columns' => [
         'reconid',      'serial',  '',          '', '', '', 
         'recondate',    @date_type,                 '', '', 
@@ -962,7 +964,17 @@ sub tables_hashref {
       'index' => [],
     },
 
-    #eventually for cust_main too
+    'contact_class' => {
+      'columns' => [
+        'classnum',    'serial',   '',      '', '', '', 
+        'classname',   'varchar',  '', $char_d, '', '', 
+        'disabled',    'char', 'NULL',       1, '', '', 
+      ],
+      'primary_key' => 'classnum',
+      'unique' => [],
+      'index' => [ ['disabled'] ],
+    },
+
     'contact' => {
       'columns' => [
         'contactnum', 'serial',     '',      '', '', '',
@@ -1053,6 +1065,7 @@ sub tables_hashref {
         'coord_auto',         'char', 'NULL',       1, '', '',
         'country',            'char',     '',       2, '', '', 
         'geocode',         'varchar', 'NULL',      20, '', '',
+        'district',        'varchar', 'NULL',      20, '', '',
         'location_type',   'varchar', 'NULL',      20, '', '',
         'location_number', 'varchar', 'NULL',      20, '', '',
         'location_kind',      'char', 'NULL',       1, '', '',
@@ -1177,11 +1190,12 @@ sub tables_hashref {
       'index'       => [ [ 'custnum' ], [ 'billpkgnum' ] ],
     },
 
-    'cust_main_county' => { #county+state+country are checked off the
-                            #cust_main_county for validation and to provide
-                            # a tax rate.
+    'cust_main_county' => { #district+city+county+state+country are checked 
+                            #off the cust_main_county for validation and to 
+                            #provide a tax rate.
       'columns' => [
         'taxnum',   'serial',   '',    '', '', '', 
+        'district', 'varchar',  'NULL',    20, '', '',
         'city',     'varchar',  'NULL',    $char_d, '', '',
         'county',   'varchar',  'NULL',    $char_d, '', '', 
         'state',    'varchar',  'NULL',    $char_d, '', '', 
@@ -1196,7 +1210,8 @@ sub tables_hashref {
       'primary_key' => 'taxnum',
       'unique' => [],
   #    'unique' => [ ['taxnum'], ['state', 'county'] ],
-      'index' => [ [ 'city' ], [ 'county' ], [ 'state' ], [ 'country' ],
+      'index' => [ [ 'district' ], [ 'city' ], [ 'county' ], [ 'state' ], 
+                   [ 'country' ],
                    [ 'taxclass' ],
                  ],
     },
@@ -1476,6 +1491,7 @@ sub tables_hashref {
         'last_bill',      @date_type,             '', '', 
         'susp',           @date_type,             '', '', 
         'adjourn',        @date_type,             '', '', 
+        'resume',         @date_type,             '', '', 
         'cancel',         @date_type,             '', '', 
         'expire',         @date_type,             '', '', 
         'contract_end',   @date_type,             '', '',
@@ -1580,7 +1596,8 @@ sub tables_hashref {
         'percent',    'decimal',     '',   '7,4', '', '',
         'months',     'decimal', 'NULL',   '7,4', '', '',
         'disabled',      'char', 'NULL',       1, '', '', 
-        'setup',      'char', 'NULL',       1, '', '', 
+        'setup',         'char', 'NULL',       1, '', '', 
+        #'linked',        'char', 'NULL',       1, '', '',
       ],
       'primary_key' => 'discountnum',
       'unique' => [],
@@ -1801,11 +1818,12 @@ sub tables_hashref {
 
     'part_svc' => {
       'columns' => [
-        'svcpart',    'serial',    '',   '', '', '', 
-        'svc',        'varchar',   '',   $char_d, '', '', 
-        'svcdb',      'varchar',   '',   $char_d, '', '', 
-        'disabled',   'char',  'NULL',   1, '', '', 
-        'preserve',   'char', 'NULL',  1, '', '',
+        'svcpart',             'serial',     '',        '', '', '', 
+        'svc',                'varchar',     '',   $char_d, '', '', 
+        'svcdb',              'varchar',     '',   $char_d, '', '', 
+        'disabled',              'char', 'NULL',         1, '', '', 
+        'preserve',              'char', 'NULL',         1, '', '',
+        'selfservice_access', 'varchar', 'NULL',   $char_d, '', '',
       ],
       'primary_key' => 'svcpart',
       'unique' => [],
@@ -1892,6 +1910,7 @@ sub tables_hashref {
         '_password_encoding', 'varchar', 'NULL', $char_d, '', '',
         'sec_phrase', 'varchar',  'NULL',   $char_d, '', '', 
         'popnum',    'int',    'NULL',   '', '', '', 
+        'sectornum', 'int', 'NULL',      '', '', '',
         'uid',       'int', 'NULL',   '', '', '', 
         'gid',       'int', 'NULL',   '', '', '', 
         'finger',    'varchar',   'NULL',   2*$char_d, '', '', 
@@ -2118,12 +2137,13 @@ sub tables_hashref {
 
     'hardware_type' => {
       'columns' => [
-        'typenum',  'serial', '',      '', '', '',
-        'classnum',    'int', '',      '', '', '',
-        'model',   'varchar', '', $char_d, '', '',
+        'typenum',  'serial',     '',      '', '', '',
+        'classnum',    'int',     '',      '', '', '',
+        'model',   'varchar',     '', $char_d, '', '',
+        'revision','varchar', 'NULL', $char_d, '', '',
       ],
       'primary_key' => 'typenum',
-      'unique' => [ ],
+      'unique' => [ [ 'classnum', 'model', 'revision' ] ],
       'index'  => [ ],
     },
 
@@ -2278,6 +2298,7 @@ sub tables_hashref {
         'server',      'varchar', 'NULL',  64,              '', '',
         'community',   'varchar', 'NULL',  50,              '', '',
         'description', 'varchar',     '', 200, 'RADIUS Client', '',
+        'svcnum',          'int', 'NULL',  '',              '', '',
       ],
       'primary_key' => 'nasnum',
       'unique'      => [ [ 'nasname' ], ],
@@ -2474,6 +2495,7 @@ sub tables_hashref {
         'routername', 'varchar', '', $char_d, '', '', 
         'svcnum', 'int', 'NULL', '', '', '', 
         'agentnum',   'int', 'NULL', '', '', '', 
+        'manual_addr', 'char', 'NULL', 1, '', '',
       ],
       'primary_key' => 'routernum',
       'unique'      => [],
@@ -2509,6 +2531,7 @@ sub tables_hashref {
       'columns' => [
         'svcnum',                  'int',     '',      '', '', '', 
         'description',         'varchar', 'NULL', $char_d, '', '', 
+        'routernum',               'int', 'NULL',      '', '', '',
         'blocknum',                'int', 'NULL',      '', '', '', 
         'sectornum',               'int', 'NULL',      '', '', '',
         'speed_up',                'int', 'NULL',      '', '', '', 
@@ -2534,6 +2557,10 @@ sub tables_hashref {
         #'agentnum',      'int', 'NULL',      '', '', '',
         'towername', 'varchar',     '', $char_d, '', '',
         'disabled',     'char', 'NULL',       1, '', '',
+        'latitude', 'decimal', 'NULL',   '10,7', '', '', 
+        'longitude','decimal', 'NULL',   '10,7', '', '', 
+        'altitude', 'decimal', 'NULL',       '', '', '', 
+        'coord_auto',  'char', 'NULL',        1, '', '',
       ],
       'primary_key' => 'towernum',
       'unique'      => [ [ 'towername' ] ], # , 'agentnum' ] ],
@@ -2668,23 +2695,25 @@ sub tables_hashref {
 
     'rate_detail' => {
       'columns' => [
-        'ratedetailnum',   'serial',  '',     '', '', '', 
-        'ratenum',         'int',     '',     '', '', '', 
-        'orig_regionnum',  'int', 'NULL',     '', '', '', 
-        'dest_regionnum',  'int',     '',     '', '', '', 
-        'min_included',    'int',     '',     '', '', '', 
-        'conn_charge',     'decimal', '', '10,4', '0', '',
-        'conn_sec',        'int',     '',     '', '0', '',
-        'min_charge',      'decimal', '', '10,5', '', '', #@money_type, '', '', 
-        'sec_granularity', 'int',     '',     '', '', '', 
-        'ratetimenum',     'int', 'NULL',     '', '', '',
-        'classnum',        'int', 'NULL',     '', '', '', 
-        'cdrtypenum',      'int', 'NULL',     '', '', '',
-        'region_group', 'char', 'NULL',       1, '', '', 
+        'ratedetailnum',   'serial',  '',     '',      '', '', 
+        'ratenum',         'int',     '',     '',      '', '', 
+        'orig_regionnum',  'int', 'NULL',     '',      '', '', 
+        'dest_regionnum',  'int',     '',     '',      '', '', 
+        'min_included',    'int',     '',     '',      '', '', 
+        'conn_charge',     'decimal', '', '10,4', '0.0000', '',
+        'conn_sec',        'int',     '',     '',      '0', '',
+        'min_charge',      'decimal', '', '10,5',       '', '',
+        'sec_granularity', 'int',     '',     '',       '', '', 
+        'ratetimenum',     'int', 'NULL',     '',       '', '',
+        'classnum',        'int', 'NULL',     '',       '', '', 
+        'cdrtypenum',      'int', 'NULL',     '',       '', '',
+        'region_group', 'char', 'NULL',        1,       '', '', 
       ],
       'primary_key' => 'ratedetailnum',
       'unique'      => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ],
-      'index'       => [ [ 'ratenum', 'dest_regionnum' ] ],
+      'index'       => [ [ 'ratenum', 'dest_regionnum' ],
+                         [ 'ratenum', 'ratetimenum' ]
+                       ],
     },
 
     'rate_region' => {
@@ -2922,6 +2951,10 @@ sub tables_hashref {
         'lastapp',     'varchar',  '', $char_d, \"''", '', 
         'lastdata',    'varchar',  '', $char_d, \"''", '', 
 
+        #currently only opensips
+        'src_ip_addr', 'varchar',  'NULL',  15,    '', '',
+        'dst_ip_addr', 'varchar',  'NULL',  15,    '', '',
+
         #these don't seem to be logged by most of the SQL cdr_* modules
         #except tds under sql-illegal names, so;
         # ... don't rely on them for rating?
@@ -2978,9 +3011,15 @@ sub tables_hashref {
         'charged_party',       'varchar', 'NULL', $char_d, '', '',
 
         # how it was rated internally...
-        'rated_price',         'decimal', 'NULL',  '10,4', '', '',
-        'rated_seconds',           'int', 'NULL',      '', '', '',
-        'rated_minutes', 'double precision', 'NULL',   '', '', '',
+        'rated_pretty_dst',       'varchar', 'NULL', $char_d, '', '',
+        'rated_regionname',       'varchar', 'NULL', $char_d, '', '',
+        'rated_price',            'decimal', 'NULL',  '10,4', '', '',
+        'rated_seconds',              'int', 'NULL',      '', '', '',
+        'rated_minutes', 'double precision', 'NULL',      '', '', '',
+        'rated_granularity',          'int', 'NULL',      '', '', '',
+        'rated_ratedetailnum',        'int', 'NULL',      '', '', '',
+        'rated_classnum',             'int', 'NULL',      '', '', '', 
+        'rated_ratename',         'varchar', 'NULL', $char_d, '', '', 
 
         'carrierid',               'int', 'NULL',      '', '', '',
 
@@ -3015,6 +3054,7 @@ sub tables_hashref {
                    [ 'sessionnum' ], [ 'subscriber' ],
                    [ 'freesidestatus' ], [ 'freesiderewritestatus' ],
                    [ 'cdrbatch' ], [ 'cdrbatchnum' ],
+                   [ 'src_ip_addr' ], [ 'dst_ip_addr' ],
                  ],
     },