#!/usr/bin/perl --
use strict; use warnings;
#~ http://cpansearch.perl.org/src/JROBINSON/SQL-Translator-0.11010/t/4
+7postgres-producer.t
use SQL::Translator::Schema::Table;
use SQL::Translator::Producer::PostgreSQL;
my $table = SQL::Translator::Schema::Table->new( name => 'urls' );
#~ column_name | data_type
#~ -----------------+-------------------
my %columnType = map { split /\s+\|\s+/, $_ }
split /[\r\n]+/, <<'__COL_TYPE__';
date_checked | date
http_code | integer
base_uri | text
host_alive | boolean
last_check_good | boolean
count_fails | integer
count_success | integer
pri | boolean
url | text
table_id | integer
tbl | character varying
id | integer
__COL_TYPE__
while( my( $name, $type ) = each %columnType ){
my $field = SQL::Translator::Schema::Field->new(
name => $name,
table => $table,
data_type => $type,
);
$table->add_field( $field );
}
#~ use Data::Dump ; dd SQL::Translator::Producer::PostgreSQL::create_t
+able($table) ;
my( $sql, $rest ) = SQL::Translator::Producer::PostgreSQL::create_tabl
+e($table);
print "$sql;\n\n";
__END__
--
-- Table: urls
--
CREATE TABLE urls (
tbl character varying,
url text,
id integer,
host_alive boolean,
count_fails integer,
base_uri text,
pri boolean,
http_code integer,
date_checked date,
count_success integer,
table_id integer,
last_check_good boolean
);
package EDINA::ORI::urls;
use base 'DBIx::Class';
use strict;
use warnings;
__PACKAGE__->load_components(qw/ Core/);
__PACKAGE__->table('urls');
__PACKAGE__->add_columns(
'tbl' => {
'data_type' => 'varchar',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'tbl',
'is_nullable' => 1,
'size' => 0
},
'url' => {
'data_type' => 'text',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'url',
'is_nullable' => 1,
'size' => '64000'
},
'id' => {
'data_type' => 'integer',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'id',
'is_nullable' => 1,
'size' => '10'
},
'host_alive' => {
'data_type' => 'boolean',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'host_alive',
'is_nullable' => 1,
'size' => 0
},
'count_fails' => {
'data_type' => 'integer',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'count_fails',
'is_nullable' => 1,
'size' => '10'
},
'base_uri' => {
'data_type' => 'text',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'base_uri',
'is_nullable' => 1,
'size' => '64000'
},
'pri' => {
'data_type' => 'boolean',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'pri',
'is_nullable' => 1,
'size' => 0
},
'http_code' => {
'data_type' => 'integer',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'http_code',
'is_nullable' => 1,
'size' => '10'
},
'date_checked' => {
'data_type' => 'date',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'date_checked',
'is_nullable' => 1,
'size' => 0
},
'count_success' => {
'data_type' => 'integer',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'count_success',
'is_nullable' => 1,
'size' => '10'
},
'table_id' => {
'data_type' => 'integer',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'table_id',
'is_nullable' => 1,
'size' => '10'
},
'last_check_good' => {
'data_type' => 'boolean',
'is_auto_increment' => 0,
'default_value' => undef,
'is_foreign_key' => 0,
'name' => 'last_check_good',
'is_nullable' => 1,
'size' => 0
},
);
package EDINA::ORI;
use base 'DBIx::Class::Schema';
use strict;
use warnings;
__PACKAGE__->register_class('urls', 'EDINA::ORI::urls');
1;