use database SERIAL or AUTO_INCREMENT for primary keys, finally, yay!
authorivan <ivan>
Thu, 19 Sep 2002 13:34:52 +0000 (13:34 +0000)
committerivan <ivan>
Thu, 19 Sep 2002 13:34:52 +0000 (13:34 +0000)
closes: bug#69

FS/FS/Record.pm
bin/dbdef-create
bin/fs-setup

index c247ed2..8778dee 100644 (file)
@@ -9,8 +9,8 @@ use Carp qw(carp cluck croak confess);
 use File::CounterFile;
 use Locale::Country;
 use DBI qw(:sql_types);
-use DBIx::DBSchema 0.19;
-use FS::UID qw(dbh checkruid getotaker datasrc driver_name);
+use DBIx::DBSchema 0.21;
+use FS::UID qw(dbh getotaker datasrc driver_name);
 use FS::SearchCache;
 use FS::Msgcat qw(gettext);
 
@@ -60,14 +60,12 @@ FS::Record - Database record objects
     $hashref = $record->hashref;
 
     $error = $record->insert;
-    #$error = $record->add; #deprecated
 
     $error = $record->delete;
-    #$error = $record->del; #deprecated
 
     $error = $new_record->replace($old_record);
-    #$error = $new_record->rep($old_record); #deprecated
 
+    # external use deprecated - handled by the database (at least for Pg, mysql)
     $value = $record->unique('column');
 
     $error = $record->ut_float('column');
@@ -88,7 +86,7 @@ FS::Record - Database record objects
 
     $quoted_value = _quote($value,'table','field');
 
