Skip to content

Commit

Permalink
Fix all tests where deferrable has become relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair McGowan-Douglas committed Nov 3, 2015
1 parent 2ec331e commit c0eeacf
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 58 deletions.
4 changes: 2 additions & 2 deletions t/17sqlfxml-producer.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ $ans = <<EOXML;
</index>
</indices>
<constraints>
<constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
<constraint name="" type="PRIMARY KEY" fields="id" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="0">
<extra />
</constraint>
<constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="1">
<constraint name="" type="UNIQUE" fields="email" reference_table="" reference_fields="" on_delete="" on_update="" match_type="" expression="" options="" deferrable="0">
<extra />
</constraint>
</constraints>
Expand Down
8 changes: 4 additions & 4 deletions t/23json.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ my $json = to_json(from_json(<<JSON), { canonical => 1, pretty => 1 });
"person" : {
"constraints" : [
{
"deferrable" : 1,
"deferrable" : 0,
"expression" : "",
"fields" : [
"person_id"
Expand All @@ -39,7 +39,7 @@ my $json = to_json(from_json(<<JSON), { canonical => 1, pretty => 1 });
"type" : "PRIMARY KEY"
},
{
"deferrable" : 1,
"deferrable" : 0,
"expression" : "",
"fields" : [
"name"
Expand Down Expand Up @@ -142,7 +142,7 @@ my $json = to_json(from_json(<<JSON), { canonical => 1, pretty => 1 });
"pet" : {
"constraints" : [
{
"deferrable" : 1,
"deferrable" : 0,
"expression" : "",
"fields" : [],
"match_type" : "",
Expand All @@ -155,7 +155,7 @@ my $json = to_json(from_json(<<JSON), { canonical => 1, pretty => 1 });
"type" : "CHECK"
},
{
"deferrable" : 1,
"deferrable" : 0,
"expression" : "",
"fields" : [
"pet_id",
Expand Down
8 changes: 4 additions & 4 deletions t/24yaml.t
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ schema:
tables:
person:
constraints:
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- person_id
Expand All @@ -33,7 +33,7 @@ schema:
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- name
Expand Down Expand Up @@ -117,7 +117,7 @@ schema:
order: 1
pet:
constraints:
- deferrable: 1
- deferrable: 0
expression: ''
fields: []
match_type: ''
Expand All @@ -128,7 +128,7 @@ schema:
reference_fields: []
reference_table: ''
type: CHECK
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- pet_id
Expand Down
11 changes: 4 additions & 7 deletions t/30sqlt-new-diff-pgsql.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ my $out = SQL::Translator::Diff::schema_diff(
}
);

# NOTE that unique_name is an index and not a constraint (create2.yml) and
# therefore does not have the DEFERRABLE flag on it

eq_or_diff($out, <<'## END OF DIFF', "Diff as expected");
-- Convert schema 'create1.yml' to 'create2.yml':;
Expand Down Expand Up @@ -91,9 +88,9 @@ ALTER TABLE "person" RENAME COLUMN "description" TO "physical_description";
ALTER TABLE "person" ADD CONSTRAINT "unique_name" UNIQUE ("name");
ALTER TABLE "person" ADD CONSTRAINT "UC_person_id" UNIQUE ("person_id") DEFERRABLE;
ALTER TABLE "person" ADD CONSTRAINT "UC_person_id" UNIQUE ("person_id");
ALTER TABLE "person" ADD CONSTRAINT "UC_age_name" UNIQUE ("age", "name") DEFERRABLE;
ALTER TABLE "person" ADD CONSTRAINT "UC_age_name" UNIQUE ("age", "name");
DROP TABLE "deleted" CASCADE;
Expand Down Expand Up @@ -144,9 +141,9 @@ ALTER TABLE person ALTER COLUMN nickname TYPE character varying(24);
ALTER TABLE person RENAME COLUMN description TO physical_description;
ALTER TABLE person ADD CONSTRAINT UC_person_id UNIQUE (person_id) DEFERRABLE;
ALTER TABLE person ADD CONSTRAINT UC_person_id UNIQUE (person_id);
ALTER TABLE person ADD CONSTRAINT UC_age_name UNIQUE (age, name) DEFERRABLE;
ALTER TABLE person ADD CONSTRAINT UC_age_name UNIQUE (age, name);
DROP TABLE deleted CASCADE;
Expand Down
2 changes: 1 addition & 1 deletion t/39-filter-globals.t
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ is_deeply ($struct, {
Person => {
constraints => [
{
deferrable => 1,
deferrable => 0,
expression => "",
fields => [
"modified"
Expand Down
8 changes: 4 additions & 4 deletions t/46xml-to-pg.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ CREATE TABLE "Basic" (
"emptytagdef" character varying DEFAULT '',
"another_id" integer DEFAULT 2,
"timest" timestamp,
PRIMARY KEY ("id") DEFERRABLE,
CONSTRAINT "emailuniqueindex" UNIQUE ("email") DEFERRABLE,
CONSTRAINT "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" UNIQUE ("title") DEFERRABLE
PRIMARY KEY ("id"),
CONSTRAINT "emailuniqueindex" UNIQUE ("email"),
CONSTRAINT "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" UNIQUE ("title")
);
CREATE INDEX "titleindex" on "Basic" ("title");
DROP TABLE "Another" CASCADE;
CREATE TABLE "Another" (
"id" serial NOT NULL,
"num" numeric(10,2),
PRIMARY KEY ("id") DEFERRABLE
PRIMARY KEY ("id")
);
DROP VIEW "email_list";
Expand Down
18 changes: 9 additions & 9 deletions t/47postgres-producer.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ my $pk_constraint = SQL::Translator::Schema::Constraint->new(

my ($pk_constraint_def_ref, $pk_constraint_fk_ref ) = SQL::Translator::Producer::PostgreSQL::create_constraint($pk_constraint);
ok(@{$pk_constraint_def_ref} == 1 && @{$pk_constraint_fk_ref} == 0, 'precheck of create_Primary Key constraint');
is($pk_constraint_def_ref->[0], 'CONSTRAINT foo PRIMARY KEY (myfield) DEFERRABLE', 'Create Primary Key Constraint works');
is($pk_constraint_def_ref->[0], 'CONSTRAINT foo PRIMARY KEY (myfield)', 'Create Primary Key Constraint works');

my $alter_pk_constraint = SQL::Translator::Producer::PostgreSQL::alter_drop_constraint($pk_constraint);
is($alter_pk_constraint, 'ALTER TABLE mytable DROP CONSTRAINT foo', 'Alter drop Primary Key constraint works');
Expand Down Expand Up @@ -188,15 +188,15 @@ for my $name ( 'foo', undef ) {
my ($pk_constraint_def_ref, $pk_constraint_pk_ref ) = SQL::Translator::Producer::PostgreSQL::create_constraint($pk_constraint);

if ( $name ) {
is($pk_constraint_def_ref->[0], "CONSTRAINT $name PRIMARY KEY (myfield) DEFERRABLE", 'Create Primary Key Constraint works');
is($pk_constraint_def_ref->[0], "CONSTRAINT $name PRIMARY KEY (myfield)", 'Create Primary Key Constraint works');

# ToDo: may we should check if the constraint name was valid, or if next
# unused_name created has choosen a different one
my $alter_pk_constraint = SQL::Translator::Producer::PostgreSQL::alter_drop_constraint($pk_constraint);
is($alter_pk_constraint, "ALTER TABLE mytable DROP CONSTRAINT $name", 'Alter drop Primary Key constraint works');
}
else {
is($pk_constraint_def_ref->[0], 'PRIMARY KEY (myfield) DEFERRABLE', 'Create un-named Primary Key Constraint works');
is($pk_constraint_def_ref->[0], 'PRIMARY KEY (myfield)', 'Create un-named Primary Key Constraint works');

my $alter_pk_constraint = SQL::Translator::Producer::PostgreSQL::alter_drop_constraint($pk_constraint);
is($alter_pk_constraint, 'ALTER TABLE mytable DROP CONSTRAINT mytable_pkey', 'Alter drop un-named Foreign Key constraint works');
Expand Down Expand Up @@ -627,25 +627,25 @@ is($view2_sql1, $view2_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL 2');
{
my $constr = $table->add_constraint(name => 'constr', type => UNIQUE, fields => ['foo']);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr);
is($def->[0], 'CONSTRAINT constr UNIQUE (foo) DEFERRABLE', 'constraint created');
is($def->[0], 'CONSTRAINT constr UNIQUE (foo)', 'constraint created');
($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr, $quote);
is($def->[0], 'CONSTRAINT "constr" UNIQUE ("foo") DEFERRABLE', 'constraint created w/ quotes');
is($def->[0], 'CONSTRAINT "constr" UNIQUE ("foo")', 'constraint created w/ quotes');
}

{
my $constr = $table->add_constraint(name => 'constr', type => UNIQUE, fields => ['lower(foo)']);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr);
is($def->[0], 'CONSTRAINT constr UNIQUE (lower(foo)) DEFERRABLE', 'constraint created');
is($def->[0], 'CONSTRAINT constr UNIQUE (lower(foo))', 'constraint created');
($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr, $quote);
is($def->[0], 'CONSTRAINT "constr" UNIQUE (lower(foo)) DEFERRABLE', 'constraint created w/ quotes');
is($def->[0], 'CONSTRAINT "constr" UNIQUE (lower(foo))', 'constraint created w/ quotes');
}

{
my $constr = $table->add_constraint(name => 'constr', type => UNIQUE, fields => ['bar', 'lower(foo)']);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr);
is($def->[0], 'CONSTRAINT constr UNIQUE (bar, lower(foo)) DEFERRABLE', 'constraint created');
is($def->[0], 'CONSTRAINT constr UNIQUE (bar, lower(foo))', 'constraint created');
($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr, $quote);
is($def->[0], 'CONSTRAINT "constr" UNIQUE ("bar", lower(foo)) DEFERRABLE', 'constraint created w/ quotes');
is($def->[0], 'CONSTRAINT "constr" UNIQUE ("bar", lower(foo))', 'constraint created w/ quotes');
}

{
Expand Down
24 changes: 12 additions & 12 deletions t/63-spacial-pgsql.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ is($field1_geocol, "INSERT INTO geometry_columns VALUES ('','myschema','my''tabl

my $field1_geocon = SQL::Translator::Producer::PostgreSQL::add_geometry_constraints($field1, $options);

is($field1_geocon, qq[ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_myfield" CHECK ((ST_NDims("myfield") = 2)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_myfield" CHECK ((ST_SRID("myfield") = -1)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_geotype_myfield" CHECK ((GeometryType("myfield") = 'POINT'::text OR "myfield" IS NULL)) DEFERRABLE],
is($field1_geocon, qq[ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_myfield" CHECK ((ST_NDims("myfield") = 2));
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_myfield" CHECK ((ST_SRID("myfield") = -1));
ALTER TABLE "my'table" 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',
Expand Down Expand Up @@ -82,19 +82,19 @@ my $alter_field2 = SQL::Translator::Producer::PostgreSQL::alter_field($field2,
is($alter_field2, qq[ALTER TABLE "my'table" ALTER COLUMN "myfield" DROP NOT NULL;
ALTER TABLE "my'table" ALTER COLUMN "myfield" TYPE geometry;
INSERT INTO geometry_columns VALUES ('','myschema','my''table','myfield','2','-1','POINT');
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_myfield" CHECK ((ST_NDims("myfield") = 2)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_myfield" CHECK ((ST_SRID("myfield") = -1)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_geotype_myfield" CHECK ((GeometryType("myfield") = 'POINT'::text OR "myfield" IS NULL)) DEFERRABLE],
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_myfield" CHECK ((ST_NDims("myfield") = 2));
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_myfield" CHECK ((ST_SRID("myfield") = -1));
ALTER TABLE "my'table" 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, $options);

is($add_field, qq[ALTER TABLE "my'table" ADD COLUMN "field3" geometry;
INSERT INTO geometry_columns VALUES ('','myschema','my''table','field3','2','-1','POINT');
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_field3" CHECK ((ST_NDims("field3") = 2)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_field3" CHECK ((ST_SRID("field3") = -1)) DEFERRABLE;
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_geotype_field3" CHECK ((GeometryType("field3") = 'POINT'::text OR "field3" IS NULL)) DEFERRABLE],
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_dims_field3" CHECK ((ST_NDims("field3") = 2));
ALTER TABLE "my'table" ADD CONSTRAINT "enforce_srid_field3" CHECK ((ST_SRID("field3") = -1));
ALTER TABLE "my'table" 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, $options);
Expand Down Expand Up @@ -125,9 +125,9 @@ is($create_table,qq[--
CREATE TABLE "my'table" (
"field3" geometry,
"field4" geography(POINT,-1),
CONSTRAINT "enforce_dims_field3" CHECK ((ST_NDims("field3") = 2)) DEFERRABLE,
CONSTRAINT "enforce_srid_field3" CHECK ((ST_SRID("field3") = -1)) DEFERRABLE,
CONSTRAINT "enforce_geotype_field3" CHECK ((GeometryType("field3") = 'POINT'::text OR "field3" IS NULL)) DEFERRABLE
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','my''table','field3','2','-1','POINT')],
'Create table with geometry works.');
Expand Down
6 changes: 3 additions & 3 deletions t/data/diff/pgsql/create1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ schema:
- person_id
reference_table: person
type: FOREIGN KEY
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- position
Expand Down Expand Up @@ -111,7 +111,7 @@ schema:
order: 4
person:
constraints:
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- person_id
Expand All @@ -123,7 +123,7 @@ schema:
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- age
Expand Down
8 changes: 4 additions & 4 deletions t/data/diff/pgsql/create2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ schema:
- person_id
reference_table: person
type: FOREIGN KEY
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- employee_id
Expand Down Expand Up @@ -96,7 +96,7 @@ schema:
order: 4
person:
constraints:
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- person_id
Expand All @@ -108,7 +108,7 @@ schema:
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- person_id
Expand All @@ -120,7 +120,7 @@ schema:
reference_fields: []
reference_table: ''
type: UNIQUE
- deferrable: 1
- deferrable: 0
expression: ''
fields:
- age
Expand Down
8 changes: 4 additions & 4 deletions t/data/template/testresult_basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Constraints
match_type:
reference_fields:
reference_table:
deferrable: 1
deferrable: 0
on_delete:
on_update:
options:
Expand All @@ -165,7 +165,7 @@ Constraints
match_type:
reference_fields:
reference_table:
deferrable: 1
deferrable: 0
on_delete:
on_update:
options:
Expand All @@ -178,7 +178,7 @@ Constraints
match_type:
reference_fields:
reference_table:
deferrable: 1
deferrable: 0
on_delete:
on_update:
options:
Expand Down Expand Up @@ -240,7 +240,7 @@ Constraints
match_type:
reference_fields:
reference_table:
deferrable: 1
deferrable: 0
on_delete:
on_update:
options:
Expand Down
8 changes: 4 additions & 4 deletions t/data/xml/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ Created on Fri Aug 15 15:08:18 2003

<constraints>
<constraint name="" type="PRIMARY KEY" fields="id"
reference_table="" options="" deferrable="1" match_type=""
reference_table="" options="" deferrable="0" match_type=""
expression="" on_update="" on_delete="">
<extra foo="bar" hello="world" bar="baz" />
</constraint>
<constraint name="emailuniqueindex" type="UNIQUE" fields="email" />
<constraint name="very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" type="UNIQUE" fields="title" />
<constraint name="emailuniqueindex" type="UNIQUE" fields="email" deferrable="0" />
<constraint name="very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" type="UNIQUE" fields="title" deferrable="0" />
<constraint name="" type="FOREIGN KEY" fields="another_id"
reference_table="Another" options="" deferrable="1" match_type=""
expression="" on_update="" on_delete="">
Expand All @@ -81,7 +81,7 @@ Created on Fri Aug 15 15:08:18 2003

<constraints>
<constraint name="" type="PRIMARY KEY" fields="id"
reference_table="" options="" deferrable="1" match_type=""
reference_table="" options="" deferrable="0" match_type=""
expression="" on_update="" on_delete="">
</constraint>
</constraints>
Expand Down

0 comments on commit c0eeacf

Please sign in to comment.