[Jifty-commit] r2787 - in jifty/branches/virtual-models: . lib/Jifty lib/Jifty/Manual lib/Jifty/Model lib/Jifty/Script t/TestApp-DatabaseBackedModels/etc t/TestApp-DatabaseBackedModels/lib/TestApp/DatabaseBackedModels t/TestApp-DatabaseBackedModels/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Feb 11 00:04:00 EST 2007


Author: jesse
Date: Sun Feb 11 00:03:58 2007
New Revision: 2787

Modified:
   jifty/branches/virtual-models/   (props changed)
   jifty/branches/virtual-models/lib/Jifty/ClassLoader.pm
   jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm
   jifty/branches/virtual-models/lib/Jifty/Model/ModelClass.pm
   jifty/branches/virtual-models/lib/Jifty/Record.pm
   jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm
   jifty/branches/virtual-models/lib/Jifty/Script/Database.pm
   jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/etc/config.yml
   jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/lib/TestApp/DatabaseBackedModels/Bootstrap.pm
   jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/t/dump_load.t

Log:
 r21989 at hualien:  jesse | 2007-02-11 00:03:37 -0500
 * POD cleanups
 * Additional tests of database backed models
 * Disabled versioned records, as the versioned stuff isn't at all baked
 


Modified: jifty/branches/virtual-models/lib/Jifty/ClassLoader.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/ClassLoader.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/ClassLoader.pm	Sun Feb 11 00:03:58 2007
@@ -226,13 +226,14 @@
 sub _require_model_related_classes {
     my $self = shift;
     my $full = shift;
-    push (@{$self->models}, $full); 
+    push( @{ $self->models }, $full );
 
     my $base = $self->{base};
-        my($short) = $full =~ /::Model::(.*)/;
-        Jifty::Util->require($full . "Collection");
-        Jifty::Util->require($base . "::Action::" . $_ . $short)
-            for qw/Create Update Delete Search/;
+
+    my ($short) = $full =~ /::Model::(.*)/;
+    Jifty::Util->require( $full . "Collection" );
+    Jifty::Util->require( $base . "::Action::" . $_ . $short )
+        for qw/Create Update Delete Search/;
 
 }
 

Modified: jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Manual/Config.pm	Sun Feb 11 00:03:58 2007
@@ -62,6 +62,7 @@
 =head4 Database
 
 =over
+
 =item                Database =>  $db_name,
 
 =item                Driver   => "SQLite",

Modified: jifty/branches/virtual-models/lib/Jifty/Model/ModelClass.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Model/ModelClass.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Model/ModelClass.pm	Sun Feb 11 00:03:58 2007
@@ -73,6 +73,12 @@
 }
 
 
+=head2 delete
+
+When deleting model classes from the metamodel tables, we also drop the table in the database.
+
+=cut
+
 sub delete {
     my $self = shift;
     # XXX TODO: remove all columns here.

Modified: jifty/branches/virtual-models/lib/Jifty/Record.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Record.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Record.pm	Sun Feb 11 00:03:58 2007
@@ -447,6 +447,15 @@
 
 }
 
