diff --git a/AUTHORS b/AUTHORS index f01fa19b4..e05e379bc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -27,6 +27,7 @@ The following people have contributed to the SQLFairy project: - Geoff Cant - Gudmundur A. Thorisson - Guillermo Roditi +- Ivan Baidakou (basiliscos) - Jaime Soriano Pastor - Jason Williams - Johan Viklund diff --git a/lib/SQL/Translator/Generator/DDL/SQLite.pm b/lib/SQL/Translator/Generator/DDL/SQLite.pm index 0f55fd992..4c34b23db 100644 --- a/lib/SQL/Translator/Generator/DDL/SQLite.pm +++ b/lib/SQL/Translator/Generator/DDL/SQLite.pm @@ -75,10 +75,22 @@ sub _ipk { ( $field->data_type =~ /^number?$/i && $field->size !~ /,/ ) ) } +sub field_autoinc { + my ($self, $field) = @_; + my $auto_increment_method = $field->extra->{auto_increment_method}; + # use 'old' backward-compatible behaviour, i.e. use + # monotonic autoincrement only if it is specified in extra + my $force_autoinc = $field->is_auto_increment + && $self->_ipk($field) + && defined($auto_increment_method) + && $auto_increment_method eq 'sequence' + ; + return ( $force_autoinc ? 'AUTOINCREMENT' : () ) +} + sub field { my ($self, $field) = @_; - return join ' ', $self->field_comments($field), $self->field_name($field), @@ -86,6 +98,7 @@ sub field { ? ( 'INTEGER PRIMARY KEY' ) : ( $self->field_type($field) ) ), + $self->field_autoinc($field), $self->field_nullable($field), $self->field_default($field, { NULL => 1, diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index 66bb8bb4c..08bc6a45c 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -164,6 +164,25 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0; is_deeply($result, $expected, 'correctly unquoted excempted DEFAULTs'); } +{ + my $table = SQL::Translator::Schema::Table->new( + name => 'some_table', + ); + $table->add_field( + name => 'id', + data_type => 'integer', + is_auto_increment => 1, + is_nullable => 0, + extra => { + auto_increment_method => 'sequence', + }, + ); + $table->primary_key('id'); + my $expected = [ qq]; + my $result = [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })]; + is_deeply($result, $expected, 'correctly built monotonicly autoincremened PK'); +} + { my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] );