[Jifty-commit] r4105 - in jifty/trunk: lib/Jifty/Script
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Wed Sep 12 23:23:36 EDT 2007
Author: sterling
Date: Wed Sep 12 23:23:35 2007
New Revision: 4105
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Script/Schema.pm
Log:
r12049 at dynpc145: andrew | 2007-09-12 22:19:16 -0500
Improving schema setup for plugins that are turned on after the application is initially deployed.
Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm (original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm Wed Sep 12 23:23:35 2007
@@ -195,7 +195,7 @@
for my $plugin (Jifty->plugins) {
my $plugin_bootstrapper = $plugin->bootstrapper;
Jifty::Util->require($plugin_bootstrapper);
- $plugin_bootstrapper->run() if $bootstrapper->can('run');
+ $plugin_bootstrapper->run() if $plugin_bootstrapper->can('run');
}
};
die $@ if $@;
@@ -342,14 +342,50 @@
for my $plugin (Jifty->plugins) {
my $plugin_class = ref $plugin;
- my $dbv = version->new( Jifty::Model::Metadata->load($plugin_class . '_db_version') || '0.0.0' );
+
+ my $dbv = Jifty::Model::Metadata->load($plugin_class . '_db_version');
my $appv = version->new( $plugin->version );
- next unless $self->upgrade_tables( $plugin_class, $dbv, $appv, $plugin->upgrade_class );
- if ( $self->{print} ) {
- warn "Need to upgrade ${plugin_class}_db_version to $appv here!";
- } else {
- Jifty::Model::Metadata->store( $plugin_class . '_db_version' => $appv );
+ # Upgrade this plugin from dbv -> appv
+ if (defined $dbv) {
+ $dbv = version->new( $dbv );
+
+ next unless $self->upgrade_tables( $plugin_class, $dbv, $appv, $plugin->upgrade_class );
+ if ( $self->{print} ) {
+ warn "Need to upgrade ${plugin_class}_db_version to $appv here!";
+ } else {
+ Jifty::Model::Metadata->store( $plugin_class . '_db_version' => $appv );
+ }
+ }
+
+ # Install this plugin
+ else {
+ my $log = Log::Log4perl->get_logger("SchemaTool");
+ $log->info("Generating SQL to set up $plugin_class...");
+ Jifty->handle->begin_transaction;
+
+ # Create the tables
+ $self->create_tables_for_models(
+ grep { $_->isa('Jifty::DBI::Record') and /^\Q$plugin_class\E::Model::/ }
+ $self->schema->models);
+
+ # Save the plugin version to the database
+ Jifty::Model::Metadata->store( $plugin_class . '_db_version' => $appv )
+ unless $self->{print};
+
+ # Run the bootstrapper for initial data
+ unless ($self->{print}) {
+ eval {
+ my $bootstrapper = $plugin->bootstrapper;
+ Jifty::Util->require($bootstrapper);
+ $bootstrapper->run if $bootstrapper->can('run');
+ };
+ die $@ if $@;
+ }
+
+ # Save them records
+ Jifty->handle->commit;
+ $log->info("Set up $plugin_class version $appv");
}
}
}
More information about the Jifty-commit
mailing list