Column::sql_add_column fix when adding primary keys to Pg 7.2.x
authorivan <ivan>
Fri, 2 Dec 2005 02:19:35 +0000 (02:19 +0000)
committerivan <ivan>
Fri, 2 Dec 2005 02:19:35 +0000 (02:19 +0000)
Changes
DBSchema/Column.pm

diff --git a/Changes b/Changes
index e5ee33b..6dd85e1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for Perl extension DBIx::DBSchema.
 
 0.29 unreleased
+       - Column::sql_add_column fix when adding primary keys to Pg 7.2.x
        - workaround for PAUSE parsing of DBIx::DBSchema::DBD::Pg version: move
          DBD::Pg verison checking after $VERSION declaration, thanks Andreas!
 
index 6c55735..9a067a5 100644 (file)
@@ -351,7 +351,12 @@ sub sql_add_column {
 
       #needs more work for old Pg
 
-      my $nextval = "nextval('public.${table}_${column}_seq'::text)";
+      my $nextval;
+      if ( $dbh->{'pg_server_version'} > 70300 ) {
+        $nextval = "nextval('public.${table}_${column}_seq'::text)";
+      } else {
+        $nextval = "nextval('${table}_${column}_seq'::text)";
+      }
 
       (
         "ALTER TABLE $table ALTER COLUMN $column SET DEFAULT $nextval",
@@ -369,10 +374,23 @@ sub sql_add_column {
     $real_null = $self->null;
     $self->null('NULL');
 
-    push @after_add, sub {
-      my($table, $column) = @_;
-      "ALTER TABLE $table ALTER $column SET NOT NULL";
-    };
+    if ( $dbh->{'pg_server_version'} > 70300 ) {
+
+      push @after_add, sub {
+        my($table, $column) = @_;
+        "ALTER TABLE $table ALTER $column SET NOT NULL";
+      };
+
+    } else {
+
+      push @after_add, sub {
+        my($table, $column) = @_;
+        "UPDATE pg_attribute SET attnotnull = TRUE ".
+        " WHERE attname = '$column' ".
+        " AND attrelid = ( SELECT oid FROM pg_class WHERE relname = '$table' )";
+      };
+
+    }
 
   }