Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/RDBMSRules.pm view on Meta::CPAN
}
sub alter_primary_key_sql
{
shift()->_virtual;
}
sub can_alter_table_name
{
1;
}
sub can_alter_column_name
{
1;
}
sub alter_table_name_sql
{
shift()->_virtual;
}
sub alter_column_name_sql
{
shift()->_virtual;
}
sub recreate_table_sql
{
shift()->_virtual;
}
=pod
sub reverse_engineer
{
my $self = shift;
my $schema = shift;
my $dbh = $schema->driver->handle;
foreach my $table ( $dbh->tables )
{
my $t = $schema->make_table( name => $table );
$self->reverse_engineer_table($t);
}
}
sub reverse_engineer_table
{
my $self = shift;
my $table = shift;
my $dbh = $table->schema->driver->handle;
my $sth = $dbh->column_info( undef, $table->schema->name, $table->name, undef );
while ( my $col_info = $sth->fetchrow_hashref )
{
use Data::Dumper; warn Dumper $col_info;
my %attr = ( name => $col_info->{COLUMN_NAME},
type => $col_info->{TYPE_NAME},
nullable => $col_info->{NULLABLE} ? 1 : 0,
);
$attr{size} =
$col_info->{COLUMN_SIZE} if $col_info->{COLUMN_SIZE};
$attr{precision} =
$col_info->{DECIMAL_DIGITS} if $col_info->{DECIMAL_DIGITS};
$attr{default} =
$col_info->{COLUMN_DEF} if defined $col_info->{COLUMN_DEF};
$attr{comment} =
$col_info->{REMARKS} if defined $col_info->{REMARKS};
$table->make_column(%attr);
}
$self->reverse_engineer_table_primary_key($table);
}
sub reverse_engineer_table_primary_key
{
my $self = shift;
my $table = shift;
my $dbh = $table->schema->driver->handle;
my $sth = $dbh->column_info( undef, $table->schema->name, $table->name );
while ( my $pk_info = $sth->fetchrow_hashref )
{
$table->add_primary_key( $table->column( $pk_info->{COLUMN_NAME} ) );
}
}
=cut
sub rules_id
{
shift()->_virtual;
}
sub schema_sql_diff
{
my $self = shift;
validate( @_, { new => { isa => 'Alzabo::Schema' },
old => { isa => 'Alzabo::Schema' } } );
my %p = @_;
local $self->{state};
my @sql;
my %changed_name;
foreach my $new_t ( $p{new}->tables )
{
( run in 2.764 seconds using v1.01-cache-2.11-cpan-d8267643d1d )