VoipNow export, #11170
[freeside.git] / FS / FS / Schema.pm
index 281ca6b..ecfb0e4 100644 (file)
@@ -184,11 +184,15 @@ sub dbdef_dist {
   #  ));
   #}
 
+  my $tables_hashref_torrus = tables_hashref_torrus();
+
   #create history tables (false laziness w/create-history-tables)
   foreach my $table (
-    grep { ! /^clientapi_session/ }
-    grep { ! /^h_/ }
-    $dbdef->tables
+    grep {    ! /^clientapi_session/
+           && ! /^h_/
+           && ! $tables_hashref_torrus->{$_}
+         }
+      $dbdef->tables
   ) {
     my $tableobj = $dbdef->table($table)
       or die "unknown table $table";
@@ -325,6 +329,101 @@ sub dbdef_dist {
 
 }
 
+#torrus tables http://torrus.org/reporting_setup.pod.html#create_sql_tables
+sub tables_hashref_torrus {
+
+  return {
+
+    # Collector export table. It usually grows at several megabytes
+    # per month, and is updated every 5 minutes
+    'srvexport' => {
+      'columns' => [
+        'id',         'serial', '', '', '', '',
+        'srv_date',     'date', '', '', '', '',#date and time of the data sample
+        'srv_time',     'time', '', '', '', '',
+        'serviceid', 'varchar', '', 64, '', '',#unique service ID per counter
+        'value',     'double precision', '', '', '', '',#collected rate or gauge value
+        'intvl', 'int', '', '', '', '', # collection interval - for counter volume calculation
+      ],
+      'primary_key' => 'id',
+      'unique' => [],
+      'index'  => [ ['srv_date'], ['srv_date', 'srv_time'], ['serviceid'], ],
+    },
+
+    #Tables for (currently monthly only) report contents.
+    #These are updated usually once per month, and read at the moment of
+    #rendering the report output (HTML now, PDF or XML or Excel or whatever
+    #in the future)
+
+    #DBIx::Sequence backend, theplatform-independent inplementation
+    #of sequences
+    'dbix_sequence_state' => {
+      'columns' => [
+        'id',       'serial', '', '', '', '',
+        'dataset', 'varchar', '', 50, '', '',
+        'state_id',    'int', '', '', '', '',
+      ],
+      'primary_key' => 'id',
+      #CONSTRAINT pk_dbix_sequence PRIMARY KEY (dataset, state_id)
+      'unique' => [ [ 'dataset', 'state_id' ], ],
+      'index'  => [],
+    },
+
+    'dbix_sequence_release' => {
+      'columns' => [
+        'id',       'serial', '', '', '', '',
+        'dataset', 'varchar', '', 50, '', '',
+        'released_id', 'int', '', '', '', '',
+      ],
+      'primary_key' => 'id',
+      #CONSTRAINT pk_dbi_release PRIMARY KEY (dataset, released_id)
+      'unique' => [ [ 'dataset', 'released_id', ] ],
+      'index'  => [],
+    },
+
+    #Each report is characterized by name, date and time.
+    #Monthly reports are automatically assigned 00:00 of the 1st day
+    #in the month. The report contains fields for every service ID
+    #defined across all datasource trees.
+    'reports' => {
+      'columns' => [
+        'id',          'serial', '', '', '', '',
+        'rep_date',      'date', '', '', '', '',#Start date of the report
+        'rep_time',      'time', '', '', '', '',#Start time of the report
+        'reportname', 'varchar', '', 64, '', '',#Report name, such as
+                                                # MonthlyUsage
+        'iscomplete',     'int', '', '', '', '',#0 when the report is in
+                                                # progress, 1 when it is ready
+      ],
+      'primary_key' => 'id',
+      'unique' => [ [ qw(rep_date rep_time reportname) ] ],
+      'index'  => [ [ 'rep_date' ] ],
+    },
+
+    #Each report contains fields. For each service ID,
+    #the report may contain several fields for various statistics.
+    #Each field contains information about the units of the value it
+    #contains
+    'reportfields' => {
+      'columns' => [
+        'id',              'serial',     '', '',    '', '',
+        'rep_id',             'int', 'NULL', '',    '', '',
+        'name',           'varchar',     '', 64,    '', '',#name of the field,
+                                                           # such as AVG or MAX
+        'serviceid',      'varchar',     '', 64,    '', '',#service ID
+        'value', 'double precision',     '', '',    '', '',#Numeric value
+        'units',          'varchar',     '', 64, \"''", '',#Units, such as bytes
+                                                           # or Mbps
+      ],
+      'primary_key', => 'id',
+      'unique' => [ [ qw(rep_id name serviceid) ] ],
+      'index'  => [],
+    },
+
+  };
+
+}
+
 sub tables_hashref {
 
   my $char_d = 80; #default maxlength for text fields
@@ -909,6 +1008,7 @@ sub tables_hashref {
         'location_type',     'varchar', 'NULL',      20, '', '',
         'location_number',     'varchar', 'NULL',      20, '', '',
         'location_kind',     'char', 'NULL',      1, '', '',
+        'disabled',      'char', 'NULL',   1, '', '', 
       ],
       'primary_key' => 'locationnum',
       'unique'      => [],
@@ -932,6 +1032,7 @@ sub tables_hashref {
       'columns' => [
         'notenum',  'serial',  '',     '', '', '', 
         'custnum',  'int',  '',     '', '', '', 
+        'classnum',      'int',     'NULL', '', '', '', 
         '_date',    @date_type, '', '', 
         'otaker',   'varchar', 'NULL',    32, '', '', 
         'usernum',   'int', 'NULL', '', '', '',
@@ -941,6 +1042,17 @@ sub tables_hashref {
       'unique' => [],
       'index' => [ [ 'custnum' ], [ '_date' ], [ 'usernum' ], ],
     },
+    
+    'cust_note_class' => {
+      'columns' => [
+        'classnum',    'serial',   '',      '', '', '', 
+        'classname',   'varchar',  '', $char_d, '', '', 
+        'disabled',    'char', 'NULL',       1, '', '', 
+      ],
+      'primary_key' => 'classnum',
+      'unique' => [],
+      'index' => [ ['disabled'] ],
+    },
 
     'cust_category' => {
       'columns' => [
@@ -1299,6 +1411,7 @@ sub tables_hashref {
         'locationnum',         'int', 'NULL', '', '', '',
         'otaker',          'varchar', 'NULL', 32, '', '', 
         'usernum',             'int', 'NULL', '', '', '',
+        'order_date',     @date_type,             '', '', 
         'start_date',     @date_type,             '', '', 
         'setup',          @date_type,             '', '', 
         'bill',           @date_type,             '', '', 
@@ -1315,14 +1428,15 @@ sub tables_hashref {
         'manual_flag',        'char', 'NULL',  1, '', '', 
         'no_auto',            'char', 'NULL',  1, '', '', 
         'quantity',            'int', 'NULL', '', '', '',
+        'agent_pkgid',         'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'pkgnum',
       'unique' => [],
       'index' => [ ['custnum'], ['pkgpart'], [ 'pkgbatch' ], [ 'locationnum' ],
-                   [ 'usernum' ],
+                   [ 'usernum' ], [ 'agent_pkgid' ],
                    [ 'start_date' ], ['setup'], ['last_bill'], ['bill'],
                    ['susp'], ['adjourn'], ['expire'], ['cancel'],
-                   ['change_date'],
+                   ['change_date'], ['order_date'],
                  ],
     },
 
@@ -1685,7 +1799,7 @@ sub tables_hashref {
         'prospectnum',    'int',     'NULL',     '', '', '',
         'locationnum',    'int',     'NULL',     '', '', '',
        'phonenum',     'varchar', 'NULL',       24, '', '',
-        'exportnum',      'int', '', '', '', '', 
+        'exportnum',      'int', 'NULL', '', '', '', 
         'vendor_qual_id',      'varchar', 'NULL', $char_d, '', '', 
         'status',      'char', '', 1, '', '', 
       ],
@@ -1734,6 +1848,8 @@ sub tables_hashref {
         'pbxsvc',    'int', 'NULL', '', '', '',
         'last_login',  @date_type, '', '', 
         'last_logout', @date_type, '', '', 
+        #cardfortress field(s)
+        'cf_privatekey',      'text', 'NULL',      '', '', '',
         #communigate pro fields (quota = MaxAccountSize)
         'cgp_aliases',     'varchar', 'NULL',     255, '', '',
         #settings
@@ -1803,6 +1919,8 @@ sub tables_hashref {
        'setup_date',      @date_type, '', '',
        'renewal_interval', 'int', 'NULL',       '', '', '',
        'expiration_date', @date_type, '', '',
+       'au_registrant_name',       'varchar', 'NULL',  $char_d, '', '',
+       'au_eligibility_type',      'varchar', 'NULL',  $char_d, '', '',
         #communigate pro fields (quota = MaxAccountSize)
         'max_accounts',     'int', 'NULL',       '', '', '',
         'trailer',         'text', 'NULL',       '', '', '',
@@ -1844,8 +1962,8 @@ sub tables_hashref {
        'due_date',     'int', 'NULL',       '', '', '',
         'vendor_order_id',              'varchar', 'NULL', $char_d,  '', '',
         'vendor_qual_id',              'varchar', 'NULL', $char_d,  '', '',
-        'vendor_order_type',   'char', 'NULL',       1,  '', '', 
-        'vendor_order_status',   'char', 'NULL',       1,  '', '', 
+        'vendor_order_type',   'varchar', 'NULL', $char_d,  '', '',
+        'vendor_order_status',   'varchar', 'NULL', $char_d,  '', '',
         'first',              'varchar', 'NULL', $char_d,  '', '',
         'last',              'varchar', 'NULL', $char_d,  '', '',
         'company',              'varchar', 'NULL', $char_d,  '', '',
@@ -1854,6 +1972,8 @@ sub tables_hashref {
         'local_voice_provider', 'varchar', 'NULL', $char_d,  '', '',
         'circuitnum',              'varchar', 'NULL', $char_d,  '', '',
         'rate_band',              'varchar', 'NULL', $char_d,  '', '',
+       'vpi',     'int', 'NULL',       '', '', '',
+       'vci',     'int', 'NULL',       '', '', '',
         'isp_chg',   'char', 'NULL',       1,  '', '', 
         'isp_prev',              'varchar', 'NULL', $char_d,  '', '',
         'username',              'varchar', 'NULL', $char_d,  '', '',
@@ -1871,9 +1991,9 @@ sub tables_hashref {
       'columns' => [
         'notenum',           'serial',    '',        '', '', '',
        'svcnum',     'int', '',       '', '', '',
-        'by',              'varchar', 'NULL', $char_d,  '', '',
+        'author',     'varchar', 'NULL', $char_d,  '', '',
         'priority',   'char', 'NULL',       1,  '', '', 
-       'date',     'int', 'NULL',       '', '', '',
+       '_date',     'int', 'NULL',       '', '', '',
        'note',     'text', '',       '', '', '',
       ],
       'primary_key' => 'notenum',
@@ -2234,6 +2354,7 @@ sub tables_hashref {
         'altitude', 'decimal', 'NULL', '', '', '', 
         'vlan_profile', 'varchar', 'NULL', $char_d, '', '', 
         'performance_profile', 'varchar', 'NULL', $char_d, '', '',
+        'plan_id', 'varchar', 'NULL', $char_d, '', '',
       ],
       'primary_key' => 'svcnum',
       'unique'      => [ [ 'mac_addr' ] ],
@@ -2323,6 +2444,18 @@ sub tables_hashref {
       'index'       => [ [ 'pkgpart' ], [ 'optionname' ] ],
     },
 
+    'part_pkg_vendor' => {
+      'columns' => [
+        'num', 'serial', '', '', '', '', 
+        'pkgpart', 'int', '', '', '', '', 
+        'exportnum', 'int', '', '', '', '', 
+        'vendor_pkg_id', 'varchar', '', $char_d, '', '', 
+      ],
+      'primary_key' => 'num',
+      'unique' => [ [ 'pkgpart', 'exportnum' ] ],
+      'index'       => [ [ 'pkgpart' ] ],
+    },
+    
     'part_pkg_report_option' => {
       'columns' => [
         'num',      'serial',   '',      '', '', '', 
@@ -2357,6 +2490,7 @@ sub tables_hashref {
         'sec_granularity', 'int',     '',     '', '', '', 
         'ratetimenum',     'int', 'NULL',     '', '', '',
         'classnum',        'int', 'NULL',     '', '', '', 
+        'cdrtypenum',      'int', 'NULL',     '', '', '',
       ],
       'primary_key' => 'ratedetailnum',
       'unique'      => [ [ 'ratenum', 'orig_regionnum', 'dest_regionnum' ] ],
@@ -2846,6 +2980,16 @@ sub tables_hashref {
         'pbxsvc',           'int', 'NULL',      '', '', '',
         'domsvc',           'int', 'NULL',      '', '', '', 
         'locationnum',      'int', 'NULL', '', '', '',
+        'forwarddst',     'varchar',     'NULL',      15, '', '', 
+        'email',           'varchar', 'NULL',  255, '', '', 
+        'lnp_status',   'varchar', 'NULL', $char_d, '', '',
+        'portable',    'char', 'NULL',       1,  '', '', 
+        'lrn',     'char',     'NULL',      10, '', '', 
+       'lnp_desired_due_date',     'int', 'NULL',       '', '', '',
+       'lnp_due_date',     'int', 'NULL',       '', '', '',
+        'lnp_other_provider', 'varchar', 'NULL', $char_d,  '', '',
+        'lnp_other_provider_account', 'varchar', 'NULL', $char_d,  '', '',
+        'lnp_reject_reason', 'varchar', 'NULL', $char_d,  '', '',
       ],
       'primary_key' => 'svcnum',
       'unique' => [],
@@ -2870,7 +3014,7 @@ sub tables_hashref {
       'columns' => [
         'devicepart', 'serial',  '',      '', '', '',
         'devicename', 'varchar', '', $char_d, '', '',
-        #'classnum', #tie to an inventory class?
+        'inventory_classnum', 'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'devicepart',
       'unique' => [ [ 'devicename' ] ], #?
@@ -2887,6 +3031,8 @@ sub tables_hashref {
         'nxx',         'char',    'NULL',       3, '', '', 
         'station',     'char',    'NULL',       4, '', '',
         'name',        'varchar', 'NULL', $char_d, '', '',
+        'rate_center_abbrev', 'varchar', 'NULL', $char_d, '', '',
+        'ordernum',      'int',     'NULL',      '', '', '',
         'svcnum',      'int',     'NULL',      '', '', '',
         'availbatch', 'varchar',  'NULL', $char_d, '', '',
       ],
@@ -2900,6 +3046,45 @@ sub tables_hashref {
                     [ 'availbatch' ],
                   ],
     },
+    
+    'lata' => {
+      'columns' => [
+        'latanum',    'int',      '',      '', '', '', 
+        'description',   'varchar',    '',      $char_d, '', '', 
+      ],
+      'primary_key' => 'latanum',
+      'unique' => [],
+      'index'  => [],
+    },
+    
+    'did_vendor' => {
+      'columns' => [
+        'vendornum',    'serial',      '',      '', '', '', 
+        'vendorname',   'varchar',        '',     $char_d, '', '', 
+      ],
+      'primary_key' => 'vendornum',
+      'unique' => [],
+      'index'  => [],
+    },
+    
+    'did_order' => {
+      'columns' => [
+        'ordernum',    'serial',      '',      '', '', '', 
+        'vendornum',   'int',       '',      '', '', '', 
+        'vendor_order_id',   'varchar',  '',   $char_d, '', '', 
+        'msa',        'varchar', 'NULL', $char_d, '', '',
+        'latanum',      'int',     'NULL',      '', '', '',
+        'rate_center',        'varchar', 'NULL', $char_d, '', '',
+        'state',       'char',    'NULL',       2, '', '', 
+        'quantity',      'int',     '',      '', '', '',
+        'submitted',      'int',     '',      '', '', '',
+        'confirmed',      'int',     'NULL',      '', '', '',
+        'received',      'int',     'NULL',      '', '', '',
+      ],
+      'primary_key' => 'ordernum',
+      'unique' => [ [ 'vendornum', 'vendor_order_id' ] ],
+      'index'  => [],
+    },
 
     'reason_type' => {
       'columns' => [
@@ -3070,7 +3255,54 @@ sub tables_hashref {
       'unique' => [],
       'index'  => [], #recnum
     },
-   
+
+    'svc_port' => {
+      'columns' => [
+        'svcnum',                'int',     '',      '', '', '', 
+        'serviceid', 'varchar', '', 64, '', '', #srvexport / reportfields
+      ],
+      'primary_key' => 'svcnum',
+      'unique' => [],
+      'index'  => [], #recnum
+    },
+
+    'areacode'  => {
+      'columns' => [
+        'code',        'char',        '',       3, '', '', 
+        'country',     'char',    'NULL',       2, '', '',
+        'state',       'char',    'NULL',       2, '', '', 
+        'description','varchar',  'NULL',     255, '', '',
+      ], 
+      'primary_key' => 'code',
+      'unique' => [],
+      'index'  => [],
+    },
+
+    %{ tables_hashref_torrus() },
+
+    # tables of ours for doing torrus virtual port combining
+    'torrus_srvderive' => {
+      'columns' => [
+        'derivenum',     'serial',     '', '', '', '',
+        'serviceid',    'varchar',     '', 64, '', '', #srvexport / reportfields
+        'last_srv_date',   'date', 'NULL', '', '', '',
+      ],
+      'primary_key' => 'derivenum',
+      'unique' => [ ['serviceid'] ],
+      'index'  => [],
+    },
+
+    'torrus_srvderive_component' => {
+      'columns' => [
+        'componentnum', 'serial', '', '', '', '',
+        'derivenum',       'int', '', '', '', '',
+        'serviceid',   'varchar', '', 64, '', '', #srvexport / reportfields
+      ],
+      'primary_key' => 'componentnum',
+      'unique'      => [ [ 'derivenum', 'serviceid' ], ],
+      'index'       => [ [ 'derivenum', ], ],
+    },
+
 
     # name type nullability length default local