[freeside-commits] freeside/FS/FS Schema.pm, 1.44.2.14, 1.44.2.15 Setup.pm, 1.8.2.1, 1.8.2.2 svc_acct.pm, 1.217.2.13, 1.217.2.14
Ivan,,,
ivan at wavetail.420.am
Sun Oct 28 05:52:02 PDT 2007
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv19393/FS/FS
Modified Files:
Tag: FREESIDE_1_7_BRANCH
Schema.pm Setup.pm svc_acct.pm
Log Message:
finish mysql locking workaround
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.44.2.14
retrieving revision 1.44.2.15
diff -u -d -r1.44.2.14 -r1.44.2.15
--- Schema.pm 25 Oct 2007 19:02:47 -0000 1.44.2.14
+++ Schema.pm 28 Oct 2007 12:51:59 -0000 1.44.2.15
@@ -65,13 +65,22 @@
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 @@
my $tables_hashref = tables_hashref();
-
#turn it into objects
my $dbdef = new DBIx::DBSchema map {
@@ -125,10 +133,11 @@
@$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 @@
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 =~ /^(\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
- ],
+ 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;
}
Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.217.2.13
retrieving revision 1.217.2.14
diff -u -d -r1.217.2.13 -r1.217.2.14
--- svc_acct.pm 16 Aug 2007 18:23:20 -0000 1.217.2.13
+++ svc_acct.pm 28 Oct 2007 12:52:00 -0000 1.217.2.14
@@ -21,7 +21,7 @@
use Date::Format;
use Crypt::PasswdMD5 1.2;
use Data::Dumper;
-use FS::UID qw( datasrc );
+use FS::UID qw( datasrc driver_name );
use FS::Conf;
use FS::Record qw( qsearch qsearchs fields dbh dbdef );
use FS::Msgcat qw(gettext);
@@ -1142,11 +1142,19 @@
my $global_unique = $conf->config('global_unique-username') || 'none';
return '' if $global_unique eq 'disabled';
- #this is Pg-specific. what to do for mysql etc?
- # ( mysql LOCK TABLES certainly isn't equivalent or useful here :/ )
warn "$me locking svc_acct table for duplicate search" if $DEBUG;
- dbh->do("LOCK TABLE svc_acct IN SHARE ROW EXCLUSIVE MODE")
- or die dbh->errstr;
+ if ( driver_name =~ /^Pg/i ) {
+ dbh->do("LOCK TABLE svc_acct IN SHARE ROW EXCLUSIVE MODE")
+ or die dbh->errstr;
+ } elsif ( driver_name =~ /^mysql/i ) {
+ dbh->do("SELECT * FROM duplicate_lock
+ WHERE lockname = 'svc_acct'
+ FOR UPDATE"
+ ) or die dbh->errstr;
+ } else {
+ die "unknown database ". driver_name.
+ "; don't know how to lock for duplicate search";
+ }
warn "$me acquired svc_acct table lock for duplicate search" if $DEBUG;
my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
Index: Setup.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Setup.pm,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -u -d -r1.8.2.1 -r1.8.2.2
--- Setup.pm 24 Apr 2007 22:36:22 -0000 1.8.2.1
+++ Setup.pm 28 Oct 2007 12:51:59 -0000 1.8.2.2
@@ -5,7 +5,7 @@
use Exporter;
#use Tie::DxHash;
use Tie::IxHash;
-use FS::UID qw( dbh );
+use FS::UID qw( dbh driver_name );
use FS::Record;
use FS::svc_domain;
@@ -45,6 +45,8 @@
populate_locales();
+ populate_duplock();
+
#initial_data data
populate_initial_data(%opt);
@@ -125,6 +127,18 @@
die $error if $error;
}
+sub populate_duplock {
+
+ return unless driver_name =~ /^mysql/i;
+
+ my $sth = dbh->prepare(
+ "INSERT INTO duplicate_lock ( lockname ) VALUES ( 'svc_acct' )"
+ ) or die dbh->errstr;
+
+ $sth->execute or die $sth->errstr;
+
+}
+
sub populate_initial_data {
my %opt = @_;
More information about the freeside-commits
mailing list