[freeside-commits] freeside/FS/FS tax_rate.pm, 1.27, 1.28 cust_bill_pkg_detail.pm, 1.6, 1.7

Jeff Finucane,420,, jeff at wavetail.420.am
Fri Jun 19 14:49:05 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv17114

Modified Files:
	tax_rate.pm cust_bill_pkg_detail.pm 
Log Message:
support some older Pg when upgrading tax rates and cust_bill_pkg_details

Index: cust_bill_pkg_detail.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill_pkg_detail.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- cust_bill_pkg_detail.pm	4 Apr 2009 16:22:19 -0000	1.6
+++ cust_bill_pkg_detail.pm	19 Jun 2009 21:49:03 -0000	1.7
@@ -148,6 +148,37 @@
 
         }
 
+      } elsif ( $dbh->{pg_server_version} =~ /^704/ ) {  # earlier?
+
+        # ideally this would be supported in DBIx-DBSchema and friends
+
+        #  XXX_FIXME better locking
+
+        foreach my $table ( qw( cust_bill_pkg_detail h_cust_bill_pkg_detail ) ){
+
+          warn "updating $table column classnum to integer\n" if $DEBUG;
+
+          my $sql = "ALTER TABLE $table RENAME classnum TO old_classnum";
+          my $sth = $dbh->prepare($sql) or die $dbh->errstr;
+          $sth->execute or die $sth->errstr;
+
+          my $def = dbdef->table($table)->column('classnum');
+          $def->type('integer');
+          $def->length(''); 
+          $sql = "ALTER TABLE $table ADD COLUMN ". $def->line($dbh);
+          $sth = $dbh->prepare($sql) or die $dbh->errstr;
+          $sth->execute or die $sth->errstr;
+
+          $sql = "UPDATE $table SET classnum = int4( text( old_classnum ) )";
+          $sth = $dbh->prepare($sql) or die $dbh->errstr;
+          $sth->execute or die $sth->errstr;
+
+          $sql = "ALTER TABLE $table DROP old_classnum";
+          $sth = $dbh->prepare($sql) or die $dbh->errstr;
+          $sth->execute or die $sth->errstr;
+
+        }
+
       } else {
 
         die "cust_bill_pkg_detail classnum upgrade unsupported for this Pg version\n";

Index: tax_rate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/tax_rate.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- tax_rate.pm	1 Jun 2009 05:43:11 -0000	1.27
+++ tax_rate.pm	19 Jun 2009 21:49:03 -0000	1.28
@@ -1664,6 +1664,50 @@
         }
       }
 
+    } elsif ( $dbh->{pg_server_version} =~ /^704/ ) {
+
+      # ideally this would be supported in DBIx-DBSchema and friends
+
+      foreach my $column ( @column ) {
+        my $columndef = dbdef->table($self->table)->column($column);
+        unless ($columndef->type eq 'numeric') {
+
+          warn "updating tax_rate column $column to numeric\n" if $DEBUG;
+
+          foreach my $table ( qw( tax_rate h_tax_rate ) ) {
+
+            my $sql = "ALTER TABLE $table RENAME $column TO old_$column";
+            my $sth = $dbh->prepare($sql) or die $dbh->errstr;
+            $sth->execute or die $sth->errstr;
+
+            my $def = dbdef->table($table)->column($column);
+            $def->type('numeric');
+            $def->length('14,8'); 
+            my $null = $def->null;
+            $def->null('NULL');
+
+            $sql = "ALTER TABLE $table ADD COLUMN ". $def->line($dbh);
+            $sth = $dbh->prepare($sql) or die $dbh->errstr;
+            $sth->execute or die $sth->errstr;
+
+            $sql = "UPDATE $table SET $column = CAST( old_$column AS numeric )";
+            $sth = $dbh->prepare($sql) or die $dbh->errstr;
+            $sth->execute or die $sth->errstr;
+
+            unless ( $null eq 'NULL' ) {
+              $sql = "ALTER TABLE $table ALTER $column SET NOT NULL";
+              $sth = $dbh->prepare($sql) or die $dbh->errstr;
+              $sth->execute or die $sth->errstr;
+            }
+
+            $sql = "ALTER TABLE $table DROP old_$column";
+            $sth = $dbh->prepare($sql) or die $dbh->errstr;
+            $sth->execute or die $sth->errstr;
+
+          }
+        }
+      }
+
     } else {
 
       warn "WARNING: tax_rate table upgrade unsupported for this Pg version\n";



More information about the freeside-commits mailing list