[Jifty-commit] r3243 - in jifty/trunk: lib/Jifty lib/Jifty/Script
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu May 17 15:04:01 EDT 2007
Author: jesse
Date: Thu May 17 15:03:58 2007
New Revision: 3243
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Record.pm
jifty/trunk/lib/Jifty/Script/Schema.pm
Log:
r56895 at pinglin: jesse | 2007-05-14 18:50:31 -0400
* Moved the commands for add/drop column to Jifty::Record (they should move to JDBI eventually)
* Added a drop_table to Jifty::Record
Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm (original)
+++ jifty/trunk/lib/Jifty/Record.pm Thu May 17 15:03:58 2007
@@ -554,6 +554,22 @@
}
+=head2 drop_table_in_db
+
+When called, this method will generate the SQL to remove this model's
+table in the database and execute it in the application's currently
+open database. This method can destroy a lot of data. Be sure you
+know what you're doing.
+
+
+=cut
+
+sub drop_table_in_db {
+ my $self = shift;
+ my $ret = Jifty->handle->simple_query( 'DROP TABLE ' . $self->table );
+ $ret or die "error removing table $self: " . $ret->error_message;
+}
+
sub _make_schema {
my $class = shift;
@@ -580,6 +596,20 @@
return "ALTER TABLE " . $self->table . " ADD COLUMN " . $definition;
}
+
+=head2 add_column_in_db column_name
+
+Executes the SQL code generated by add_column_sql. Dies on failure.
+
+=cut
+
+sub add_column_in_db {
+ my $self = shift;
+ my $ret = Jifty->handle->simple_query($self->add_column_sql(@_));
+ $ret or die "error adding column ". $_[0] ." to $self: " . $ret->error_message;
+
+}
+
=head2 drop_column_sql column_name
Returns the SQL statement neccessary to remove C<column_name> from this class's representation in the database
@@ -594,6 +624,20 @@
return "ALTER TABLE " . $self->table . " DROP COLUMN " . $col->name;
}
+
+=head2 drop_column_in_db column_name
+
+Executes the SQL code generated by drop_column_sql. Dies on failure.
+
+=cut
+
+sub drop_column_in_db {
+ my $self = shift;
+ my $ret = Jifty->handle->simple_query($self->drop_column_sql(@_));
+ $ret or die "error dropping column ". $_[0] ." to $self: " . $ret->error_message;
+
+}
+
=head2 schema_version
This method is used by L<Jifty::DBI::Record> to determine which schema version is in use. It returns the current database version stored in the configuration.
Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm (original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm Thu May 17 15:03:58 2007
@@ -375,7 +375,7 @@
my $renamed = $upgradeclass->just_renamed || {};
# skip it if this was dropped by a rename
- _exec_sql($model->drop_column_sql($col->name))
+ $model->drop_column_in_db($col->name)
unless defined $renamed
->{ $model->table }
->{'drop'}
@@ -389,7 +389,7 @@
my $renamed = $upgradeclass->just_renamed || {};
# skip it if this was added by a rename
- _exec_sql($model->add_column_sql($col->name))
+ $model->add_column_in_db($col->name)
unless defined $renamed
->{ $model->table }
->{'add'}
More information about the Jifty-commit
mailing list