+ my($self, $dbh) = ( shift, _dbh(@_) );
+ (
+ ( map { $self->table($_)->sql_create_table($dbh); } $self->tables ),
+ ( map { $self->table($_)->sql_add_constraints($dbh); } $self->tables ),
+ );
+}
+
+=item sql_update_schema [ OPTIONS_HASHREF, ] PROTOTYPE_SCHEMA [ DATABASE_HANDLE | DATA_SOURCE [ USERNAME PASSWORD [ ATTR ] ] ]
+
+Returns a list of SQL statements to update this schema so that it is idential
+to the provided prototype schema, also a DBIx::DBSchema object.
+
+Right now this method knows how to add new tables and alter existing tables,
+including indices. If specifically requested by passing an options hashref
+with B<drop_tables> set true before all other arguments, it will also drop
+tables.
+
+See L<DBIx::DBSchema::Table/sql_alter_table>,
+L<DBIx::DBSchema::Column/sql_add_column> and
+L<DBIx::DBSchema::Column/sql_alter_column> for additional specifics and
+limitations.
+
+The data source can be specified by passing an open DBI database handle, or by
+passing the DBI data source name, username and password.
+
+Although the username and password are optional, it is best to call this method
+with a database handle or data source including a valid username and password -
+a DBI connection will be opened and used to check the database version as well
+as for more reliable quoting and type mapping. Note that the database
+connection will be used passively, B<not> to actually run the CREATE
+statements.
+
+If passed a DBI data source (or handle) such as `DBI:mysql:database' or
+`DBI:Pg:dbname=database', will use syntax specific to that database engine.
+Currently supported databases are MySQL and PostgreSQL.
+
+If not passed a data source (or handle), or if there is no driver for the
+specified database, will attempt to use generic SQL syntax.
+
+=cut
+
+#gosh, false laziness w/DBSchema::Table::sql_alter_schema
+
+sub sql_update_schema {
+ my($self, $opt, $new, $dbh) = ( shift, _parse_opt(\@_), shift, _dbh(@_) );
+
+ my @r = ();
+ my @later = ();
+
+ foreach my $table ( $new->tables ) {
+
+ if ( $self->table($table) ) {
+
+ warn "$table exists\n" if $DEBUG > 1;
+
+ push @r,
+ $self->table($table)->sql_alter_table( $new->table($table),
+ $dbh, $opt );
+ push @later,
+ $self->table($table)->sql_alter_constraints( $new->table($table),
+ $dbh, $opt );
+
+ } else {
+
+ warn "table $table does not exist.\n" if $DEBUG;
+
+ push @r, $new->table($table)->sql_create_table( $dbh );
+ push @later, $new->table($table)->sql_add_constraints( $dbh );
+
+ }
+