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,
);
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))
-ALTER TABLE mytable ADD CONSTRAINT enforce_geotype_myfield CHECK ((geometrytype(myfield) = 'POINT'::text OR myfield IS NULL))],
+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 $field2 = SQL::Translator::Schema::Field->new( name => 'myfield',
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_geotype_myfield CHECK ((geometrytype(myfield) = 'POINT'::text OR myfield IS NULL))],
+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');
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))],
+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);
CREATE TABLE mytable (
field3 geometry,
field4 geography(POINT,-1),
- CONSTRAINT enforce_dims_field3 CHECK ((st_ndims(field3) = 2)),
- CONSTRAINT enforce_srid_field3 CHECK ((st_srid(field3) = -1)),
- CONSTRAINT enforce_geotype_field3 CHECK ((geometrytype(field3) = 'POINT'::text OR field3 IS NULL))
+ CONSTRAINT enforce_dims_field3 CHECK ((ST_NDims(field3) = 2)),
+ CONSTRAINT enforce_srid_field3 CHECK ((ST_SRID(field3) = -1)),
+ CONSTRAINT enforce_geotype_field3 CHECK ((GeometryType(field3) = 'POINT'::text OR field3 IS NULL))
);
INSERT INTO geometry_columns VALUES ('','myschema','mytable','field3','2','-1','POINT')],'Create table with geometry works.');