my $sql_dir = dir($Bin,"..","var");
my @connect_info = DBICTest->_database(
- no_deploy=>1,
- no_populate=>1,
- sqlite_use_file => 1,
+ no_deploy=>1,
+ no_populate=>1,
+ sqlite_use_file => 1,
);
{ # create the schema
my $admin = DBIx::Class::Admin->new(
- schema_class=> "DBICTest::Schema",
- sql_dir=> $sql_dir,
- connect_info => \@connect_info,
+ schema_class=> "DBICTest::Schema",
+ sql_dir=> $sql_dir,
+ connect_info => \@connect_info,
);
isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
lives_ok { $admin->create('MySQL'); } 'Can create MySQL sql';
{ # upgrade schema
#my $schema = DBICTest->init_schema(
-# no_deploy => 1,
-# no_populat => 1,
-# sqlite_use_file => 1,
+# no_deploy => 1,
+# no_populat => 1,
+# sqlite_use_file => 1,
#);
clean_dir($sql_dir);
require DBICVersionOrig;
my $admin = DBIx::Class::Admin->new(
- schema_class => 'DBICVersion::Schema',
- sql_dir => $sql_dir,
- connect_info => \@connect_info,
+ schema_class => 'DBICVersion::Schema',
+ sql_dir => $sql_dir,
+ connect_info => \@connect_info,
);
my $schema = $admin->schema();
require DBICVersionNew;
$admin = DBIx::Class::Admin->new(
- schema_class => 'DBICVersion::Schema',
- sql_dir => "t/var",
- connect_info => \@connect_info
+ schema_class => 'DBICVersion::Schema',
+ sql_dir => "t/var",
+ connect_info => \@connect_info
);
lives_ok { $admin->create($schema->storage->sqlt_type(), {}, "1.0" ); } 'Can create diff for ' . $schema->storage->sqlt_type;
clean_dir($sql_dir);
my $admin = DBIx::Class::Admin->new(
- schema_class => 'DBICVersion::Schema',
- sql_dir => $sql_dir,
- _confirm => 1,
- connect_info => \@connect_info,
+ schema_class => 'DBICVersion::Schema',
+ sql_dir => $sql_dir,
+ _confirm => 1,
+ connect_info => \@connect_info,
);
$admin->version("3.0");
}
sub clean_dir {
- my ($dir) =@_;
- $dir = $dir->resolve;
- if ( ! -d $dir ) {
- $dir->mkpath();
- }
- foreach my $file ($dir->children) {
- # skip any hidden files
- next if ($file =~ /^\./);
- unlink $file;
- }
+ my ($dir) =@_;
+ $dir = $dir->resolve;
+ if ( ! -d $dir ) {
+ $dir->mkpath();
+ }
+ foreach my $file ($dir->children) {
+ # skip any hidden files
+ next if ($file =~ /^\./);
+ unlink $file;
+ }
}
done_testing;
{ # test data maniplulation functions
- # create a DBICTest so we can steal its connect info
- my $schema = DBICTest->init_schema(
- # no_deploy=>1,
- # no_populate=>1,
- sqlite_use_file => 1,
- );
-
-
- my $admin = DBIx::Class::Admin->new(
- schema_class=> "DBICTest::Schema",
- connect_info => $schema->storage->connect_info(),
- quiet => 1,
- _confirm=>1,
- );
- isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
-
- $admin->insert('Employee', { name => 'Matt' });
- my $employees = $schema->resultset('Employee');
- is ($employees->count(), 1, "insert okay" );
-
- my $employee = $employees->find(1);
- is($employee->name(), 'Matt', "insert valid" );
-
- $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'});
-
- $employee = $employees->find(1);
- is($employee->name(), 'Trout', "update Matt to Trout" );
-
- $admin->insert('Employee', {name =>'Aran'});
-
- my $expected_data = [
- [$employee->result_source->columns() ],
- [1,1,undef,undef,undef,'Trout'],
- [2,2,undef,undef,undef,'Aran']
- ];
- my $data;
- lives_ok { $data = $admin->select('Employee')} 'can retrive data from database';
- cmp_deeply($data, $expected_data, 'DB matches whats expected');
-
- $admin->delete('Employee', {name=>'Trout'});
- my $del_rs = $employees->search({name => 'Trout'});
- is($del_rs->count(), 0, "delete Trout" );
- is ($employees->count(), 1, "left Aran" );
+ # create a DBICTest so we can steal its connect info
+ my $schema = DBICTest->init_schema(
+ # no_deploy=>1,
+ # no_populate=>1,
+ sqlite_use_file => 1,
+ );
+
+
+ my $admin = DBIx::Class::Admin->new(
+ schema_class=> "DBICTest::Schema",
+ connect_info => $schema->storage->connect_info(),
+ quiet => 1,
+ _confirm=>1,
+ );
+ isa_ok ($admin, 'DBIx::Class::Admin', 'create the admin object');
+
+ $admin->insert('Employee', { name => 'Matt' });
+ my $employees = $schema->resultset('Employee');
+ is ($employees->count(), 1, "insert okay" );
+
+ my $employee = $employees->find(1);
+ is($employee->name(), 'Matt', "insert valid" );
+
+ $admin->update('Employee', {name => 'Trout'}, {name => 'Matt'});
+
+ $employee = $employees->find(1);
+ is($employee->name(), 'Trout', "update Matt to Trout" );
+
+ $admin->insert('Employee', {name =>'Aran'});
+
+ my $expected_data = [
+ [$employee->result_source->columns() ],
+ [1,1,undef,undef,undef,'Trout'],
+ [2,2,undef,undef,undef,'Aran']
+ ];
+ my $data;
+ lives_ok { $data = $admin->select('Employee')} 'can retrive data from database';
+ cmp_deeply($data, $expected_data, 'DB matches whats expected');
+
+ $admin->delete('Employee', {name=>'Trout'});
+ my $del_rs = $employees->search({name => 'Trout'});
+ is($del_rs->count(), 0, "delete Trout" );
+ is ($employees->count(), 1, "left Aran" );
}