initial support for handling changes to a column's type or size
[DBIx-DBSchema.git] / DBSchema / Column.pm
index b13d5c0..0d00159 100644 (file)
@@ -5,7 +5,7 @@ use vars qw($VERSION);
 use Carp;
 use DBIx::DBSchema::_util qw(_load_driver _dbh);
 
-$VERSION = '0.12';
+$VERSION = '0.13';
 
 =head1 NAME
 
@@ -267,7 +267,10 @@ sub line {
   my $default;
   my $orig_default = $self->default;
   if ( $driver_class->can("_column_value_needs_quoting") ) {
-    if ($driver_class->_column_value_needs_quoting($self)) {
+    if ( $driver_class->_column_value_needs_quoting($self)
+         && !ref($self->default)
+       )
+    {
       $default = $dbh->quote($self->default);
     } else {
       $default = ref($self->default) ? ${$self->default} : $self->default;
@@ -429,35 +432,51 @@ sub sql_alter_column {
   my $dbd = "DBIx::DBSchema::DBD::$driver";
   my $hashref = $dbd->alter_column_callback( $dbh, $table, $self, $new );
 
-  # change the name...
+  if ( $hashref->{'sql_alter'} ) {
 
-  # change the type...
-
-  if ( $hashref->{'sql_alter_null' } ) {
-
-    push @sql, $hashref->{'sql_alter_null'};
+    push @sql, $hashref->{'sql_alter'};
 
   } else {
 
-    # change nullability from NOT NULL to NULL
-    if ( ! $self->null && $new->null ) {
-  
-      push @sql, "ALTER TABLE $table ALTER COLUMN $name DROP NOT NULL";
-  
+    # change the name...
+    # not yet implemented.  how do we tell which old column it was?
+
+    # change the type...
+    if ( $hashref->{'sql_alter_type'} ) {
+      push @sql, $hashref->{'sql_alter_type'};
     }
-  
-    # change nullability from NULL to NOT NULL...
-    # this one could be more complicated, need to set a DEFAULT value and update
-    # the table first...
-    if ( $self->null && ! $new->null ) {
-  
-      push @sql, "ALTER TABLE $table ALTER COLUMN $name SET NOT NULL";
-  
+
+    # change nullability...
+
+    if ( $hashref->{'sql_alter_null'} ) {
+
+      push @sql, $hashref->{'sql_alter_null'};
+
+    } else {
+
+      # change nullability from NOT NULL to NULL
+      if ( ! $self->null && $new->null ) {
+    
+        push @sql, "ALTER TABLE $table ALTER COLUMN $name DROP NOT NULL";
+    
+      }
+    
+      # change nullability from NULL to NOT NULL...
+      # this one could be more complicated, need to set a DEFAULT value and update
+      # the table first...
+      if ( $self->null && ! $new->null ) {
+    
+        push @sql, "ALTER TABLE $table ALTER COLUMN $name SET NOT NULL";
+    
+      }
+
     }
 
+    # change default
+
+    # change other stuff...
+
   }
-  
-  # change other stuff...
 
   @sql;