From: ivan Date: Fri, 2 Dec 2005 02:19:35 +0000 (+0000) Subject: Column::sql_add_column fix when adding primary keys to Pg 7.2.x X-Git-Tag: DBIx_DBSchema_0_29~5 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=760e1b3a7e2656b7f4fabd507218864c6dc28c52;p=DBIx-DBSchema.git Column::sql_add_column fix when adding primary keys to Pg 7.2.x --- diff --git a/Changes b/Changes index e5ee33b..6dd85e1 100644 --- 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! diff --git a/DBSchema/Column.pm b/DBSchema/Column.pm index 6c55735..9a067a5 100644 --- a/DBSchema/Column.pm +++ b/DBSchema/Column.pm @@ -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' )"; + }; + + } }