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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu May 24 00:14:21 EDT 2007


Author: jesse
Date: Thu May 24 00:14:20 2007
New Revision: 3291

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

Log:
 r57068 at pinglin:  jesse | 2007-05-24 00:06:49 -0400
 * Extract the model list from Script::Schema to Schema


Modified: jifty/trunk/lib/Jifty/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Schema.pm	(original)
+++ jifty/trunk/lib/Jifty/Schema.pm	Thu May 24 00:14:20 2007
@@ -32,10 +32,32 @@
     my $class = shift;
     my $self = {};
     bless $self, $class;
+    $self->_init_model_list();
     return $self;
 
 }
 
+=head2 _init_model_list
+
+Reads in our application class from the config file and finds all our app's models.
+
+=cut
+
+sub _init_model_list {
+
+    my $self = shift;
+
+    # This creates a sub "models" which when called, finds packages under
+    # the application's ::Model, requires them, and returns a list of their
+    # names.
+    Jifty::Module::Pluggable->import(
+        require     => 1,
+        except      => qr/\.#/,
+        search_path => [ "Jifty::Model", Jifty->app_class("Model") ],
+        sub_name    => 'models',
+    );
+}
+
 
 sub serialize_current_schema {
     my $self = shift;    

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 24 00:14:20 2007
@@ -52,7 +52,6 @@
     
     );
     $self->manage_database_existence();
-    $self->prepare_model_classes();
     if ( $self->{create_all_tables} ) {
         $self->create_all_tables();
     } elsif ( $self->{'setup_tables'} ) {
@@ -78,6 +77,20 @@
     Jifty->new( no_handle        => 1, logger_component => 'SchemaTool',) unless Jifty->class_loader;
 }
 
+=head2 schema
+
+Returns a Jifty::Schema object.
+
+=cut
+
+sub schema {
+    my $self = shift;
+
+    $self->{'SCHEMA'} ||= Jifty::Schema->new();
+    return $self->{'SCHEMA'};
+}
+
+
 =head2 print_help
 
 Prints out help for the package using pod2usage.
@@ -98,27 +111,6 @@
         if $self->{man};
 }
 
-=head2 prepare_model_classes
-
-Reads in our application class from the config file and finds all our app's models.
-
-=cut
-
-sub prepare_model_classes {
-
-    my $self = shift;
-
-    # This creates a sub "models" which when called, finds packages under
-    # the application's ::Model, requires them, and returns a list of their
-    # names.
-    Jifty::Module::Pluggable->import(
-        require     => 1,
-        except      => qr/\.#/,
-        search_path => [ "Jifty::Model", Jifty->app_class("Model") ],
-        sub_name    => 'models',
-    );
-}
-
 =head2 probe_database_existence
 
 Probes our database to see if it exists and is up to date.
@@ -197,7 +189,7 @@
     # Start a transaction
     Jifty->handle->begin_transaction;
 
-    $self->create_tables_for_models (grep {$_->isa('Jifty::DBI::Record')}  __PACKAGE__->models );
+    $self->create_tables_for_models (grep {$_->isa('Jifty::DBI::Record')} $self->schema->models );
 
     # Update the versions in the database
     Jifty::Model::Metadata->store( application_db_version => $appv );
@@ -240,7 +232,6 @@
     my $appv = version->new( Jifty->config->framework('Database')->{'Version'} );
     my $jiftyv = version->new( $Jifty::VERSION  );
 
-    my $schema = Jifty::Schema->new();
 
     for my $model ( @models) {
 
@@ -253,7 +244,7 @@
         }
         $log->info("Using $model, as it appears to be new.");
 
-            $schema->_check_reserved($model)
+            $self->schema->_check_reserved($model)
         unless ( $self->{'ignore_reserved'}
             or !Jifty->config->framework('Database')->{'CheckSchema'} );
 
@@ -350,7 +341,7 @@
                      $upgradeclass->versions();
     };
 
-    for my $model_class ( grep {/^\Q$baseclass\E::Model::/} __PACKAGE__->models ) {
+    for my $model_class ( grep {/^\Q$baseclass\E::Model::/} $self->schema->models ) {
 
         # We don't want to get the Collections, for example.
         next unless $model_class->isa('Jifty::DBI::Record');


More information about the Jifty-commit mailing list