X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FSchema.pm;h=d4a51a60d8e3b4e246d54cf4ec7f0e185a9f6dfa;hb=37f181cc0b65e4509dd68593cb7555db42d8e088;hp=3084e3625c82b99920b211efc03daa31ca83136c;hpb=2f3b4161da680cd0fff8c91dbdc50fe5e974610e;p=freeside.git diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 3084e3625..d4a51a60d 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -65,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 @@ -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; } @@ -256,6 +303,7 @@ sub tables_hashref { my @date_type = ( 'int', 'NULL', '' ); my @perl_type = ( 'text', 'NULL', '' ); my @money_type = ( 'decimal', '', '10,2' ); + my @money_typen = ( 'decimal', 'NULL', '10,2' ); my $username_len = 32; #usernamemax config file @@ -465,11 +513,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 +666,101 @@ sub tables_hashref { 'index' => [ [ 'county' ], [ 'state' ], [ 'country' ] ], }, + 'tax_rate' => { + 'columns' => [ + 'taxnum', 'serial', '', '', '', '', + 'geocode', 'varchar', 'NULL', $char_d, '', '',#cch provides 10 char + 'data_vendor', 'varchar', 'NULL', $char_d, '', '',#auto update source + 'location', 'varchar', 'NULL', $char_d, '', '',#provided by tax authority + 'taxclassnum', 'int', '', '', '', '', + 'effective_date', @date_type, '', '', + 'tax', 'real', '', '', '', '', # tax % + 'excessrate', 'real', 'NULL','', '', '', # second tax % + 'taxbase', @money_typen, '', '', # amount at first tax rate + 'taxmax', @money_typen, '', '', # maximum about at both rates + 'usetax', 'real', 'NULL', '', '', '', # tax % when non-local + 'useexcessrate', 'real', 'NULL', '', '', '', # second tax % when non-local + 'unittype', 'int', 'NULL', '', '', '', # for fee + 'fee', 'real', 'NULL', '', '', '', # amount tax per unit + 'excessfee', 'real', 'NULL', '', '', '', # second amount tax per unit + 'feebase', 'real', 'NULL', '', '', '', # units taxed at first rate + 'feemax', 'real', 'NULL', '', '', '', # maximum number of unit taxed + 'maxtype', 'int', 'NULL', '', '', '', # indicator of how thresholds accumulate + 'taxname', 'varchar', 'NULL', $char_d, '', '', # may appear on invoice + 'taxauth', 'int', 'NULL', '', '', '', # tax authority + 'basetype', 'int', 'NULL', '', '', '', # indicator of basis for tax + 'passtype', 'int', 'NULL', '', '', '', # indicator declaring how item should be shown + 'passflag', 'char', 'NULL', 1, '', '', # Y = required to list as line item, N = Prohibited + 'setuptax', 'char', 'NULL', 1, '', '', # Y = setup tax exempt + 'recurtax', 'char', 'NULL', 1, '', '', # Y = recur tax exempt + 'manual', 'char', 'NULL', 1, '', '', # Y = manually edited + ], + 'primary_key' => 'taxnum', + 'unique' => [], + 'index' => [ ['taxclassnum'], ['data_vendor', 'geocode'] ], + }, + + 'cust_tax_location' => { + 'columns' => [ + 'custlocationnum', 'serial', '', '', '', '', + 'data_vendor', 'varchar', 'NULL', $char_d, '', '', # update source + 'zip', 'char', '', 5, '', '', + 'state', 'char', '', 2, '', '', + 'plus4hi', 'char', '', 4, '', '', + 'plus4lo', 'char', '', 4, '', '', + 'default_location','char', 'NULL', 1, '', '', # Y = default for zip + 'geocode', 'varchar', '', 20, '', '', + ], + 'primary_key' => 'custlocationnum', + 'unique' => [], + 'index' => [ [ 'zip', 'plus4lo', 'plus4hi' ] ], + }, + + 'tax_class' => { + 'columns' => [ + 'taxclassnum', 'serial', '', '', '', '', + 'data_vendor', 'varchar', 'NULL', $char_d, '', '', + 'taxclass', 'varchar', '', $char_d, '', '', + 'description', 'varchar', '', 2*$char_d, '', '', + ], + 'primary_key' => 'taxclassnum', + 'unique' => [ [ 'data_vendor', 'taxclass' ] ], + 'index' => [], + }, + + '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 +772,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' ] ], }, @@ -799,7 +936,6 @@ sub tables_hashref { 'cust_refund' => { 'columns' => [ 'refundnum', 'serial', '', '', '', '', - #now cust_credit_refund #'crednum', 'int', '', '', '', '', 'custnum', 'int', '', '', '', '', '_date', @date_type, '', '', 'refund', @money_type, '', '', @@ -815,7 +951,7 @@ sub tables_hashref { ], 'primary_key' => 'refundnum', 'unique' => [], - 'index' => [ [ 'custnum' ] ], + 'index' => [ ['custnum'], ['_date'] ], }, 'cust_credit_refund' => { @@ -828,7 +964,7 @@ sub tables_hashref { ], 'primary_key' => 'creditrefundnum', 'unique' => [], - 'index' => [ [ 'crednum', 'refundnum' ] ], + 'index' => [ ['crednum'], ['refundnum'] ], }, @@ -860,6 +996,7 @@ sub tables_hashref { 'disabled', 'char', 'NULL', 1, '', '', 'taxclass', 'varchar', 'NULL', $char_d, '', '', 'classnum', 'int', 'NULL', '', '', '', + 'taxproductnum', 'int', 'NULL', '', '', '', 'pay_weight', 'real', 'NULL', '', '', '', 'credit_weight', 'real', 'NULL', '', '', '', 'agentnum', 'int', 'NULL', '', '', '', @@ -870,6 +1007,61 @@ sub tables_hashref { 'index' => [ [ 'promo_code' ], [ 'disabled' ], [ 'agentnum' ], ], }, + 'part_pkg_taxclass' => { + 'columns' => [ + 'taxclassnum', 'serial', '', '', '', '', + 'taxclass', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'taxclassnum', + 'unique' => [ [ 'taxclass' ] ], + 'index' => [], + }, + + 'part_pkg_taxproduct' => { + 'columns' => [ + 'taxproductnum', 'serial', '', '', '', '', + 'data_vendor', 'varchar', 'NULL', $char_d, '', '', + 'taxproduct', 'varchar', '', $char_d, '', '', + 'description', 'varchar', '', 2*$char_d, '', '', + ], + 'primary_key' => 'taxproductnum', + 'unique' => [ [ 'data_vendor', 'taxproduct' ] ], + 'index' => [], + }, + + 'part_pkg_taxrate' => { + 'columns' => [ + 'pkgtaxratenum', 'serial', '', '', '', '', + 'data_vendor', 'varchar', 'NULL', $char_d, '', '', # update source + 'geocode', 'varchar', 'NULL', $char_d, '', '', # cch provides 10 + 'taxproductnum', 'int', '', '', '', '', + 'city', 'varchar', 'NULL', $char_d, '', '', # tax_location? + 'county', 'varchar', 'NULL', $char_d, '', '', + 'state', 'varchar', 'NULL', $char_d, '', '', + 'local', 'varchar', 'NULL', $char_d, '', '', + 'country', 'char', 'NULL', 2, '', '', + 'taxclassnumtaxed', 'int', 'NULL', '', '', '', + 'taxcattaxed', 'varchar', 'NULL', $char_d, '', '', + 'taxclassnum', 'int', 'NULL', '', '', '', + 'effdate', @date_type, '', '', + 'taxable', 'char', 'NULL', 1, '', '', + ], + 'primary_key' => 'pkgtaxratenum', + 'unique' => [], + 'index' => [ [ 'data_vendor', 'geocode', 'taxproductnum' ] ], + }, + + 'part_pkg_taxoverride' => { + 'columns' => [ + 'taxoverridenum', 'serial', '', '', '', '', + 'pkgpart', 'serial', '', '', '', '', + 'taxclassnum', 'serial', '', '', '', '', + ], + 'primary_key' => 'taxoverridenum', + 'unique' => [], + 'index' => [ [ 'pkgpart' ], [ 'taxclassnum' ] ], + }, + # 'part_title' => { # 'columns' => [ # 'titlenum', 'int', '', '', @@ -983,6 +1175,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' ] ], @@ -1022,7 +1216,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, '', '', @@ -1156,6 +1350,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' => [], @@ -1279,6 +1475,7 @@ sub tables_hashref { 'routernum', 'serial', '', '', '', '', 'routername', 'varchar', '', $char_d, '', '', 'svcnum', 'int', 'NULL', '', '', '', + 'agentnum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'routernum', 'unique' => [], @@ -1302,6 +1499,7 @@ sub tables_hashref { 'routernum', 'int', '', '', '', '', 'ip_gateway', 'varchar', '', 15, '', '', 'ip_netmask', 'int', '', '', '', '', + 'agentnum', 'int', 'NULL', '', '', '', ], 'primary_key' => 'blocknum', 'unique' => [ [ 'blocknum', 'routernum' ] ], @@ -1574,7 +1772,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, \"''", '', @@ -1666,7 +1865,7 @@ sub tables_hashref { 'cdr_type' => { 'columns' => [ 'cdrtypenum' => 'serial', '', '', '', '', - 'cdrtypename' => 'varchar', '', '', '', '', + 'cdrtypename' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'cdrtypenum', 'unique' => [], @@ -1676,7 +1875,7 @@ sub tables_hashref { 'cdr_carrier' => { 'columns' => [ 'carrierid' => 'serial', '', '', '', '', - 'carriername' => 'varchar', '', '', '', '', + 'carriername' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'carrierid', 'unique' => [], @@ -1781,7 +1980,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' ] ], @@ -1815,7 +2014,7 @@ sub tables_hashref { 'columns' => [ 'reasonnum', 'serial', '', '', '', '', 'reason_type', 'int', '', '', '', '', - 'reason', 'varchar', '', $char_d, '', '', + 'reason', 'text', '', '', '', '', 'disabled', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'reasonnum', @@ -1828,7 +2027,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' ]],