Changes for SQL::Translator
* Add support for monotonically increasing SQLite autoincs (GH#47)
+ * Add support for CHECK constraint in SQLite producer (GH#57)
* Fix forgotten quoting in the MySQL DROP TABLE diff producer (GH#50)
* Improve add_trigger consistency between producers (GH#48)
* Declare dependencies in deterministic order (RT#102859)
if ($c->type eq "FOREIGN KEY") {
push @field_defs, create_foreignkey($c);
}
+ elsif ($c->type eq "CHECK") {
+ push @field_defs, create_check_constraint($c);
+ }
next unless $c->type eq UNIQUE;
push @constraint_defs, create_constraint($c);
}
return (@create, $create_table, @index_defs, @constraint_defs );
}
+sub create_check_constraint {
+ my $c = shift;
+ my $check = '';
+ $check .= 'CONSTRAINT ' . _generator->quote( $c->name ) . ' ' if $c->name;
+ $check .= 'CHECK(' . $c->expression . ')';
+ return $check;
+}
+
sub create_foreignkey {
my $c = shift;
}
}
+{
+ my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] );
+ my $constr = $table->add_constraint(name => 'constr', expression => "foo != 'baz'");
+ my ($def) = SQL::Translator::Producer::SQLite::create_check_constraint($constr);
+
+ is($def, q{CONSTRAINT "constr" CHECK(foo != 'baz')}, 'check constraint created');
+}
+
done_testing;