# Don't ship the last dist we built :)
\.tar\.gz$
+
+# Skip maint stuff
+^maint/
# print Dumper($dbixschema->registered_classes);
- foreach my $tableclass ($dbixschema->registered_classes)
+ #foreach my $tableclass ($dbixschema->registered_classes)
+ foreach my $moniker ($dbixschema->sources)
{
- eval "use $tableclass";
- print("Can't load $tableclass"), next if($@);
- my $source = $tableclass->result_source_instance;
+ #eval "use $tableclass";
+ #print("Can't load $tableclass"), next if($@);
+ my $source = $dbixschema->source($moniker);
my $table = $schema->add_table(
name => $source->name,
# data_type is a number, column_type is text?
my %colinfo = (
name => $col,
- default_value => '',
size => 0,
is_auto_increment => 0,
is_foreign_key => 0,
is_nullable => 0,
%{$source->column_info($col)}
);
+ if ($colinfo{is_nullable}) {
+ $colinfo{default} = '' unless exists $colinfo{default};
+ }
my $f = $table->add_field(%colinfo) || die $table->error;
}
$table->primary_key($source->primary_columns);
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use lib qw(lib t/lib);
+
+use UNIVERSAL::require;
+
+my $from = 'SQL::Translator::Parser::DBIx::Class';
+my $to = 'SQL::Translator::Producer::SQLite';
+my $sqlt = 'SQL::Translator';
+my $schema = 'DBICTest::Schema';
+
+$from->require;
+$to->require;
+$sqlt->require;
+$schema->require;
+
+my $tr = $sqlt->new;
+
+$from->can("parse")->($tr, $schema);
+print $to->can("produce")->($tr);
use base 'DBIx::Class::Core';
DBICTest::Schema::Artist->table('artist');
-DBICTest::Schema::Artist->add_columns('artistid', {}, 'name');
+DBICTest::Schema::Artist->add_columns(
+ 'artistid' => {
+ data_type => 'integer',
+ is_auto_increment => 1
+ },
+ 'name' => {
+ data_type => 'varchar',
+ is_nullable => 1,
+ },
+);
DBICTest::Schema::Artist->set_primary_key('artistid');
__PACKAGE__->mk_classdata('field_name_for', {
use base 'DBIx::Class::Core';
__PACKAGE__->table('artist_undirected_map');
-__PACKAGE__->add_columns(qw/id1 id2/);
+__PACKAGE__->add_columns(
+ 'id1' => { data_type => 'integer' },
+ 'id2' => { data_type => 'integer' },
+);
__PACKAGE__->set_primary_key(qw/id1 id2/);
1;
use base 'DBIx::Class::Core';
DBICTest::Schema::CD->table('cd');
-DBICTest::Schema::CD->add_columns(qw/cdid artist title year/);
+DBICTest::Schema::CD->add_columns(
+ 'cdid' => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'artist' => {
+ data_type => 'integer',
+ },
+ 'title' => {
+ data_type => 'varchar',
+ },
+ 'year' => {
+ data_type => 'varchar',
+ },
+);
DBICTest::Schema::CD->set_primary_key('cdid');
DBICTest::Schema::CD->add_unique_constraint(artist_title => [ qw/artist title/ ]);
use base 'DBIx::Class::Core';
__PACKAGE__->table('cd_to_producer');
-__PACKAGE__->add_columns(qw/cd producer/);
+__PACKAGE__->add_columns(
+ cd => { data_type => 'integer' },
+ producer => { data_type => 'integer' },
+);
__PACKAGE__->set_primary_key(qw/cd producer/);
1;
use base 'DBIx::Class::Core';
DBICTest::Schema::FourKeys->table('fourkeys');
-DBICTest::Schema::FourKeys->add_columns(qw/foo bar hello goodbye/);
+DBICTest::Schema::FourKeys->add_columns(
+ 'foo' => { data_type => 'integer' },
+ 'bar' => { data_type => 'integer' },
+ 'hello' => { data_type => 'integer' },
+ 'goodbye' => { data_type => 'integer' },
+);
DBICTest::Schema::FourKeys->set_primary_key(qw/foo bar hello goodbye/);
1;
use base qw/DBIx::Class::Core/;
DBICTest::Schema::LinerNotes->table('liner_notes');
-DBICTest::Schema::LinerNotes->add_columns(qw/liner_id notes/);
+DBICTest::Schema::LinerNotes->add_columns(
+ 'liner_id' => {
+ data_type => 'integer',
+ },
+ 'notes' => {
+ data_type => 'varchar',
+ },
+);
DBICTest::Schema::LinerNotes->set_primary_key('liner_id');
1;
use base 'DBIx::Class::Core';
DBICTest::Schema::OneKey->table('onekey');
-DBICTest::Schema::OneKey->add_columns(qw/id artist cd/);
+DBICTest::Schema::OneKey->add_columns(
+ 'id' => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'artist' => {
+ data_type => 'integer',
+ },
+ 'cd' => {
+ data_type => 'integer',
+ },
+);
DBICTest::Schema::OneKey->set_primary_key('id');
use base 'DBIx::Class::Core';
__PACKAGE__->table('producer');
-__PACKAGE__->add_columns(qw/producerid name/);
+__PACKAGE__->add_columns(
+ 'producerid' => {
+ data_type => 'integer',
+ is_auto_increment => 1
+ },
+ 'name' => {
+ data_type => 'varchar',
+ },
+);
__PACKAGE__->set_primary_key('producerid');
1;
use base 'DBIx::Class::Core';\r
\r
__PACKAGE__->table('self_ref');\r
-__PACKAGE__->add_columns(qw/id name/);\r
+__PACKAGE__->add_columns(\r
+ 'id' => {\r
+ data_type => 'integer',\r
+ is_auto_increment => 1,\r
+ },\r
+ 'name' => {\r
+ data_type => 'varchar',\r
+ },\r
+);\r
__PACKAGE__->set_primary_key('id');\r
\r
1;\r
use base 'DBIx::Class::Core';\r
\r
__PACKAGE__->table('self_ref_alias');\r
-__PACKAGE__->add_columns(qw/self_ref alias/);\r
+__PACKAGE__->add_columns(\r
+ 'self_ref' => {\r
+ data_type => 'integer',\r
+ },\r
+ 'alias' => {\r
+ data_type => 'integer',\r
+ },\r
+);\r
__PACKAGE__->set_primary_key('self_ref alias');\r
\r
1;\r
use base qw/DBIx::Class::Core/;
DBICTest::Schema::Tag->table('tags');
-DBICTest::Schema::Tag->add_columns(qw/tagid cd tag/);
+DBICTest::Schema::Tag->add_columns(
+ 'tagid' => {
+ data_type => 'varchar',
+ is_auto_increment => 1,
+ },
+ 'cd' => {
+ data_type => 'integer',
+ },
+ 'tag' => {
+ data_type => 'varchar'
+ },
+);
DBICTest::Schema::Tag->set_primary_key('tagid');
1;
use base 'DBIx::Class::Core';
DBICTest::Schema::Track->table('track');
-DBICTest::Schema::Track->add_columns(qw/trackid cd position title/);
+DBICTest::Schema::Track->add_columns(
+ 'trackid' => {
+ data_type => 'integer',
+ is_auto_increment => 1,
+ },
+ 'cd' => {
+ data_type => 'integer',
+ },
+ 'position' => {
+ data_type => 'integer',
+ },
+ 'title' => {
+ data_type => 'varchar',
+ },
+);
DBICTest::Schema::Track->set_primary_key('trackid');
1;
use base 'DBIx::Class::Core';
DBICTest::Schema::TwoKeys->table('twokeys');
-DBICTest::Schema::TwoKeys->add_columns(qw/artist cd/);
+DBICTest::Schema::TwoKeys->add_columns(
+ 'artist' => { data_type => 'integer' },
+ 'cd' => { data_type => 'integer' },
+);
DBICTest::Schema::TwoKeys->set_primary_key(qw/artist cd/);
1;
my $dbh = DBI->connect($dsn);
my $sql = <<EOSQL;
-CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
-
-CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL,
- title VARCHAR, year VARCHAR);
-
-CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR);
-
-CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
- position INTEGER NOT NULL, title VARCHAR);
-
-CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
- tag VARCHAR);
-
-CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL,
- PRIMARY KEY (artist, cd) );
-
-CREATE TABLE fourkeys (foo INTEGER NOT NULL, bar INTEGER NOT NULL,
- hello INTEGER NOT NULL, goodbye INTEGER NOT NULL,
- PRIMARY KEY (foo, bar, hello, goodbye) );
-
-CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
- artist INTEGER NOT NULL, cd INTEGER NOT NULL );
-
-CREATE TABLE self_ref (id INTEGER NOT NULL PRIMARY KEY,
- name VARCHAR );
-
-CREATE TABLE self_ref_alias (self_ref INTEGER NOT NULL, alias INTEGER NOT NULL,
- PRIMARY KEY( self_ref, alias ) );
-
-CREATE TABLE artist_undirected_map (id1 INTEGER NOT NULL, id2 INTEGER NOT NULL, PRIMARY KEY(id1, id2));
-
-CREATE TABLE producer (producerid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
-
-CREATE TABLE cd_to_producer (cd INTEGER NOT NULL, producer INTEGER NOT NULL);
INSERT INTO artist (artistid, name) VALUES (1, 'Caterwauler McCrae');
EOSQL
+open IN, "t/lib/sqlite.sql";
+
+{ local $/ = undef; $sql = <IN>.$sql; }
+
+close IN;
+
$dbh->do($_) for split(/\n\n/, $sql);
$schema->storage->dbh->do("PRAGMA synchronous = OFF");
1;
+
+__DATA__
+
+CREATE TABLE artist (artistid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
+
+CREATE TABLE cd (cdid INTEGER NOT NULL PRIMARY KEY, artist INTEGER NOT NULL,
+ title VARCHAR, year VARCHAR);
+
+CREATE TABLE liner_notes (liner_id INTEGER NOT NULL PRIMARY KEY, notes VARCHAR);
+
+CREATE TABLE track (trackid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
+ position INTEGER NOT NULL, title VARCHAR);
+
+CREATE TABLE tags (tagid INTEGER NOT NULL PRIMARY KEY, cd INTEGER NOT NULL,
+ tag VARCHAR);
+
+CREATE TABLE twokeys (artist INTEGER NOT NULL, cd INTEGER NOT NULL,
+ PRIMARY KEY (artist, cd) );
+
+CREATE TABLE fourkeys (foo INTEGER NOT NULL, bar INTEGER NOT NULL,
+ hello INTEGER NOT NULL, goodbye INTEGER NOT NULL,
+ PRIMARY KEY (foo, bar, hello, goodbye) );
+
+CREATE TABLE onekey (id INTEGER NOT NULL PRIMARY KEY,
+ artist INTEGER NOT NULL, cd INTEGER NOT NULL );
+
+CREATE TABLE self_ref (id INTEGER NOT NULL PRIMARY KEY,
+ name VARCHAR );
+
+CREATE TABLE self_ref_alias (self_ref INTEGER NOT NULL, alias INTEGER NOT NULL,
+ PRIMARY KEY( self_ref, alias ) );
+
+CREATE TABLE artist_undirected_map (id1 INTEGER NOT NULL, id2 INTEGER NOT NULL, PRIMARY KEY(id1, id2));
+
+CREATE TABLE producer (producerid INTEGER NOT NULL PRIMARY KEY, name VARCHAR);
+
+CREATE TABLE cd_to_producer (cd INTEGER NOT NULL, producer INTEGER NOT NULL);
+
--- /dev/null
+--
+-- Created by SQL::Translator::Producer::SQLite
+-- Created on Fri Jan 27 01:16:24 2006
+--
+BEGIN TRANSACTION;
+
+--
+-- Table: twokeys
+--
+CREATE TABLE twokeys (
+ artist integer NOT NULL,
+ cd integer NOT NULL,
+ PRIMARY KEY (artist, cd)
+);
+
+--
+-- Table: liner_notes
+--
+CREATE TABLE liner_notes (
+ liner_id INTEGER PRIMARY KEY NOT NULL,
+ notes varchar NOT NULL
+);
+
+--
+-- Table: cd_to_producer
+--
+CREATE TABLE cd_to_producer (
+ cd integer NOT NULL,
+ producer integer NOT NULL,
+ PRIMARY KEY (cd, producer)
+);
+
+--
+-- Table: artist
+--
+CREATE TABLE artist (
+ artistid INTEGER PRIMARY KEY NOT NULL,
+ name varchar
+);
+
+--
+-- Table: self_ref_alias
+--
+CREATE TABLE self_ref_alias (
+ self_ref integer NOT NULL,
+ alias integer NOT NULL
+);
+
+--
+-- Table: fourkeys
+--
+CREATE TABLE fourkeys (
+ foo integer NOT NULL,
+ bar integer NOT NULL,
+ hello integer NOT NULL,
+ goodbye integer NOT NULL,
+ PRIMARY KEY (foo, bar, hello, goodbye)
+);
+
+--
+-- Table: cd
+--
+CREATE TABLE cd (
+ cdid INTEGER PRIMARY KEY NOT NULL,
+ artist integer NOT NULL,
+ title varchar NOT NULL,
+ year varchar NOT NULL
+);
+
+--
+-- Table: artist_undirected_map
+--
+CREATE TABLE artist_undirected_map (
+ id1 integer NOT NULL,
+ id2 integer NOT NULL,
+ PRIMARY KEY (id1, id2)
+);
+
+--
+-- Table: onekey
+--
+CREATE TABLE onekey (
+ id INTEGER PRIMARY KEY NOT NULL,
+ artist integer NOT NULL,
+ cd integer NOT NULL
+);
+
+--
+-- Table: track
+--
+CREATE TABLE track (
+ trackid INTEGER PRIMARY KEY NOT NULL,
+ cd integer NOT NULL,
+ position integer NOT NULL,
+ title varchar NOT NULL
+);
+
+--
+-- Table: producer
+--
+CREATE TABLE producer (
+ producerid INTEGER PRIMARY KEY NOT NULL,
+ name varchar NOT NULL
+);
+
+--
+-- Table: self_ref
+--
+CREATE TABLE self_ref (
+ id INTEGER PRIMARY KEY NOT NULL,
+ name varchar NOT NULL
+);
+
+--
+-- Table: tags
+--
+CREATE TABLE tags (
+ tagid varchar NOT NULL,
+ cd integer NOT NULL,
+ tag varchar NOT NULL,
+ PRIMARY KEY (tagid)
+);
+
+COMMIT;
ok($schema->storage(), 'Storage available');
+$schema->source("Artist")->{_columns}{'artistid'} = {};
+
my $typeinfo = $schema->source("Artist")->column_info('artistid');
is($typeinfo->{data_type}, 'INTEGER', 'column_info ok');
}
'data_type' => 'INTEGER'
},
'name' => {
- 'data_type' => 'VARCHAR'
+ 'data_type' => 'varchar'
}
};
is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
# count the SELECTs
DBI->trace(0, undef);
-my $selects = 0;
-my $trace = IO::File->new('t/var/dbic.trace', '<')
+$selects = 0;
+$trace = IO::File->new('t/var/dbic.trace', '<')
or die "Unable to read trace file";
while (<$trace>) {
$selects++ if /SELECT(?!.*WHERE 1=0.*)/;