max13 / laravel-sqfix
Laravel package fixing SQLite Schema grammar
Requires
- php: ^7.3|^8.0
- illuminate/contracts: ^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0
- phpunit/phpunit: ^9.3
README
SQLite
has many quirks, some of them are bugs and stayed like this because of legacy code, bugs that became features, etc… See the complete list on their website:
ROWID
s: Every table (except explicitely createdWITHOUT ROWID
) have a 64-bit signed integer column namedrowid
. This column has the same attributes expected for aPRIMARY KEY
(starts at1
, is anINTEGER
, isUNIQUE
across the table, and is usually incremented by1
on every insert), and can reuse (in certain condition) previously deletedrowid
s. Only the exact type (case insensitive)INTEGER PRIMARY KEY
will make a column an alias ofrowid
. Which is recommended in most cases.AUTOINCREMENT
: When this keyword is used, it will use a different algorithm forrowid
, briefly, anAUTOINCREMENT
will makeSQLite
create an table used to track the increments (sqlite_sequence
),rowid
s are guaranteed to be increasing and never reused. The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed.
This package replaces the default optimized behavior advised by SQLite
and will have no effect on other drivers. Laravel
’s ids are automatically created as aliases of rowid
, and the ->trueSyntax()
modifier will use the "unfixed" SQL grammar.
Installation
You can install the package via composer:
composer require max13/laravel-sqfix
That’s it!
Usage
Schema::create('jobs', function (Blueprint $table) { $table->bigIncrements('id'); // … });
The normal behavior of Laravel
is to define the table jobs
with the following statement:
create table "jobs" ("id" integer not null primary key autoincrement)
Which will both create a column named id
distinct from rowid
with the same properties. Double the work.
This package is making Laravel
produce the following table:
create table "jobs" ("id" integer primary key)
Optimisation max.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.