X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FSchema.pm;h=e8f65fe4980ca29d797ac57db5bbf07f1c951339;hb=7ed55804735f4f687cd64139db7bae9746282a89;hp=9d4a054b01a6c7c5b9a9d5dd4225c464f1d6b956;hpb=ca63c29a40e2c7ad13558eb204fbb6764bf7a351;p=freeside.git diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 9d4a054b0..e8f65fe49 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -7,7 +7,6 @@ use DBIx::DBSchema 0.33; use DBIx::DBSchema::Table; use DBIx::DBSchema::Column 0.06; use DBIx::DBSchema::Index; -use FS::UID qw(datasrc); @ISA = qw(Exporter); @EXPORT_OK = qw( dbdef dbdef_dist reload_dbdef ); @@ -66,13 +65,22 @@ assuming it is up-to-date). See L. 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 @@ -80,7 +88,6 @@ sub dbdef_dist { my $tables_hashref = tables_hashref(); - #turn it into objects my $dbdef = new DBIx::DBSchema map { @@ -126,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; @@ -185,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; } @@ -266,15 +312,17 @@ sub tables_hashref { 'agent' => { 'columns' => [ - '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, '', '', - 'ticketing_queueid', 'int', 'NULL', '', '', '', + 'agentnum', 'serial', '', '', '', '', + 'agent', 'varchar', '', $char_d, '', '', + 'typenum', 'int', '', '', '', '', + 'disabled', 'char', 'NULL', 1, '', '', + 'ticketing_queueid', 'int', 'NULL', '', '', '', + 'invoice_template', 'varchar', 'NULL', $char_d, '', '', + 'username', 'varchar', 'NULL', $char_d, '', '', #deprecated + '_password', 'varchar', 'NULL', $char_d, '', '', #deprecated + 'freq', 'int', 'NULL', '', '', '', #deprecated (never used) + 'prog', @perl_type, '', '', #deprecated (never used) + ], 'primary_key' => 'agentnum', 'unique' => [], @@ -350,6 +398,84 @@ sub tables_hashref { 'index' => [ ['payby'], ['disabled'], ], }, + 'part_event' => { + 'columns' => [ + 'eventpart', 'serial', '', '', '', '', + 'agentnum', 'int', 'NULL', '', '', '', + 'event', 'varchar', '', $char_d, '', '', + 'eventtable', 'varchar', '', $char_d, '', '', + 'check_freq', 'varchar', 'NULL', $char_d, '', '', + 'weight', 'int', '', '', '', '', + 'action', 'varchar', '', $char_d, '', '', + 'disabled', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'eventpart', + 'unique' => [], + 'index' => [ ['agentnum'], ['eventtable'], ['check_freq'], ['disabled'], ], + }, + + 'part_event_option' => { + 'columns' => [ + 'optionnum', 'serial', '', '', '', '', + 'eventpart', 'int', '', '', '', '', + 'optionname', 'varchar', '', $char_d, '', '', + 'optionvalue', 'text', 'NULL', '', '', '', + ], + 'primary_key' => 'optionnum', + 'unique' => [], + 'index' => [ [ 'eventpart' ], [ 'optionname' ] ], + }, + + 'part_event_condition' => { + 'columns' => [ + 'eventconditionnum', 'serial', '', '', '', '', + 'eventpart', 'int', '', '', '', '', + 'conditionname', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'eventconditionnum', + 'unique' => [], + 'index' => [ [ 'eventpart' ], [ 'conditionname' ] ], + }, + + 'part_event_condition_option' => { + 'columns' => [ + 'optionnum', 'serial', '', '', '', '', + 'eventconditionnum', 'int', '', '', '', '', + 'optionname', 'varchar', '', $char_d, '', '', + 'optionvalue', 'text', 'NULL', '', '', '', + ], + 'primary_key' => 'optionnum', + 'unique' => [], + 'index' => [ [ 'eventconditionnum' ], [ 'optionname' ] ], + }, + + 'part_event_condition_option_option' => { + 'columns' => [ + 'optionoptionnum', 'serial', '', '', '', '', + 'optionnum', 'int', '', '', '', '', + 'optionname', 'varchar', '', $char_d, '', '', + 'optionvalue', 'text', 'NULL', '', '', '', + ], + 'primary_key' => 'optionoptionnum', + 'unique' => [], + 'index' => [ [ 'optionnum' ], [ 'optionname' ] ], + }, + + 'cust_event' => { + 'columns' => [ + 'eventnum', 'serial', '', '', '', '', + 'eventpart', 'int', '', '', '', '', + 'tablenum', 'int', '', '', '', '', + '_date', @date_type, '', '', + 'status', 'varchar', '', $char_d, '', '', + 'statustext', 'text', 'NULL', '', '', '', + ], + 'primary_key' => 'eventnum', + #no... there are retries now #'unique' => [ [ 'eventpart', 'invnum' ] ], + 'unique' => [], + 'index' => [ ['eventpart'], ['tablenum'], ['status'] ], + }, + 'cust_bill_pkg' => { 'columns' => [ 'billpkgnum', 'serial', '', '', '', '', @@ -538,6 +664,32 @@ 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' => 'pendingpaynum', + 'unique' => [ [ 'payunique' ] ], + 'index' => [ [ 'custnum' ], [ 'status' ], ], + }, + 'cust_pay' => { 'columns' => [ 'paynum', 'serial', '', '', '', '', @@ -556,7 +708,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' ] ], }, @@ -667,22 +819,29 @@ 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'] ], + 'index' => [ ['custnum'], ['pkgpart'], + ['setup'], ['last_bill'], ['bill'], ['susp'], ['adjourn'], + ['expire'], ['cancel'], + ['change_date'], + ], }, 'cust_pkg_option' => { @@ -729,7 +888,7 @@ sub tables_hashref { ], 'primary_key' => 'refundnum', 'unique' => [], - 'index' => [], + 'index' => [ [ 'custnum' ] ], }, 'cust_credit_refund' => { @@ -776,10 +935,12 @@ 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_title' => { @@ -814,7 +975,7 @@ sub tables_hashref { ], 'primary_key' => 'refnum', 'unique' => [], - 'index' => [ ['disabled'] ], + 'index' => [ ['disabled'], ['agentnum'], ], }, 'part_svc' => { @@ -902,6 +1063,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', '', '', @@ -920,7 +1095,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, '', '', @@ -969,10 +1144,10 @@ sub tables_hashref { 'svc_www' => { 'columns' => [ - 'svcnum', 'int', '', '', '', '', - 'recnum', 'int', '', '', '', '', - 'usersvc', 'int', '', '', '', '', - 'config', 'text', 'NULL', '', '', '', + 'svcnum', 'int', '', '', '', '', + 'recnum', 'int', '', '', '', '', + 'usersvc', 'int', 'NULL', '', '', '', + 'config', 'text', 'NULL', '', '', '', ], 'primary_key' => 'svcnum', 'unique' => [], @@ -1054,6 +1229,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' => [], @@ -1472,7 +1649,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, \"''", '', @@ -1564,7 +1742,7 @@ sub tables_hashref { 'cdr_type' => { 'columns' => [ 'cdrtypenum' => 'serial', '', '', '', '', - 'cdrtypename' => 'varchar', '', '', '', '', + 'cdrtypename' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'cdrtypenum', 'unique' => [], @@ -1574,7 +1752,7 @@ sub tables_hashref { 'cdr_carrier' => { 'columns' => [ 'carrierid' => 'serial', '', '', '', '', - 'carriername' => 'varchar', '', '', '', '', + 'carriername' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'carrierid', 'unique' => [], @@ -1635,6 +1813,7 @@ sub tables_hashref { 'usernum', 'int', '', '', '', '', 'prefname', 'varchar', '', $char_d, '', '', 'prefvalue', 'text', 'NULL', '', '', '', + 'expiration', @date_type, '', '', ], 'primary_key' => 'prefnum', 'unique' => [], @@ -1678,7 +1857,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' ] ], @@ -1725,13 +1904,23 @@ sub tables_hashref { 'confnum', 'serial', '', '', '', '', 'agentnum', 'int', 'NULL', '', '', '', 'name', 'varchar', '', $char_d, '', '', - 'value', 'varchar', 'NULL', '', '', '', # Pg specific + 'value', 'long varbinary', 'NULL', '', '', '', ], 'primary_key' => 'confnum', 'unique' => [ [ 'agentnum', 'name' ]], 'index' => [], }, + 'pkg_referral' => { + 'columns' => [ + 'pkgrefnum', 'serial', '', '', '', '', + 'pkgnum', 'int', '', '', '', '', + 'refnum', 'int', '', '', '', '', + ], + 'primary_key' => 'pkgrefnum', + 'unique' => [ [ 'pkgnum', 'refnum' ] ], + 'index' => [ [ 'pkgnum' ], [ 'refnum' ] ], + }, # name type nullability length default local #'new_table' => {