X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FSchema.pm;h=bd098def71f0efb95bfdc03cd4f2fa082348b399;hb=dc39152e4b1b881f0115aa5cbe42fbf48a71e5c5;hp=adc32a29aae1d0d7f70f32a82824a0b47ac0148d;hpb=9509e5bfb7f9331303153cac24d7bfecbe2ea9f1;p=freeside.git diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index adc32a29a..bd098def7 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; } @@ -746,24 +793,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'], ], }, @@ -858,10 +909,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' => { @@ -896,7 +949,7 @@ sub tables_hashref { ], 'primary_key' => 'refnum', 'unique' => [], - 'index' => [ ['disabled'] ], + 'index' => [ ['disabled'], ['agentnum'], ], }, 'part_svc' => { @@ -984,6 +1037,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 +1069,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 +1203,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 +1623,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 +1716,7 @@ sub tables_hashref { 'cdr_type' => { 'columns' => [ 'cdrtypenum' => 'serial', '', '', '', '', - 'cdrtypename' => 'varchar', '', '', '', '', + 'cdrtypename' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'cdrtypenum', 'unique' => [], @@ -1656,7 +1726,7 @@ sub tables_hashref { 'cdr_carrier' => { 'columns' => [ 'carrierid' => 'serial', '', '', '', '', - 'carriername' => 'varchar', '', '', '', '', + 'carriername' => 'varchar', '', $char_d, '', '', ], 'primary_key' => 'carrierid', 'unique' => [], @@ -1717,6 +1787,7 @@ sub tables_hashref { 'usernum', 'int', '', '', '', '', 'prefname', 'varchar', '', $char_d, '', '', 'prefvalue', 'text', 'NULL', '', '', '', + 'expiration', @date_type, '', '', ], 'primary_key' => 'prefnum', 'unique' => [], @@ -1760,7 +1831,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' ] ], @@ -1807,7 +1878,7 @@ 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' ]],