[Rt-commit] r2987 - in DBIx-SearchBuilder/trunk: . SearchBuilder t
glasser at bestpractical.com
glasser at bestpractical.com
Mon May 30 18:43:41 EDT 2005
Author: glasser
Date: Mon May 30 18:43:41 2005
New Revision: 2987
Modified:
DBIx-SearchBuilder/trunk/ (props changed)
DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm
DBIx-SearchBuilder/trunk/t/10schema.t
DBIx-SearchBuilder/trunk/t/testmodels.pl
Log:
r33494 at tin-foil: glasser | 2005-05-30 18:41:14 -0400
Columns, primary keys work in SchemaGen.
Modified: DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm
==============================================================================
--- DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm (original)
+++ DBIx-SearchBuilder/trunk/SearchBuilder/SchemaGenerator.pm Mon May 30 18:43:41 2005
@@ -80,7 +80,8 @@
sub CreateTableSQL {
my $self = shift;
- return join "\n\n", map { "$_ ;" } $self->_db_schema->sql($self->handle->dbh);
+ # The sort here is to make it predictable, so that we can write tests.
+ return join "\n\n", map { "$_ ;" } sort $self->_db_schema->sql($self->handle->dbh);
}
=for private_doc _DBSchemaTableFromModel MODEL
@@ -97,8 +98,27 @@
my $table_name = $model->Table;
my $desc = $model->TableDescription;
- my $table = DBIx::DBSchema::Table->new( {
+ my $primary = "id"; # TODO allow override
+ my $primary_col = DBIx::DBSchema::Column->new({
+ name => $primary,
+ type => 'serial',
+ });
+
+ my @cols = ($primary_col);
+
+ # The sort here is to make it predictable, so that we can write tests.
+ for my $field (sort keys %$desc) {
+ push @cols, DBIx::DBSchema::Column->new({
+ name => $field,
+ type => $desc->{$field}{'TYPE'},
+ null => 'null',
+ });
+ }
+
+ my $table = DBIx::DBSchema::Table->new({
name => $table_name,
+ primary_key => $primary,
+ columns => \@cols,
});
return $table;
Modified: DBIx-SearchBuilder/trunk/t/10schema.t
==============================================================================
--- DBIx-SearchBuilder/trunk/t/10schema.t (original)
+++ DBIx-SearchBuilder/trunk/t/10schema.t Mon May 30 18:43:41 2005
@@ -4,7 +4,7 @@
use warnings;
use Test::More;
-use constant TESTS_PER_DRIVER => 10;
+use constant TESTS_PER_DRIVER => 12;
our @AvailableDrivers;
BEGIN {
@@ -57,12 +57,36 @@
ok($ret != 0, "added model from real class");
- is_spaceless($SG->CreateTableSQL, <<END_SCHEMA, "got the right schema");
- CREATE TABLE Addresses ( ) ;
+ is_ignoring_space($SG->CreateTableSQL, <<END_SCHEMA, "got the right schema");
+ CREATE TABLE Addresses (
+ id serial NOT NULL ,
+ Name varchar ,
+ Phone varchar ,
+ PRIMARY KEY (id)
+ ) ;
+END_SCHEMA
+
+ $ret = $SG->AddModel('Sample::Employee');
+
+ ok($ret != 0, "added model from another real class");
+
+ is_ignoring_space($SG->CreateTableSQL, <<END_SCHEMA, "got the right schema");
+ CREATE TABLE Addresses (
+ id serial NOT NULL ,
+ Name varchar ,
+ Phone varchar ,
+ PRIMARY KEY (id)
+ ) ;
+ CREATE TABLE Employees (
+ id serial NOT NULL ,
+ Dexterity integer ,
+ Name varchar ,
+ PRIMARY KEY (id)
+ ) ;
END_SCHEMA
}}
-sub is_spaceless {
+sub is_ignoring_space {
my $a = shift;
my $b = shift;
Modified: DBIx-SearchBuilder/trunk/t/testmodels.pl
==============================================================================
--- DBIx-SearchBuilder/trunk/t/testmodels.pl (original)
+++ DBIx-SearchBuilder/trunk/t/testmodels.pl Mon May 30 18:43:41 2005
@@ -16,4 +16,17 @@
}
}
+package Sample::Employee;
+
+use base qw/DBIx::SearchBuilder::Record/;
+
+sub Table { "Employees" }
+
+sub TableDescription {
+ return {
+ Name => { TYPE => 'varchar', },
+ Dexterity => { TYPE => 'integer', },
+ }
+}
+
1;
\ No newline at end of file
More information about the Rt-commit
mailing list