my $temporary = "";
- if(exists $table->{extra}{temporary}) {
- $temporary = $table->{extra}{temporary} ? "TEMPORARY " : "";
+ if(exists $table->extra->{temporary}) {
+ $temporary = $table->extra->{temporary} ? "TEMPORARY " : "";
}
my $create_statement;
my @constraints;
push @constraints, SQL::Translator::Schema::Constraint->new(
name => "enforce_dims_".$field->name,
- expression => "(ST_NDims($field) = ".$field->{extra}{dimensions}.")",
+ expression => "(ST_NDims($field) = ".$field->extra->{dimensions}.")",
table => $field->table,
type => CHECK_C,
);
push @constraints, SQL::Translator::Schema::Constraint->new(
name => "enforce_srid_".$field->name,
- expression => "(ST_SRID($field) = ".$field->{extra}{srid}.")",
+ expression => "(ST_SRID($field) = ".$field->extra->{srid}.")",
table => $field->table,
type => CHECK_C,
);
push @constraints, SQL::Translator::Schema::Constraint->new(
name => "enforce_geotype_".$field->name,
- expression => "(GeometryType($field) = '".$field->{extra}{geometry_type}."'::text OR $field IS NULL)",
+ expression => "(GeometryType($field) = '".$field->extra->{geometry_type}."'::text OR $field IS NULL)",
table => $field->table,
type => CHECK_C,
);
# Geography
#
if($data_type eq 'geography'){
- $data_type .= '('.$field->{extra}{geography_type}.','. $field->{extra}{srid} .')'
+ $data_type .= '('.$field->extra->{geography_type}.','. $field->extra->{srid} .')'
}
return $data_type;
$to_field->name)
if ( !defined $new_default && defined $old_default );
- # add geometry column and contraints
+ # add geometry column and constraints
push @out, add_geometry_column($to_field) if is_geometry($to_field);
push @out, add_geometry_constraints($to_field) if is_geometry($to_field);
$field->table->schema->name,
$options->{table} ? $options->{table} : $field->table->name,
$field->name,
- $field->{extra}{dimensions},
- $field->{extra}{srid},
- $field->{extra}{geometry_type});
+ $field->extra->{dimensions},
+ $field->extra->{srid},
+ $field->extra->{geometry_type});
return $out;
}
return $out;
}
+sub batch_alter_table {
+ my ( $table, $diff_hash, $options ) = @_;
+ my $qt = $options->{quote_table_names} || '';
+ $generator->quote_chars([$qt]);
+
+ # as long as we're not renaming the table we don't need to be here
+ if ( @{$diff_hash->{rename_table}} == 0 ) {
+ return map {
+ if (@{ $diff_hash->{$_} || [] }) {
+ my $meth = __PACKAGE__->can($_) or die __PACKAGE__ . " cant $_";
+ map { $meth->( (ref $_ eq 'ARRAY' ? @$_ : $_), $options ) }
+ @{ $diff_hash->{$_} }
+ }
+ else { () }
+ } qw/alter_drop_constraint
+ alter_drop_index
+ drop_field
+ add_field
+ alter_field
+ rename_field
+ alter_create_index
+ alter_create_constraint
+ alter_table/;
+ }
+
+ # first we need to perform drops which are on old table
+ my @sql = map {
+ if (@{ $diff_hash->{$_} || [] }) {
+ my $meth = __PACKAGE__->can($_) or die __PACKAGE__ . " cant $_";
+ map { $meth->( (ref $_ eq 'ARRAY' ? @$_ : $_), $options ) }
+ @{ $diff_hash->{$_} }
+ }
+ else { () }
+ } qw/alter_drop_constraint
+ alter_drop_index
+ drop_field/;
+
+ # next comes the rename_table
+ my $old_table = $diff_hash->{rename_table}[0][0];
+ push @sql, rename_table( $old_table, $table, $options );
+
+ # for alter_field (and so also rename_field) we need to make sure old
+ # field has table name set to new table otherwise calling alter_field dies
+ $diff_hash->{alter_field} =
+ [map { $_->[0]->table($table) && $_ } @{$diff_hash->{alter_field}}];
+ $diff_hash->{rename_field} =
+ [map { $_->[0]->table($table) && $_ } @{$diff_hash->{rename_field}}];
+
+ # now add everything else
+ push @sql, map {
+ if (@{ $diff_hash->{$_} || [] }) {
+ my $meth = __PACKAGE__->can($_) or die __PACKAGE__ . " cant $_";
+ map { $meth->( (ref $_ eq 'ARRAY' ? @$_ : $_), $options ) }
+ @{ $diff_hash->{$_} }
+ }
+ else { () }
+ } qw/add_field
+ alter_field
+ rename_field
+ alter_create_index
+ alter_create_constraint
+ alter_table/;
+
+ return @sql;
+}
+
1;
# -------------------------------------------------------------------