[Jifty-commit] r990 - in jifty/trunk: . lib lib/Jifty lib/Jifty/Script lib/Jifty/Upgrade lib/Jifty/Web

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu May 4 16:25:02 EDT 2006


Author: alexmv
Date: Thu May  4 16:25:00 2006
New Revision: 990

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty.pm
   jifty/trunk/lib/Jifty/Handle.pm
   jifty/trunk/lib/Jifty/Model/Metadata.pm
   jifty/trunk/lib/Jifty/Model/Session.pm
   jifty/trunk/lib/Jifty/Script/Schema.pm
   jifty/trunk/lib/Jifty/Upgrade.pm
   jifty/trunk/lib/Jifty/Upgrade/Internal.pm
   jifty/trunk/lib/Jifty/Web/Session.pm

Log:
 r12829 at zoq-fot-pik:  chmrr | 2006-05-04 16:24:18 -0400
  * Rename 'key' to 'data_key'


Modified: jifty/trunk/lib/Jifty.pm
==============================================================================
--- jifty/trunk/lib/Jifty.pm	(original)
+++ jifty/trunk/lib/Jifty.pm	Thu May  4 16:25:00 2006
@@ -5,7 +5,7 @@
 use encoding 'utf8';
 # Work around the fact that Time::Local caches thing on first require
 BEGIN { local $ENV{'TZ'} = "GMT";  require Time::Local;}
-our $VERSION = '0.60428';
+our $VERSION = '0.60504';
 
 =head1 NAME
 

Modified: jifty/trunk/lib/Jifty/Handle.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handle.pm	(original)
+++ jifty/trunk/lib/Jifty/Handle.pm	Thu May  4 16:25:00 2006
@@ -108,8 +108,8 @@
         my $dbv  = Jifty::Model::Metadata->load("application_db_version");
         my $appv = Jifty->config->framework('Database')->{'Version'};
 
-        # Backwards compatibility -- it used to be in _db_version
         if ( not defined $dbv ) {
+            # First layer of backwards compatibility -- it used to be in _db_version
             my @v;
             eval {
                 local $SIG{__WARN__} = sub { };
@@ -118,6 +118,14 @@
             };
             $dbv = join( ".", @v ) if @v == 3;
         }
+        if ( not defined $dbv ) {
+            # It was also called the 'key' column, not the data_key column
+            eval {
+                local $SIG{__WARN__} = sub { };
+                $dbv = Jifty->handle->fetch_result(
+                    "SELECT value FROM _jifty_metadata WHERE key = 'application_db_version'");
+            };
+        }
 
         die
             "Application schema has no version in the database; perhaps you need to run this:\n"

Modified: jifty/trunk/lib/Jifty/Model/Metadata.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Model/Metadata.pm	(original)
+++ jifty/trunk/lib/Jifty/Model/Metadata.pm	Thu May  4 16:25:00 2006
@@ -22,8 +22,8 @@
 package Jifty::Model::Metadata::Schema;
 use Jifty::DBI::Schema;
 
-column key   => type is 'text';
-column value => type is 'text';
+column data_key => type is 'text';
+column value    => type is 'text';
 
 package Jifty::Model::Metadata;
 use version;
@@ -66,7 +66,7 @@
     # here, right now.
     eval {
         local $SIG{__WARN__} = sub { };
-        $self->load_by_cols( key => $key );
+        $self->load_by_cols( data_key => $key );
     };
     return undef unless $self->id;
     return $self->value;
@@ -85,11 +85,11 @@
         unless ref $self;
 
     my ( $key, $value ) = @_;
-    $self->load_by_cols( key => $key );
+    $self->load_by_cols( data_key => $key );
     if ( $self->id ) {
         $self->set_value($value);
     } else {
-        $self->create( key => $key, value => $value );
+        $self->create( data_key => $key, value => $value );
     }
 }
 

Modified: jifty/trunk/lib/Jifty/Model/Session.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Model/Session.pm	(original)
+++ jifty/trunk/lib/Jifty/Model/Session.pm	Thu May  4 16:25:00 2006
@@ -18,7 +18,7 @@
 use Jifty::DBI::Schema;
 
 column session_id => type is 'varchar(32)';
-column key => type is 'text';
+column data_key => type is 'text';
 column value => type is 'blob',
   filters are 'Jifty::DBI::Filter::Storable';
 column created => type is 'timestamp',

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  4 16:25:00 2006
@@ -144,13 +144,14 @@
             logger_component => 'SchemaTool',
         );
     };
