Hi, folks!
(Version: DBIx-Class-Schema-Loader-0.04005).
I was testing a simple catalyst app, and I found out this:
If I create the sqlite database with this sql:
CREATE TABLE post
(
id integer NOT NULL PRIMARY KEY,
person_id integer,
text text,
FOREIGN KEY(person_id) REFERENCES person(id)
);
CREATE TABLE person
(
id integer NOT NULL PRIMARY KEY,
name text
);
sqlite is happy about it, and creates the database correctly.
But, trying to create a schema from it fails:
# Code taken from the documentation, just adjusted the dsn to point to sqlite instead of pg.
$ perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib \
-e 'make_schema_at("New::Schema::Name", { debug => 1 }, [ "dbi:SQLite:dbname=db" ])'
New::Schema::Name::Post->load_components("Core");
New::Schema::Name::Person->load_components("Core");
New::Schema::Name::Post->table("post");
New::Schema::Name::Post->add_columns(
"id",
{ data_type => "integer", is_nullable => 0, size => undef },
"person_id",
{ data_type => "integer", is_nullable => 0, size => undef },
"text",
{ data_type => "text", is_nullable => 0, size => undef },
);
New::Schema::Name::Post->set_primary_key("create");
DBIx::Class::Schema::Loader::make_schema_at(): No such column create on table post at -e line 1
$
N.B.: set_primary_key("create"); makes no sense.
If instead I create the database with this code:
CREATE TABLE post(
id integer NOT NULL PRIMARY KEY,
person_id integer,
text text,
FOREIGN KEY(person_id) REFERENCES person(id)
);
CREATE TABLE person(
id integer NOT NULL PRIMARY KEY,
name text
);
everything goes smoothly:
$ perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib \
-e 'make_schema_at("New::Schema::Name", { debug => 1 }, [ "dbi:SQLite:dbname=db" ])'
New::Schema::Name::Post->load_components("Core");
New::Schema::Name::Person->load_components("Core");
New::Schema::Name::Post->table("post");
New::Schema::Name::Post->add_columns(
"id",
{ data_type => "integer", is_nullable => 0, size => undef },
"person_id",
{ data_type => "integer", is_nullable => 0, size => undef },
"text",
{ data_type => "text", is_nullable => 0, size => undef },
);
New::Schema::Name::Post->set_primary_key("id");
New::Schema::Name::Person->table("person");
New::Schema::Name::Person->add_columns(
"id",
{ data_type => "integer", is_nullable => 0, size => undef },
"name",
{ data_type => "text", is_nullable => 0, size => undef },
);
New::Schema::Name::Person->set_primary_key("id");
New::Schema::Name::Person->has_many(
"posts",
"New::Schema::Name::Post",
{ "foreign.person_id" => "self.id" },
);
New::Schema::Name::Post->belongs_to(
"person_id",
"New::Schema::Name::Person",
{ id => "person_id" },
);
Dumping manual schema for New::Schema::Name to directory ./lib ...
Schema dump completed.
$
The only difference is the position of the left parentheses.
The new line seems to adversely affect the module.
I'm not the first struck by this bug:
http://perlmonks.org/?node_id=646439
Since catalyst's dummy_create.pl helper uses DBIx-Class-Schema-Loader to do the job:
$ myapp_create.pl model DBIC::Schema
$ script/dummy_create.pl model DB DBIC::Schema Dummy::Schema create=static dbi:SQLite:dbname=db
exists "/home/pancho/catalyst/Dummy/script/../lib/Dummy/Model"
exists "/home/pancho/catalyst/Dummy/script/../t"
DBIx::Class::Schema::Loader::make_schema_at(): No such column create on table post at /usr/share/perl5/Catalyst/Helper/Model/DBIC/Schema.pm line 126
$
But does the job nicely when using the second sql to create the db.
Hope that it helps. If you need more info, please feel free to contact me.
My sincere thanks for your work.
Friendly,
pancho.
--
pancho horrillo
To be conscious that
you are ignorant is a great step
to knowledge.
Benjamin Disraeli