-foreach my $table ( dbdef_dist->tables ) {
-
- if ( dbdef->table($table) ) {
-
- warn "$table exists\n" if $DEBUG > 1;
-
- foreach my $column ( dbdef_dist->table($table)->columns ) {
- if ( dbdef->table($table)->column($column) ) {
- warn " $table.$column exists\n" if $DEBUG > 2;
- } else {
-
- if ( $DEBUG ) {
- print STDERR "column $table.$column does not exist. create?";
- next unless yesno();
- }
-
- foreach my $statement (
- dbdef_dist->table($table)->column($column)->sql_add_column( $dbh )
- ) {
- warn "$statement\n" if $DEBUG || $DRY_RUN;
- unless ( $DRY_RUN ) {
- $dbh->do( $statement)
- or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement";
- }
- }
-
- }
-
- }
-
- #should eventually check & create missing indices
-
- #should eventually drop columns not in dbdef_dist...
-
- } else {
-
- if ( $DEBUG ) {
- print STDERR "table $table does not exist. create?";
- next unless yesno();
- }
-
- foreach my $statement (
- dbdef_dist->table($table)->sql_create_table( $dbh )
- ) {
- warn "$statement\n" if $DEBUG || $DRY_RUN;
- unless ( $DRY_RUN ) {
- $dbh->do( $statement)
- or die "CREATE error: ". $dbh->errstr. "\nexecuting: $statement";
- }
- }
-
- }
-
+if ( $DRY_RUN ) {
+ print join(";\n", dbdef->sql_update_schema( dbdef_dist, $dbh ) ). ";\n";
+ exit;
+} else {
+ dbdef->update_schema( dbdef_dist, $dbh );