+    
     if ( $@ =~ /doesn't match (application schema|running jifty) version/i) {
         # We found an out-of-date DB.  Upgrade it
         $self->{setup_tables} = 1;
     } elsif ( $@ =~ /no version in the database/i ) {
         # No version table.  Assume the DB is empty.
         $self->{create_all_tables} = 1;
-    } elsif ( $@ =~ /database .*? does not exist/i ) {
+    } elsif ( $@ =~ /database .*? does not exist/i or $@ =~ /unknown database/) {
         # No database exists; we'll need to make one and fill it up
         $self->{create_database}   = 1;
         $self->{create_all_tables} = 1;
@@ -250,7 +251,18 @@
 
 sub upgrade_jifty_tables {
     my $self = shift;
-    my $dbv  = version->new( Jifty::Model::Metadata->load( 'jifty_db_version' ) || '0.60426' );
+    my $dbv  = Jifty::Model::Metadata->load( 'jifty_db_version' );
+    unless ($dbv) {
+        # Backwards combatibility -- it usd to be 'key' not 'data_key';
+        eval {
+            local $SIG{__WARN__} = sub { };
+            $dbv = Jifty->handle->fetch_result(
+                "SELECT value FROM _jifty_metadata WHERE key = 'jifty_db_version'");
+        };
+    }
+    $dbv ||= '0.60426';
+    $dbv = version->new($dbv);
+
     my $appv = version->new( $Jifty::VERSION );
 
     $self->upgrade_tables( "Jifty" => $dbv, $appv, "Jifty::Upgrade::Internal" );

Modified: jifty/trunk/lib/Jifty/Upgrade.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Upgrade.pm	(original)
+++ jifty/trunk/lib/Jifty/Upgrade.pm	Thu May  4 16:25:00 2006
@@ -16,7 +16,7 @@
 
 use base qw/Jifty::Object Exporter/;
 use vars qw/%UPGRADES @EXPORT/;
- at EXPORT = qw/since/;
+ at EXPORT = qw/since rename/;
 
 =head2 since I<VERSION> I<SUB>
 
@@ -59,9 +59,39 @@
 =cut
 
 sub upgrade_to {
-  my $class = shift;
-  my $version = shift;
-  return $UPGRADES{$class}{$version} || sub {};
+    my $class = shift;
+    my $version = shift;
+    return $UPGRADES{$class}{$version} || sub {};
+}
+
+=head2 rename table => CLASS, [column => COLUMN,] to => NAME
+
+Used in upgrade subroutines, this executes the necessary SQL to rename
+the table, or column in the table, to a new name.
+
+=cut
+
+sub rename {
+    my (%args) = @_;
+
+    $args{table} ||= $args{in};
+    die "Must provide a table to rename";
+
+    Jifty::Util->require($args{table});
+    $args{table} = $args{table}->table;
+
+    if ($args{column}) {
+        my $driver = Jifty->config->framework('Database')->{'Driver'};
+        if ($driver eq "SQLite") {
+            # SQLite doesn't support renaming columns -- cruel hack to
+            # just add the new name
+            die "SQLite does not support table renaming.  We are sad!";
+        } else {
+            Jifty->handle->simple_query("ALTER TABLE $args{table} RENAME $args{column} TO $args{to}");
+        }
+    } else {
+        Jifty->handle->simple_query("ALTER TABLE $args{table} RENAME TO $args{to}");
+    }
 }
 
 1;

Modified: jifty/trunk/lib/Jifty/Upgrade/Internal.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Upgrade/Internal.pm	(original)
+++ jifty/trunk/lib/Jifty/Upgrade/Internal.pm	Thu May  4 16:25:00 2006
@@ -20,4 +20,9 @@
     Jifty::Model::Metadata->store( application_db_version => version->new(join'.', at v));
 };
 
+since '0.60504' => sub {
+    rename column => 'key', in => 'Jifty::Model::Session',  to => 'data_key';
+    rename column => 'key', in => 'Jifty::Model::Metadata', to => 'data_key';
+};
+
 1;

Modified: jifty/trunk/lib/Jifty/Web/Session.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Session.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Session.pm	Thu May  4 16:25:00 2006
@@ -113,7 +113,7 @@
     $setting->load_by_cols(
         session_id => $self->id,
         key_type   => $key_type,
-        key        => $key
+        data_key   => $key
     );
     return $setting->value;
 }
@@ -139,7 +139,7 @@
     $setting->load_by_cols(
         session_id => $self->id,
         key_type   => $key_type,
-        key        => $key
+        data_key   => $key
     );
     if ( $setting->id ) {
         $setting->set_value($value);
@@ -147,7 +147,7 @@
         $setting->create(
             session_id => $self->id,
             key_type   => $key_type,
-            key        => $key,
+            data_key   => $key,
             value      => $value
         );
     }
@@ -171,7 +171,7 @@
     $setting->load_by_cols(
         session_id => $self->id,
         key_type   => $key_type,
-        key        => $key
+        data_key   => $key
     );
     $setting->delete if $setting->id;
 }


More information about the Jifty-commit mailing list