-    #depriciated
+    #deprecated
     $fields = hfields('table');
     if ( $fields->{Field} ) { # etc.
 
@@ -167,7 +165,7 @@ sub create {
   my $self = {};
   bless ($self, $class);
   if ( defined $self->table ) {
-    cluck "create constructor is depriciated, use new!";
+    cluck "create constructor is deprecated, use new!";
     $self->new(@_);
   } else {
     croak "FS::Record::create called (not from a subclass)!";
@@ -212,25 +210,25 @@ sub qsearch {
       my $op = '=';
       if ( ref($record->{$_}) ) {
         $op = $record->{$_}{'op'} if $record->{$_}{'op'};
-        $op = 'LIKE' if $op =~ /^ILIKE$/i && driver_name !~ /^Pg$/i;
+        $op = 'LIKE' if $op =~ /^ILIKE$/i && driver_name ne 'Pg';
         $record->{$_} = $record->{$_}{'value'}
       }
 
       if ( ! defined( $record->{$_} ) || $record->{$_} eq '' ) {
         if ( $op eq '=' ) {
-          if ( driver_name =~ /^Pg$/i ) {
+          if ( driver_name eq 'Pg' ) {
             qq-( $_ IS NULL OR $_ = '' )-;
           } else {
             qq-( $_ IS NULL OR $_ = "" )-;
           }
         } elsif ( $op eq '!=' ) {
-          if ( driver_name =~ /^Pg$/i ) {
+          if ( driver_name eq 'Pg' ) {
             qq-( $_ IS NOT NULL AND $_ != '' )-;
           } else {
             qq-( $_ IS NOT NULL AND $_ != "" )-;
           }
         } else {
-          if ( driver_name =~ /^Pg$/i ) {
+          if ( driver_name eq 'Pg' ) {
             qq-( $_ $op '' )-;
           } else {
             qq-( $_ $op "" )-;
@@ -345,7 +343,7 @@ Returns the table name.
 =cut
 
 sub table {
-#  cluck "warning: FS::Record::table depriciated; supply one in subclass!";
+#  cluck "warning: FS::Record::table deprecated; supply one in subclass!";
   my $self = shift;
   $self -> {'Table'};
 }
@@ -472,24 +470,33 @@ sub insert {
   return $error if $error;
 
   #single-field unique keys are given a value if false
-  #(like MySQL's AUTO_INCREMENT)
+  #(like MySQL's AUTO_INCREMENT or Pg SERIAL)
   foreach ( $self->dbdef_table->unique->singles ) {
     $self->unique($_) unless $self->getfield($_);
   }
-  #and also the primary key
+
+  #and also the primary key, if the database isn't going to
   my $primary_key = $self->dbdef_table->primary_key;
-  $self->unique($primary_key) 
-    if $primary_key && ! $self->getfield($primary_key);
+  my $db_seq = 0;
+  if ( $primary_key ) {
+    my $col = $self->dbdef_table->column($primary_key);
+    my $db_seq =
+      uc($col->type) eq 'SERIAL'
+      || ( driver_name eq 'Pg'    && $col->default =~ /^nextval\(/i     )
+      || ( driver_name eq 'mysql' && $col->local   =~ /AUTO_INCREMENT/i );
+    $self->unique($primary_key) unless $self->getfield($primary_key) || $db_seq;
+  }
 
+  my $table = $self->table;
   #false laziness w/delete
   my @fields =
     grep defined($self->getfield($_)) && $self->getfield($_) ne "",
     $self->fields
   ;
-  my @values = map { _quote( $self->getfield($_), $self->table, $_) } @fields;
+  my @values = map { _quote( $self->getfield($_), $table, $_) } @fields;
   #eslaf
 
-  my $statement = "INSERT INTO ". $self->table. " ( ".
+  my $statement = "INSERT INTO $table ( ".
       join( ', ', @fields ).
     ") VALUES (".
       join( ', ', @values ).
@@ -498,15 +505,6 @@ sub insert {
   warn "[debug]$me $statement\n" if $DEBUG > 1;
   my $sth = dbh->prepare($statement) or return dbh->errstr;
 
-  my $h_sth;
-  if ( defined $dbdef->table('h_'. $self->table) ) {
-    my $h_statement = $self->_h_statement('insert');
-    warn "[debug]$me $h_statement\n" if $DEBUG > 2;
-    $h_sth = dbh->prepare($h_statement) or return dbh->errstr;
-  } else {
-    $h_sth = '';
-  }
-
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
   local $SIG{QUIT} = 'IGNORE'; 
@@ -515,7 +513,63 @@ sub insert {
   local $SIG{PIPE} = 'IGNORE';
 
   $sth->execute or return $sth->errstr;
+
+  if ( $db_seq ) { # get inserted id from the database, if applicable
+    my $insertid = '';
+    if ( driver_name eq 'Pg' ) {
+
+      my $oid = $sth->{'pg_oid_status'};
+      my $i_sql = "SELECT id FROM $table WHERE oid = ?";
+      my $i_sth = dbh->prepare($i_sql) or do {
+        dbh->rollback if $FS::UID::AutoCommit;
+        return dbh->errstr;
+      };
+      $i_sth->execute($oid) or do {
+        dbh->rollback if $FS::UID::AutoCommit;
+        return $i_sth->errstr;
+      };
+      $insertid = $i_sth->fetchrow_arrayref->[0];
+
+    } elsif ( driver_name eq 'mysql' ) {
+
+      $insertid = dbh->{'mysql_insertid'};
+      # work around mysql_insertid being null some of the time, ala RT :/
+      unless ( $insertid ) {
+        warn "WARNING: DBD::mysql didn't return mysql_insertid; ".
+             "using SELECT LAST_INSERT_ID();";
+        my $i_sql = "SELECT LAST_INSERT_ID()";
+        my $i_sth = dbh->prepare($i_sql) or do {
+          dbh->rollback if $FS::UID::AutoCommit;
+          return dbh->errstr;
+        };
+        $i_sth->execute or do {
+          dbh->rollback if $FS::UID::AutoCommit;
+          return $i_sth->errstr;
+        };
+        $insertid = $i_sth->fetchrow_arrayref->[0];
+      }
+
+    } else {
+      dbh->rollback if $FS::UID::AutoCommit;
+      return "don't know how to retreive inserted ids from ". driver_name. 
+             ", try using counterfiles (maybe run dbdef-create?)";
+    }
+    $self->setfield($primary_key, $insertid);
+  }
+
+  my $h_sth;
+  if ( defined $dbdef->table('h_'. $table) ) {
+    my $h_statement = $self->_h_statement('insert');
+    warn "[debug]$me $h_statement\n" if $DEBUG > 2;
+    $h_sth = dbh->prepare($h_statement) or do {
+      dbh->rollback if $FS::UID::AutoCommit;
+      return dbh->errstr;
+    };
+  } else {
+    $h_sth = '';
+  }
   $h_sth->execute or return $h_sth->errstr if $h_sth;
+
   dbh->commit or croak dbh->errstr if $FS::UID::AutoCommit;
 
   '';
@@ -528,7 +582,7 @@ Depriciated (use insert instead).
 =cut
 
 sub add {
-  cluck "warning: FS::Record::add depriciated!";
+  cluck "warning: FS::Record::add deprecated!";
   insert @_; #call method in this scope
 }
 
@@ -546,7 +600,7 @@ sub delete {
     map {
       $self->getfield($_) eq ''
         #? "( $_ IS NULL OR $_ = \"\" )"
-        ? ( driver_name =~ /^Pg$/i
+        ? ( driver_name eq 'Pg'
               ? "$_ IS NULL"
               : "( $_ IS NULL OR $_ = \"\" )"
           )
@@ -592,7 +646,7 @@ Depriciated (use delete instead).
 =cut
 
 sub del {
-  cluck "warning: FS::Record::del depriciated!";
+  cluck "warning: FS::Record::del deprecated!";
   &delete(@_); #call method in this scope
 }
 
@@ -632,7 +686,7 @@ sub replace {
       map {
         $old->getfield($_) eq ''
           #? "( $_ IS NULL OR $_ = \"\" )"
-          ? ( driver_name =~ /^Pg$/i
+          ? ( driver_name eq 'Pg'
                 ? "$_ IS NULL"
                 : "( $_ IS NULL OR $_ = \"\" )"
             )
@@ -685,7 +739,7 @@ Depriciated (use replace instead).
 =cut
 
 sub rep {
-  cluck "warning: FS::Record::rep depriciated!";
+  cluck "warning: FS::Record::rep deprecated!";
   replace @_; #call method in this scope
 }
 
@@ -718,8 +772,13 @@ sub _h_statement {
 
 =item unique COLUMN
 
-Replaces COLUMN in record with a unique number.  Called by the B<add> method
-on primary keys and single-field unique columns (see L<DBIx::DBSchema::Table>).
+B<Warning>: External use is B<deprecated>.  
+
+Replaces COLUMN in record with a unique number, using counters in the
+filesystem.  Used by the B<insert> method on single-field unique columns
+(see L<DBIx::DBSchema::Table>) and also as a fallback for primary keys
+that aren't SERIAL (Pg) or AUTO_INCREMENT (mysql).
+
 Returns the new value.
 
 =cut
@@ -728,8 +787,6 @@ sub unique {
   my($self,$field) = @_;
   my($table)=$self->table;
 
-  #croak("&FS::UID::checkruid failed") unless &checkruid;
-
   croak "Unique called on field $field, but it is ",
         $self->getfield($field),
         ", not null!"
@@ -745,9 +802,8 @@ sub unique {
 #  my($counter) = new File::CounterFile "$user/$table.$field",0;
 # endhack
 
-  my($index)=$counter->inc;
-  $index=$counter->inc
-    while qsearchs($table,{$field=>$index}); #just in case
+  my $index = $counter->inc;
+  $index = $counter->inc while qsearchs($table, { $field=>$index } );
 
   $index =~ /^(\d*)$/;
   $index=$1;
@@ -1165,14 +1221,14 @@ sub _quote {
 
 =item hfields TABLE
 
-This is depriciated.  Don't use it.
+This is deprecated.  Don't use it.
 
 It returns a hash-type list with the fields of this record's table set true.
 
 =cut
 
 sub hfields {
-  carp "warning: hfields is depriciated";
+  carp "warning: hfields is deprecated";
   my($table)=@_;
   my(%hash);
   foreach (fields($table)) {
@@ -1208,7 +1264,7 @@ sub DESTROY { return; }
 This module should probably be renamed, since much of the functionality is
 of general use.  It is not completely unlike Adapter::DBI (see below).
 
-Exported qsearch and qsearchs should be depriciated in favor of method calls
+Exported qsearch and qsearchs should be deprecated in favor of method calls
 (against an FS::Record object like the old search and searchs that qsearch
 and qsearchs were on top of.)
 
@@ -1216,7 +1272,7 @@ The whole fields / hfields mess should be removed.
 
 The various WHERE clauses should be subroutined.
 
-table string should be depriciated in favor of DBIx::DBSchema::Table.
+table string should be deprecated in favor of DBIx::DBSchema::Table.
 
 No doubt we could benefit from a Tied hash.  Documenting how exists / defined
 true maps to the database (and WHERE clauses) would also help.
index 0b297b9..c977f87 100755 (executable)
@@ -1,10 +1,10 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: dbdef-create,v 1.5 2001-08-21 02:43:18 ivan Exp $
+# $Id: dbdef-create,v 1.6 2002-09-19 13:34:52 ivan Exp $
 
 use strict;
 use DBI;
-use DBIx::DBSchema;
+use DBIx::DBSchema 0.21;
 use FS::UID qw(adminsuidsetup datasrc driver_name);
 
 my $user = shift or die &usage;
index 81f1c26..aeaacbc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -Tw
 #
-# $Id: fs-setup,v 1.97 2002-09-09 23:01:36 khoff Exp $
+# $Id: fs-setup,v 1.98 2002-09-19 13:34:51 ivan Exp $
 
 #to delay loading dbdef until we're ready
 BEGIN { $FS::Record::setup_hack = 1; }
@@ -133,33 +133,6 @@ foreach $attribute (@check_attributes) {
   ));
 }
 
-##make part_svc table (but now as object)
-#
-#my($part_svc)=$dbdef->table('part_svc');
-#
-##because of svc_acct_pop
-##foreach (grep /^svc_/, $dbdef->tables) { 
-##foreach (qw(svc_acct svc_acct_sm svc_charge svc_domain svc_wo)) {
-#foreach (qw(svc_acct svc_domain svc_forward svc_www)) {
-#  my($table)=$dbdef->table($_);
-#  my($col);
-#  foreach $col ( $table->columns ) {
-#    next if $col =~ /^svcnum$/;
-#    $part_svc->addcolumn( new DBIx::DBSchema::Column (
-#      $table->name. '__' . $table->column($col)->name,
-#      'varchar', #$table->column($col)->type, 
-#      'NULL',
-#      $char_d, #$table->column($col)->length,
-#    ));
-#    $part_svc->addcolumn ( new DBIx::DBSchema::Column (
-#      $table->name. '__'. $table->column($col)->name . "_flag",
-#      'char',
-#      'NULL',
-#      1,
-#    ));
-#  }
-#}
-
 #create history tables (false laziness w/create-history-tables)
 foreach my $table ( grep { ! /^h_/ } $dbdef->tables ) {
   my $tableobj = $dbdef->table($table)
@@ -334,7 +307,7 @@ sub tables_hash_hack {
 
     'agent' => {
       'columns' => [
-        'agentnum', 'int',            '',     '',
+        'agentnum', 'serial',            '',     '',
         'agent',    'varchar',           '',     $char_d,
         'typenum',  'int',            '',     '',
         'freq',     'int',       'NULL', '',
@@ -347,7 +320,7 @@ sub tables_hash_hack {
 
     'agent_type' => {
       'columns' => [
-        'typenum',   'int',  '', '',
+        'typenum',   'serial',  '', '',
         'atype',     'varchar', '', $char_d,
       ],
       'primary_key' => 'typenum',
@@ -367,7 +340,7 @@ sub tables_hash_hack {
 
     'cust_bill' => {
       'columns' => [
-        'invnum',    'int',  '', '',
+        'invnum',    'serial',  '', '',
         'custnum',   'int',  '', '',
         '_date',     @date_type,
         'charged',   @money_type,
@@ -381,7 +354,7 @@ sub tables_hash_hack {
 
     'cust_bill_event' => {
       'columns' => [
-        'eventnum',    'int',  '', '',
+        'eventnum',    'serial',  '', '',
         'invnum',   'int',  '', '',
         'eventpart',   'int',  '', '',
         '_date',     @date_type,
@@ -396,7 +369,7 @@ sub tables_hash_hack {
 
     'part_bill_event' => {
       'columns' => [
-        'eventpart',    'int',  '', '',
+        'eventpart',    'serial',  '', '',
         'payby',       'char',  '', 4,
         'event',       'varchar',           '',     $char_d,
         'eventcode',    @perl_type,
@@ -427,7 +400,7 @@ sub tables_hash_hack {
 
     'cust_credit' => {
       'columns' => [
-        'crednum',  'int', '', '',
+        'crednum',  'serial', '', '',
         'custnum',  'int', '', '',
         '_date',    @date_type,
         'amount',   @money_type,
@@ -442,7 +415,7 @@ sub tables_hash_hack {
 
     'cust_credit_bill' => {
       'columns' => [
-        'creditbillnum', 'int', '', '',
+        'creditbillnum', 'serial', '', '',
         'crednum',  'int', '', '',
         'invnum',  'int', '', '',
         '_date',    @date_type,
@@ -455,7 +428,7 @@ sub tables_hash_hack {
 
     'cust_main' => {
       'columns' => [
-        'custnum',  'int',  '',     '',
+        'custnum',  'serial',  '',     '',
         'agentnum', 'int',  '',     '',
 #        'titlenum', 'int',  'NULL',   '',
         'last',     'varchar', '',     $char_d,
@@ -506,7 +479,7 @@ sub tables_hash_hack {
 
     'cust_main_invoice' => {
       'columns' => [
-        'destnum',  'int',  '',     '',
+        'destnum',  'serial',  '',     '',
         'custnum',  'int',  '',     '',
         'dest',     'varchar', '',  $char_d,
       ],
@@ -519,7 +492,7 @@ sub tables_hash_hack {
                             #cust_main_county for validation and to provide
                             # a tax rate.
       'columns' => [
-        'taxnum',   'int',   '',    '',
+        'taxnum',   'serial',   '',    '',
         'state',    'varchar',  'NULL',    $char_d,
         'county',   'varchar',  'NULL',    $char_d,
         'country',  'char',  '', 2, 
@@ -535,7 +508,7 @@ sub tables_hash_hack {
 
     'cust_pay' => {
       'columns' => [
-        'paynum',   'int',    '',   '',
+        'paynum',   'serial',    '',   '',
         #now cust_bill_pay #'invnum',   'int',    '',   '',
         'custnum',  'int',    '',   '',
         'paid',     @money_type,
@@ -553,7 +526,7 @@ sub tables_hash_hack {
 
     'cust_bill_pay' => {
       'columns' => [
-        'billpaynum', 'int',     '',   '',
+        'billpaynum', 'serial',     '',   '',
         'invnum',  'int',     '',   '',
         'paynum',  'int',     '',   '',
         'amount',  @money_type,
@@ -567,7 +540,7 @@ sub tables_hash_hack {
     'cust_pay_batch' => { #what's this used for again?  list of customers
                           #in current CARD batch? (necessarily CARD?)
       'columns' => [
-        'paybatchnum',   'int',    '',   '',
+        'paybatchnum',   'serial',    '',   '',
         'invnum',   'int',    '',   '',
         'custnum',   'int',    '',   '',
         'last',     'varchar', '',     $char_d,
@@ -592,7 +565,7 @@ sub tables_hash_hack {
 
     'cust_pkg' => {
       'columns' => [
-        'pkgnum',    'int',    '',   '',
+        'pkgnum',    'serial',    '',   '',
         'custnum',   'int',    '',   '',
         'pkgpart',   'int',    '',   '',
         'otaker',    'varchar', '', 8,
@@ -610,7 +583,7 @@ sub tables_hash_hack {
 
     'cust_refund' => {
       'columns' => [
-        'refundnum',    'int',    '',   '',
+        'refundnum',    'serial',    '',   '',
         #now cust_credit_refund #'crednum',      'int',    '',   '',
         'custnum',  'int',    '',   '',
         '_date',        @date_type,
@@ -630,7 +603,7 @@ sub tables_hash_hack {
 
     'cust_credit_refund' => {
       'columns' => [
-        'creditrefundnum', 'int',     '',   '',
+        'creditrefundnum', 'serial',     '',   '',
         'crednum',  'int',     '',   '',
         'refundnum',  'int',     '',   '',
         'amount',  @money_type,
@@ -644,7 +617,7 @@ sub tables_hash_hack {
 
     'cust_svc' => {
       'columns' => [
-        'svcnum',    'int',    '',   '',
+        'svcnum',    'serial',    '',   '',
         'pkgnum',    'int',    'NULL',   '',
         'svcpart',   'int',    '',   '',
       ],
@@ -655,7 +628,7 @@ sub tables_hash_hack {
 
     'part_pkg' => {
       'columns' => [
-        'pkgpart',    'int',    '',   '',
+        'pkgpart',    'serial',    '',   '',
         'pkg',        'varchar',   '',   $char_d,
         'comment',    'varchar',   '',   $char_d,
         'setup',      @perl_type,
@@ -696,7 +669,7 @@ sub tables_hash_hack {
 
     'part_referral' => {
       'columns' => [
-        'refnum',   'int',    '',   '',
+        'refnum',   'serial',    '',   '',
         'referral', 'varchar',   '',   $char_d,
       ],
       'primary_key' => 'refnum',
@@ -706,7 +679,7 @@ sub tables_hash_hack {
 
     'part_svc' => {
       'columns' => [
-        'svcpart',    'int',    '',   '',
+        'svcpart',    'serial',    '',   '',
         'svc',        'varchar',   '',   $char_d,
         'svcdb',      'varchar',   '',   $char_d,
         'disabled',   'char',  'NULL',   1,
@@ -718,7 +691,7 @@ sub tables_hash_hack {
 
     'part_svc_column' => {
       'columns' => [
-        'columnnum',   'int',         '', '',
+        'columnnum',   'serial',         '', '',
         'svcpart',     'int',         '', '',
         'columnname',  'varchar',     '', 64,
         'columnvalue', 'varchar', 'NULL', $char_d,
@@ -732,7 +705,7 @@ sub tables_hash_hack {
     #(this should be renamed to part_pop)
     'svc_acct_pop' => {
       'columns' => [
-        'popnum',    'int',    '',   '',
+        'popnum',    'serial',    '',   '',
         'city',      'varchar',   '',   $char_d,
         'state',     'varchar',   '',   $char_d,
         'ac',        'char',   '',   3,
@@ -746,7 +719,7 @@ sub tables_hash_hack {
 
     'part_pop_local' => {
       'columns' => [
-        'localnum',  'int',     '',     '',
+        'localnum',  'serial',     '',     '',
         'popnum',    'int',     '',     '',
         'city',      'varchar', 'NULL', $char_d,
         'state',     'char',    'NULL', 2,
@@ -781,18 +754,6 @@ sub tables_hash_hack {
       'index' => [ ['username'], ['domsvc'] ],
     },
 
-#    'svc_acct_sm' => {
-#      'columns' => [
-#        'svcnum',    'int',    '',   '',
-#        'domsvc',    'int',    '',   '',
-#        'domuid',    'int', '',   '',
-#        'domuser',   'varchar',   '',   $char_d,
-#      ],
-#      'primary_key' => 'svcnum',
-#      'unique' => [ [] ],
-#      'index' => [ ['domsvc'], ['domuid'] ], 
-#    },
-
     #'svc_charge' => {
     #  'columns' => [
     #    'svcnum',    'int',    '',   '',
@@ -816,7 +777,7 @@ sub tables_hash_hack {
 
     'domain_record' => {
       'columns' => [
-        'recnum',    'int',     '',  '',
+        'recnum',    'serial',     '',  '',
         'svcnum',    'int',     '',  '',
         'reczone',   'varchar', '',  $char_d,
         'recaf',     'char',    '',  2,
@@ -866,7 +827,7 @@ sub tables_hash_hack {
 
     'prepay_credit' => {
       'columns' => [
-        'prepaynum',   'int',     '',   '',
+        'prepaynum',   'serial',     '',   '',
         'identifier',  'varchar', '', $char_d,
         'amount',      @money_type,
         'seconds',     'int',     'NULL', '',
@@ -878,7 +839,7 @@ sub tables_hash_hack {
 
     'port' => {
       'columns' => [
-        'portnum',  'int',     '',   '',
+        'portnum',  'serial',     '',   '',
         'ip',       'varchar', 'NULL', 15,
         'nasport',  'int',     'NULL', '',
         'nasnum',   'int',     '',   '',
@@ -890,7 +851,7 @@ sub tables_hash_hack {
 
     'nas' => {
       'columns' => [
-        'nasnum',   'int',     '',    '',
+        'nasnum',   'serial',     '',    '',
         'nas',      'varchar', '',    $char_d,
         'nasip',    'varchar', '',    15,
         'nasfqdn',  'varchar', '',    $char_d,
@@ -903,7 +864,7 @@ sub tables_hash_hack {
 
     'session' => {
       'columns' => [
-        'sessionnum', 'int',       '',   '',
+        'sessionnum', 'serial',       '',   '',
         'portnum',    'int',       '',   '',
         'svcnum',     'int',       '',   '',
         'login',      @date_type,
@@ -916,7 +877,7 @@ sub tables_hash_hack {
 
     'queue' => {
       'columns' => [
-        'jobnum', 'int', '', '',
+        'jobnum', 'serial', '', '',
         'job', 'text', '', '',
         '_date', 'int', '', '',
         'status', 'varchar', '', $char_d,
@@ -930,7 +891,7 @@ sub tables_hash_hack {
 
     'queue_arg' => {
       'columns' => [
-        'argnum', 'int', '', '',
+        'argnum', 'serial', '', '',
         'jobnum', 'int', '', '',
         'arg', 'text', 'NULL', '',
       ],
@@ -941,7 +902,7 @@ sub tables_hash_hack {
 
     'queue_depend' => {
       'columns' => [
-        'dependnum', 'int', '', '',
+        'dependnum', 'serial', '', '',
         'jobnum', 'int', '', '',
         'depend_jobnum', 'int', '', '',
       ],
@@ -952,7 +913,7 @@ sub tables_hash_hack {
 
     'export_svc' => {
       'columns' => [
-        'exportsvcnum' => 'int', '', '',
+        'exportsvcnum' => 'serial', '', '',
         'exportnum'    => 'int', '', '',
         'svcpart'      => 'int', '', '',
       ],
@@ -963,7 +924,7 @@ sub tables_hash_hack {
 
     'part_export' => {
       'columns' => [
-        'exportnum', 'int', '', '',
+        'exportnum', 'serial', '', '',
         #'svcpart',   'int', '', '',
         'machine', 'varchar', '', $char_d,
         'exporttype', 'varchar', '', $char_d,
@@ -976,7 +937,7 @@ sub tables_hash_hack {
 
     'part_export_option' => {
       'columns' => [
-        'optionnum', 'int', '', '',
+        'optionnum', 'serial', '', '',
         'exportnum', 'int', '', '',
         'optionname', 'varchar', '', $char_d,
         'optionvalue', 'text', 'NULL', '',
@@ -988,7 +949,7 @@ sub tables_hash_hack {
 
     'radius_usergroup' => {
       'columns' => [
-        'usergroupnum', 'int', '', '',
+        'usergroupnum', 'serial', '', '',
         'svcnum',       'int', '', '',
         'groupname',    'varchar', '', $char_d,
       ],
@@ -999,7 +960,7 @@ sub tables_hash_hack {
 
     'msgcat' => {
       'columns' => [
-        'msgnum', 'int', '', '',
+        'msgnum', 'serial', '', '',
         'msgcode', 'varchar', '', $char_d,
         'locale', 'varchar', '', 16,
         'msg', 'text', '', '',
@@ -1011,7 +972,7 @@ sub tables_hash_hack {
 
     'cust_tax_exempt' => {
       'columns' => [
-        'exemptnum', 'int', '', '',
+        'exemptnum', 'serial', '', '',
         'custnum',   'int', '', '',
         'taxnum',    'int', '', '',
         'year',      'int', '', '',
@@ -1025,7 +986,7 @@ sub tables_hash_hack {
 
     'ac_type' => {
       'columns' => [
-        'actypenum', 'int', '', '',
+        'actypenum', 'serial', '', '',
         'actypename', 'varchar', '', 15,
       ],
       'primary_key' => 'actypenum',
@@ -1035,7 +996,7 @@ sub tables_hash_hack {
 
     'ac' => {
       'columns' => [
-        'acnum', 'int', '', '',
+        'acnum', 'serial', '', '',
         'actypenum', 'int', '', '',
         'acname', 'varchar', '', 15,
       ],
@@ -1046,7 +1007,7 @@ sub tables_hash_hack {
 
     'part_ac_field' => {
       'columns' => [
-        'acfieldpart', 'int', '', '',
+        'acfieldpart', 'serial', '', '',
         'actypenum', 'int', '', '',
         'name', 'varchar', '', 15,
         'ut_type', 'varchar', '', 15,
@@ -1080,7 +1041,7 @@ sub tables_hash_hack {
 
     'svc_broadband' => {
       'columns' => [
-        'svcnum', 'int', '', '',
+        'svcnum', 'serial', '', '',
         'actypenum', 'int', '', '',
         'speed_up', 'int', '', '',
         'speed_down', 'int', '', '',