[Jifty-commit] r4462 - in jifty/trunk: lib/Jifty lib/Jifty/Script

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Nov 18 16:39:17 EST 2007


Author: jesse
Date: Sun Nov 18 16:39:16 2007
New Revision: 4462

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Config.pm
   jifty/trunk/lib/Jifty/Handle.pm
   jifty/trunk/lib/Jifty/Script/Schema.pm

Log:
 r72119 at pinglin:  jesse | 2007-11-18 12:46:06 -0600
 * Added a new 'AutoUpgrade' option for Jifty and Application schemas, 
 so you don't need to manually upgrade every time jifty or your app version bumps


Modified: jifty/trunk/lib/Jifty/Config.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Config.pm	(original)
+++ jifty/trunk/lib/Jifty/Config.pm	Sun Nov 18 16:39:16 2007
@@ -289,6 +289,7 @@
                 Backend => 'Memcached',
             },
             Database         => {
+                AutoUpgrade => 1,
                 Database =>  $db_name,
                 Driver   => "SQLite",
                 Host     => "localhost",

Modified: jifty/trunk/lib/Jifty/Handle.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handle.pm	(original)
+++ jifty/trunk/lib/Jifty/Handle.pm	Sun Nov 18 16:39:16 2007
@@ -91,7 +91,7 @@
 
     my %lc_db_config;
     # Skip the non-dsn keys, but not anything else
-    for (grep {!/^checkschema|version|forwardcompatible|recordbaseclass|attributes$/i} keys %db_config) {
+    for (grep {!/^autoupgrade|checkschema|version|forwardcompatible|recordbaseclass|attributes$/i} keys %db_config) {
         $lc_db_config{lc($_)} = $db_config{$_};
     }
     $self->SUPER::connect( %lc_db_config , %args);
@@ -114,7 +114,9 @@
 =cut
 
 sub check_schema_version {
+    my $self = shift;
     require Jifty::Model::Metadata;
+            my $autoup = delete Jifty->config->framework('Database')->{'AutoUpgrade'};
 
     # Application db version check
     {
@@ -148,10 +150,16 @@
         unless (version->new($appv) == version->new($dbv)) {
             # if app version is older than db version, but we are still compatible
             my $compat = delete Jifty->config->framework('Database')->{'ForwardCompatible'} || $appv;
-            die
-            "Application schema version in database ($dbv) doesn't match application schema version ($appv)\n"
-            . "Please run `bin/jifty schema --setup` to upgrade the database.\n"
-                if version->new($appv) > version->new($dbv) || version->new($compat) < version->new($dbv);
+            if (version->new($appv) > version->new($dbv) || version->new($compat) < version->new($dbv)) {
+            warn "Application schema version in database ($dbv) doesn't match application schema version ($appv)\n";
+            if( $autoup 
+            ) {
+                warn "Automatically upgrading your database to match the current application schema";
+                $self->_upgrade_schema();
+            } else {
+                 die "Please run `bin/jifty schema --setup` to upgrade the database.\n";
+             }
+            }
         }
     }
 
@@ -165,10 +173,15 @@
             = version->new( Jifty::Model::Metadata->load("jifty_db_version")
                 || '0.60426' );
         my $appv = version->new($Jifty::VERSION);
-        die
-            "Internal jifty schema version in database ($dbv) doesn't match running jifty version ($appv)\n"
-            . "Please run `bin/jifty schema --setup` to upgrade the database.\n"
-            unless $appv == $dbv;
+            unless ( $appv == $dbv ) {
+           warn "Internal jifty schema version in database ($dbv) doesn't match running jifty version ($appv)\n";
+            if( $autoup) {
+                warn "Automatically upgrading your database to match the current Jifty schema\n";
+                $self->_upgrade_schema;
+            } else {
+        die "Please run `bin/jifty schema --setup` to upgrade the database.\n"
+            }
+        };
     }
 
 }
@@ -225,6 +238,15 @@
     }
 }
 
+sub _upgrade_schema {
+    my $self = shift;
+
+    my $hack = {};
+    require Jifty::Script::Schema;
+    bless $hack, "Jifty::Script::Schema";
+    $hack->run_upgrades;
+
+}
 
 =head1 AUTHOR
 

Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm	Sun Nov 18 16:39:16 2007
@@ -48,14 +48,28 @@
     if ( $self->{create_all_tables} ) {
         $self->create_all_tables();
     } elsif ( $self->{'setup_tables'} ) {
-        $self->upgrade_jifty_tables();
-        $self->upgrade_application_tables();
-        $self->upgrade_plugin_tables();
+        $self->run_upgrades();
     } else {
         print "Done.\n";
     }
 }
 
+
+=head2 run_upgrades
+
+Take the actions we need in order to bring an existing database up to current.
+
+=cut
+
+sub run_upgrades {
+    my $self = shift;
+        $self->upgrade_jifty_tables();
+        $self->upgrade_application_tables();
+        $self->upgrade_plugin_tables();
+
+}
+
+
 =head2 setup_environment
 
 Sets up a minimal Jifty environment.


More information about the Jifty-commit mailing list