framework
framework copied to clipboard
[11.x] SQLite: Add support for strict tables
This pull request adds support for strict tables in SQLite.
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->strict(); // This makes the table "STRICT".
});
I think this is a worthy addition to the framework, but I'm not entirely sure I've gone the right way about doing it.
a) It feels weird having a method specific to this one SQLite feature on the Blueprint
class.
b) Should this be something that you call inside of the Schema::create()
callback?
I considered adding a specific createStrict()
method, but that doesn't feel like a "Laravel-esque" thing to do?
I also thought about making Schema::create(...)->strict()
, but that would be a bit of a refactor since the Schema::create()
method returns void
atm.
I'm not sure. Some opinions and thoughts would be much appreciated.
@hafezdivandari r.e. the column datatypes – creating a STRICT
table in SQLite actually prevents you from using invalid column types.
So if you try to use DATETIME
, it will throw an error because that's not a real SQLite column type. Regular SQLite would try to convert DATETIME
into a valid "affinity" (as they call it) and allow you to store basically anything inside of it.
@ryangjchandler I mean most of the current types are considered invalid, even the query on your added example test will throw an exception! If we want to implement strict mode, we should use strict types only, please check:
https://github.com/laravel/framework/blob/d4ce2a5f6c11d5307df52cd5ce1c79f948cec3d6/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L597-L959
Thanks for your pull request to Laravel!
Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.
If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!
If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.