+=head2 drop_table_in_db
+
+When called, this method will drop the table that backs this model class from your 
+database. Generally, this operation can't be done and will result in data loss.
+Don't call it unless data loss is your objective.
+
+
+=cut
+
 sub drop_table_in_db {
     my $class = shift;
 

Modified: jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Record/Versioned.pm	Sun Feb 11 00:03:58 2007
@@ -30,6 +30,13 @@
 
 my ($repos, $fs, $uri);
 
+
+=head2  init_repos
+
+Create a new SVN repository for storing records.
+
+=cut
+
 sub init_repos {
     my $self = shift;
     return ($repos, $fs, $uri) if $repos;
@@ -61,6 +68,12 @@
     return ($repos, $fs, $uri) if $repos;
 }
 
+=head2 new_edit
+
+audreyt: DOC ME XXX TODO
+
+=cut
+
 sub new_edit {
     my $self = shift;
     my ($repos, $fs, $uri) = $self->init_repos;

Modified: jifty/branches/virtual-models/lib/Jifty/Script/Database.pm
==============================================================================
--- jifty/branches/virtual-models/lib/Jifty/Script/Database.pm	(original)
+++ jifty/branches/virtual-models/lib/Jifty/Script/Database.pm	Sun Feb 11 00:03:58 2007
@@ -34,6 +34,8 @@
 
 =head2 run
 
+Dump or load the current database.
+
 
 =cut
 
@@ -45,6 +47,14 @@
     elsif ($self->{load}) { $self->load(); }
 }
 
+
+=head2 load
+
+Reads a database dumpfile in YAML format on STDIN. Creates or updates your internal database as necessary.
+
+
+=cut
+
 sub load {
     my $self = shift;
     my @content = <STDIN>;
@@ -74,6 +84,14 @@
     Jifty->handle->commit;
 }
 
+
+=head2 load_content_for_class CLASSNAME HASH
+
+Loads a hash of data into records of type CLASSNAME
+
+=cut
+
+
 sub load_content_for_class {
     my $self    = shift;
     my $class   = shift;
@@ -95,7 +113,7 @@
             }
         }
 
-        my ( $val, $msg ) = $class->create( %{ $content->{$id} } );
+        my ( $val, $msg ) = $class->create( %{ $content->{$id} }, __uuid => $id );
         if ($val) {
             $self->log->info("Inserting $id into $class: $val");
         } else {
@@ -108,6 +126,13 @@
 
 }
 
+=head2 upgrade_schema tablehash columnhash
+
+Modify the current database's schema (virtual models and columns) to match that of the table hash and column hash.
+
+
+=cut
+
 
 sub upgrade_schema {
     my $self           = shift;
@@ -160,8 +185,8 @@
                 # Third, add columns that are only in the dumpfile
             }
 
