doc: sql_update_schema link to sql_add_column misspelled
[DBIx-DBSchema.git] / DBSchema / Table.pm
index 16ba3a0..8d047de 100644 (file)
@@ -4,13 +4,13 @@ use strict;
 use vars qw($VERSION $DEBUG %create_params);
 use Carp;
 #use Exporter;
-use DBIx::DBSchema::_util qw(_load_driver _dbh);
-use DBIx::DBSchema::Column 0.07;
+use DBIx::DBSchema::_util qw(_load_driver _dbh _parse_opt);
+use DBIx::DBSchema::Column 0.14;
 use DBIx::DBSchema::Index;
 use DBIx::DBSchema::ColGroup::Unique;
 use DBIx::DBSchema::ColGroup::Index;
 
-$VERSION = '0.05';
+$VERSION = '0.08';
 $DEBUG = 0;
 
 =head1 NAME
@@ -87,10 +87,11 @@ Creates a new DBIx::DBSchema::Table object.  The preferred usage is to pass a
 hash reference of named parameters.
 
   {
-    name        => TABLE_NAME,
-    primary_key => PRIMARY_KEY,
-    columns     => COLUMNS,
-    indices     => INDICES,
+    name          => TABLE_NAME,
+    primary_key   => PRIMARY_KEY,
+    columns       => COLUMNS,
+    indices       => INDICES,
+    local_options => OPTIONS,
     #deprecated# unique => UNIQUE,
     #deprecated# index  => INDEX,
   }
@@ -100,6 +101,8 @@ empty).  COLUMNS is a reference to an array of DBIx::DBSchema::Column objects
 (see L<DBIx::DBSchema::Column>).  INDICES is a reference to an array of 
 DBIx::DBSchema::Index objects (see L<DBIx::DBSchema::Index>), or a hash
 reference of index names (keys) and DBIx::DBSchema::Index objects (values).
+OPTIONS is a scalar of database-specific table options, such as "WITHOUT OIDS"
+for Pg or "TYPE=InnoDB" for mysql.
 
 Deprecated options:
 
@@ -346,6 +349,21 @@ sub name {
   }
 }
 
+=item local_options [ OPTIONS ]
+
+Returns or sets the database-specific table options string.
+
+=cut
+
+sub local_options {
+  my($self,$value)=@_;
+  if ( defined($value) ) {
+    $self->{local_options} = $value;
+  } else {
+    defined $self->{local_options} ? $self->{local_options} : '';
+  }
+}
+
 =item primary_key [ PRIMARY_KEY ]
 
 Returns or sets the primary key.
@@ -531,7 +549,8 @@ sub sql_create_table {
   my $indexnum = 1;
 
   my @r = (
-    "CREATE TABLE ". $self->name. " (\n  ". join(",\n  ", @columns). "\n)\n"
+    "CREATE TABLE ". $self->name. " (\n  ". join(",\n  ", @columns). "\n)\n".
+    $self->local_options
   );
 
   if ( $self->_unique ) {
@@ -598,7 +617,7 @@ specified database, will attempt to use generic SQL syntax.
 #gosh, false laziness w/DBSchema::sql_update_schema
 
 sub sql_alter_table {
-  my( $self, $new, $dbh ) = ( shift, shift, _dbh(@_) );
+  my($self, $opt, $new, $dbh) = ( shift, _parse_opt(\@_), shift, _dbh(@_) );
 
   my $driver = _load_driver($dbh);
 
@@ -617,23 +636,20 @@ sub sql_alter_table {
     if ( $self->column($column) )  {
 
       warn "  $table.$column exists\n" if $DEBUG > 1;
-
-      push @r,
-        $self->column($column)->sql_alter_column( $new->column($column), $dbh );
+      push @r, $self->column($column)->sql_alter_column( $new->column($column),
+                                                         $dbh,
+                                                         $opt,
+                                                       );
 
     } else {
   
       warn "column $table.$column does not exist.\n" if $DEBUG > 1;
-
-      push @r,
-        $new->column($column)->sql_add_column( $dbh );
+      push @r, $new->column($column)->sql_add_column( $dbh );
   
     }
   
   }
 
-  #should eventually drop columns not in $new...
-  
   ###
   # indices
   ###
@@ -745,7 +761,7 @@ with no indices.
 
 Copyright (c) 2000-2007 Ivan Kohler
 Copyright (c) 2000 Mail Abuse Prevention System LLC
-Copyright (c) 2007 Freeside Internet Services, Inc.
+Copyright (c) 2007-2010 Freeside Internet Services, Inc.
 All rights reserved.
 This program is free software; you can redistribute it and/or modify it under
 the same terms as Perl itself.
@@ -763,8 +779,6 @@ the object after sql_create_table, make a copy beforehand.
 
 Some of the logic in new_odbc might be better abstracted into Column.pm etc.
 
-sql_alter_table ought to drop columns not in $new
-
 Add methods to get and set specific indices, by name? (like column COLUMN_NAME)
 
 indices method should be a setter, not just a getter?