# Geometry
#
if (my @geometry_columns = grep { is_geometry($_) } $table->get_fields) {
- $create_statement .= ";";
- $create_statement .= join("\n", '', map{ drop_geometry_column($_) } @geometry_columns) if $options->{add_drop_table};
- $create_statement .= join("\n", '', map{ add_geometry_column($_) } @geometry_columns);
+ $create_statement .= join(";\n", '', map{ drop_geometry_column($_) } @geometry_columns) if $options->{add_drop_table};
+ $create_statement .= join(";\n", '', map{ add_geometry_column($_) } @geometry_columns);
}
return $create_statement, \@fks;
my $out = sprintf('ALTER TABLE %s ADD COLUMN %s',
_generator($options)->quote($new_field->table->name),
create_field($new_field, $options));
- $out .= "\n".add_geometry_column($new_field)
- . "\n".add_geometry_constraints($new_field)
+ $out .= ";\n".add_geometry_column($new_field)
+ . ";\n".add_geometry_constraints($new_field)
if is_geometry($new_field);
return $out;
my $out = sprintf('ALTER TABLE %s DROP COLUMN %s',
$generator->quote($old_field->table->name),
$generator->quote($old_field->name));
- $out .= "\n".drop_geometry_column($old_field)
+ $out .= ";\n".drop_geometry_column($old_field)
if is_geometry($old_field);
return $out;
}
sub add_geometry_constraints {
my ($field, $options) = @_;
- return join("\n", map { alter_create_constraint($_) }
+ return join(";\n", map { alter_create_constraint($_) }
create_geometry_constraints($field));
}
sub drop_geometry_constraints {
my ($field, $options) = @_;
- return join("\n", map { alter_drop_constraint($_) }
+ return join(";\n", map { alter_drop_constraint($_) }
create_geometry_constraints($field));
}
my $out = sprintf('ALTER TABLE %s %s',
$generator->quote($to_table->name),
$options->{alter_table_action});
- $out .= "\n".$options->{geometry_changes} if $options->{geometry_changes};
+ $out .= ";\n".$options->{geometry_changes} if $options->{geometry_changes};
return $out;
}
add_geometry_column($_, { table => $new_table }),
} grep { is_geometry($_) } $old_table->get_fields;
- $options->{geometry_changes} = join ("\n",@geometry_changes) if @geometry_changes;
+ $options->{geometry_changes} = join (";\n",@geometry_changes) if @geometry_changes;
return alter_table($old_table, $options);
}
my @geometry_drops = map { drop_geometry_column($_); } grep { is_geometry($_) } $table->get_fields;
- $out .= join("\n", '', @geometry_drops) if @geometry_drops;
+ $out .= join(";\n", '', @geometry_drops) if @geometry_drops;
return $out;
}
my $field1_geocon = SQL::Translator::Producer::PostgreSQL::add_geometry_constraints($field1);
-is($field1_geocon, qq[ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2))
-ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1))
+is($field1_geocon, qq[ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2));
+ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1));
ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((GeometryType(myfield) = 'POINT'::text OR myfield IS NULL))],
'Add geometry constraints works');
my $alter_field = SQL::Translator::Producer::PostgreSQL::alter_field($field1,
$field2);
is($alter_field, qq[DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'myfield';
-ALTER TABLE mytable DROP CONSTRAINT enforce_dims_myfield
-ALTER TABLE mytable DROP CONSTRAINT enforce_srid_myfield
+ALTER TABLE mytable DROP CONSTRAINT enforce_dims_myfield;
+ALTER TABLE mytable DROP CONSTRAINT enforce_srid_myfield;
ALTER TABLE mytable DROP CONSTRAINT enforce_geotype_myfield;
ALTER TABLE mytable ALTER COLUMN myfield SET NOT NULL;
ALTER TABLE mytable ALTER COLUMN myfield TYPE character varying(25)],
is($alter_field2, qq[ALTER TABLE mytable ALTER COLUMN myfield DROP NOT NULL;
ALTER TABLE mytable ALTER COLUMN myfield TYPE geometry;
INSERT INTO geometry_columns VALUES ('','myschema','mytable','myfield','2','-1','POINT');
-ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2))
-ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1))
+ALTER TABLE mytable ADD CONSTRAINT enforce_dims_myfield CHECK ((ST_NDims(myfield) = 2));
+ALTER TABLE mytable ADD CONSTRAINT enforce_srid_myfield CHECK ((ST_SRID(myfield) = -1));
ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((GeometryType(myfield) = 'POINT'::text OR myfield IS NULL))],
'Alter field non geometry to geometry works');
$field1->name('field3');
my $add_field = SQL::Translator::Producer::PostgreSQL::add_field($field1);
-is($add_field, qq[ALTER TABLE mytable ADD COLUMN field3 geometry
-INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT')
-ALTER TABLE mytable ADD CONSTRAINT enforce_dims_field3 CHECK ((ST_NDims(field3) = 2))
-ALTER TABLE mytable ADD CONSTRAINT enforce_srid_field3 CHECK ((ST_SRID(field3) = -1))
+is($add_field, qq[ALTER TABLE mytable ADD COLUMN field3 geometry;
+INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT');
+ALTER TABLE mytable ADD CONSTRAINT enforce_dims_field3 CHECK ((ST_NDims(field3) = 2));
+ALTER TABLE mytable ADD CONSTRAINT enforce_srid_field3 CHECK ((ST_SRID(field3) = -1));
ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_field3 CHECK ((GeometryType(field3) = 'POINT'::text OR field3 IS NULL))],
'Add geometry field works');
my $drop_field = SQL::Translator::Producer::PostgreSQL::drop_field($field1);
-is($drop_field, qq[ALTER TABLE mytable DROP COLUMN field3
+is($drop_field, qq[ALTER TABLE mytable DROP COLUMN field3;
DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3'], 'Drop geometry field works');
$table->add_field($field1);
INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT')],'Create table with geometry works.');
my $rename_table = SQL::Translator::Producer::PostgreSQL::rename_table($table, "table2");
-is($rename_table,qq[ALTER TABLE mytable RENAME TO table2
-DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3'
+is($rename_table,qq[ALTER TABLE mytable RENAME TO table2;
+DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'mytable' AND f_geometry_column = 'field3';
INSERT INTO geometry_columns VALUES ('','myschema','table2','field3','2','-1','POINT')],'Rename table with geometry works.');
$table->name("table2");
my $drop_table = SQL::Translator::Producer::PostgreSQL::drop_table($table);
-is($drop_table, qq[DROP TABLE table2 CASCADE
+is($drop_table, qq[DROP TABLE table2 CASCADE;
DELETE FROM geometry_columns WHERE f_table_schema = 'myschema' AND f_table_name = 'table2' AND f_geometry_column = 'field3'], 'Drop table with geometry works.');