-            foreach my $col ( values %$new_columns ) {
-                Jifty::Model::ModelClassColumn->create(%$col);
+            foreach my $col ( keys %$new_columns ) {
+                Jifty::Model::ModelClassColumn->create($new_columns->{$col}, __uuid => $col);
             }
 
         } else {
@@ -181,11 +206,12 @@
     my $self       = shift;
     my $new_tables = shift;
     my $columns    = shift;
-    foreach my $table ( values %$new_tables ) {
+    foreach my $table_id ( keys %$new_tables ) {
+        my $table = $new_tables->{$table_id};
         $self->log->debug("Creating a new table: ".$table->{name});
         delete $table->{id};
         my $class = Jifty::Model::ModelClass->new();
-        my ( $val, $msg ) = $class->create( %{$table} );
+        my ( $val, $msg ) = $class->create( %{$table}, __uuid => $table_id );
         die $msg unless ($val) ;
         # Now that we have a brand new model, let's find all its columns
         my @cols = grep { $_->{model_class} = $table->{__uuid} } values %$columns;
@@ -198,20 +224,24 @@
 
 }
 
+=head2 dump
 
+Dump the current database state as a YAML hash to STDOUT
+
+=cut
 
 sub dump {
     my $self = shift;
     my $content = $self->_models_to_hash();
-    
     print Jifty::YAML::Dump($content)."\n";
-    
 }
 
 sub _models_to_hash {
         my $self = shift;
         my $content = {};
- foreach my $model (Jifty->class_loader->models, qw(Jifty::Model::Metadata Jifty::Model::ModelClass Jifty::Model::ModelClassColumn)) {
+        foreach my $model (Jifty->class_loader->models, qw(Jifty::Model::Metadata Jifty::Model::ModelClass Jifty::Model::ModelClassColumn)) {
+
+
         next unless $model->isa('Jifty::Record');
         my $collection = $model."Collection";
         Jifty::Util->require($collection);

Modified: jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/etc/config.yml
==============================================================================
--- jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/etc/config.yml	(original)
+++ jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/etc/config.yml	Sun Feb 11 00:03:58 2007
@@ -1,5 +1,5 @@
 --- 
-framework: 
+framework:
   AdminMode: 1
   ApplicationClass: TestApp::DatabaseBackedModels
   ApplicationName: TestApp-DatabaseBackedModels
@@ -9,7 +9,8 @@
     Driver: SQLite
     Host: localhost
     Password: ''
-    RecordBaseClass: Jifty::Record::Versioned
+    RecordBaseClass: Jifty::DBI::Record::Cachable
+    RecordUUIDs: active
     User: ''
     Version: 0.0.1
   DevelMode: 1

Modified: jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/lib/TestApp/DatabaseBackedModels/Bootstrap.pm
==============================================================================
--- jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/lib/TestApp/DatabaseBackedModels/Bootstrap.pm	(original)
+++ jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/lib/TestApp/DatabaseBackedModels/Bootstrap.pm	Sun Feb 11 00:03:58 2007
@@ -10,7 +10,6 @@
 
     my $col = Jifty::Model::ModelClassColumn->new(current_user => $user);
     $col->create( name => 'name', label_text => 'Name', storage_type => 'text', hints => 'This is the widget name', model_class => $modelclass);
-    return 1;
        my $col2 = Jifty::Model::ModelClassColumn->new(current_user => $user);
     $col2->create( name => 'inventory', label_text => 'Inventory', storage_type => 'int', hints => 'How many do we have on hand?', model_class => $modelclass);
 

Modified: jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/t/dump_load.t
==============================================================================
--- jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/t/dump_load.t	(original)
+++ jifty/branches/virtual-models/t/TestApp-DatabaseBackedModels/t/dump_load.t	Sun Feb 11 00:03:58 2007
@@ -20,13 +20,11 @@
 Jifty->new();
 use_ok('Jifty::Script::Database');
 can_ok('TestApp::DatabaseBackedModels::Model::Widget', 'new');
-
 my $DATABASE = Jifty::Script::Database->new();
 
 my $dumped_bootstrap = $DATABASE->_models_to_hash();
 
 my @keys = sort keys %$dumped_bootstrap;
-
 is_deeply(\@keys, [qw/Jifty::Model::Metadata 
                     Jifty::Model::ModelClass 
                     Jifty::Model::ModelClassColumn
@@ -35,6 +33,7 @@
 
 my $dumped_widgets = $dumped_bootstrap->{'TestApp::DatabaseBackedModels::Model::Widget'};
 is (scalar keys %$dumped_widgets, 1);
+diag('got widgets');
 my @values = values %$dumped_widgets;
 my $widget = shift @values;
 is ($widget->{'name'}, 'Weeble', "Dumped data is as expected");
@@ -65,6 +64,8 @@
 $DATABASE->_load_data(\%new_tables);
 can_ok('TestApp::DatabaseBackedModels::Model::Customer', 'new');
 can_ok('TestApp::DatabaseBackedModels::Model::Customer', 'create');
+use_ok('TestApp::DatabaseBackedModels::Model::CustomerCollection');
+can_ok('TestApp::DatabaseBackedModels::Model::CustomerCollection', 'new');
 isa_ok(TestApp::DatabaseBackedModels::Model::Customer->new(), 'Jifty::DBI::Record');
 
 my $obj = TestApp::DatabaseBackedModels::Model::Customer->create();
@@ -86,6 +87,9 @@
     } 
 );
 $DATABASE->_load_data(\%new_tables);
+can_ok('TestApp::DatabaseBackedModels::Model::Vendor', 'new');
+can_ok('TestApp::DatabaseBackedModels::Model::Vendor', 'create');
+ok(!TestApp::DatabaseBackedModels::Model::Vendor->can('name'));
 can_ok('TestApp::DatabaseBackedModels::Model::Customer', 'new');
 can_ok('TestApp::DatabaseBackedModels::Model::Customer', 'create');
 can_ok('TestApp::DatabaseBackedModels::Model::Customer', 'name');
@@ -95,9 +99,6 @@
 $customers->unlimit();
 is($customers->count(),1);
 is($customers->first->name, 'Cogswell Cogs');
-can_ok('TestApp::DatabaseBackedModels::Model::Vendor', 'new');
-can_ok('TestApp::DatabaseBackedModels::Model::Vendor', 'create');
-ok(!can('TestApp::DatabaseBackedModels::Model::Vendor', 'name'));
 
 
 }


More information about the Jifty-commit mailing list