- André Walker <andre@andrewalker.net>
- Andreas 'ac0v' Specht <ac0v@sys-network.de>
- Andrew Moore <amoore@cpan.org>
+- Andrew Gregory <andrew.gregory.8@gmail.com>
- Andrew Pam <andrew.pam@strategicdata.com.au>
- Arthur Axel "fREW" Schmidt <frioux@gmail.com>
- Ben Faga <faga@cshl.edu>
* Fix erroneous PostgreSQL floating point type translations (RT#99725)
* Remove executable bit from Parser/JSON.pm (RT#100532)
* Update the Free Software Foundation's address (RT#100531)
+ * Provide default index names for SQLite (GH#45)
0.11020 2014-09-02
#
# Indices
#
- my $idx_name_default = 'A';
for my $index ( $table->get_indices ) {
push @index_defs, create_index($index);
}
#
# Constraints
#
- my $c_name_default = 'A';
for my $c ( $table->get_constraints ) {
if ($c->type eq "FOREIGN KEY") {
push @field_defs, create_foreignkey($c);
{
my ($index, $options) = @_;
- my $name = $index->name;
- $name = mk_name($name);
+ (my $index_table_name = $index->table->name) =~ s/^.+?\.//; # table name may not specify schema
+ my $name = mk_name($index->name || "${index_table_name}_idx");
my $type = $index->type eq 'UNIQUE' ? "UNIQUE " : '';
# strip any field size qualifiers as SQLite doesn't like these
my @fields = map { s/\(\d+\)$//; _generator()->quote($_) } $index->fields;
- (my $index_table_name = $index->table->name) =~ s/^.+?\.//; # table name may not specify schema
$index_table_name = _generator()->quote($index_table_name);
warn "removing schema name from '" . $index->table->name . "' to make '$index_table_name'\n" if $WARN;
my $index_def =
{
my ($c, $options) = @_;
- my $name = $c->name;
- $name = mk_name($name);
- my @fields = map _generator()->quote($_), $c->fields;
(my $index_table_name = $c->table->name) =~ s/^.+?\.//; # table name may not specify schema
+ my $name = mk_name($c->name || "${index_table_name}_idx");
+ my @fields = map _generator()->quote($_), $c->fields;
$index_table_name = _generator()->quote($index_table_name);
warn "removing schema name from '" . $c->table->name . "' to make '$index_table_name'\n" if $WARN;
is_deeply($result, $expected, 'correctly unquoted excempted DEFAULTs');
}
+{
+ my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] );
+
+ {
+ my $index = $table->add_index(name => 'myindex', fields => ['foo']);
+ my ($def) = SQL::Translator::Producer::SQLite::create_index($index);
+ is($def, 'CREATE INDEX "myindex" ON "foobar" ("foo")', 'index created');
+ }
+
+ {
+ my $index = $table->add_index(fields => ['foo']);
+ my ($def) = SQL::Translator::Producer::SQLite::create_index($index);
+ is($def, 'CREATE INDEX "foobar_idx" ON "foobar" ("foo")', 'index created');
+ }
+
+ {
+ my $constr = $table->add_constraint(name => 'constr', fields => ['foo']);
+ my ($def) = SQL::Translator::Producer::SQLite::create_constraint($constr);
+ is($def, 'CREATE UNIQUE INDEX "constr" ON "foobar" ("foo")', 'constraint created');
+ }
+
+ {
+ my $constr = $table->add_constraint(fields => ['foo']);
+ my ($def) = SQL::Translator::Producer::SQLite::create_constraint($constr);
+ is($def, 'CREATE UNIQUE INDEX "foobar_idx02" ON "foobar" ("foo")', 'constraint created');
+ }
+}
+
done_testing;