Fix sqlite 'not null error' another way

This commit is contained in:
Bubka 2022-04-01 16:57:18 +02:00
parent 109940c002
commit e749e3d98e

View File

@ -16,23 +16,24 @@ class SplitTwofaccountsUriInMultipleColumns extends Migration
*/
public function up()
{
$driver = Schema::connection($this->getConnection())->getConnection()->getDriverName();
Schema::table('twofaccounts', function (Blueprint $table) use ($driver) {
if ('sqlite' === $driver) {
$table->string('otp_type', 10)->default('');
$table->text('secret')->default('');
$table->string('algorithm', 20)->default('');
$table->unsignedTinyInteger('digits')->default(6);
} else {
$table->string('otp_type', 10);
$table->text('secret');
$table->string('algorithm', 20);
$table->unsignedTinyInteger('digits');
}
// as SQLITE disallow to add a not nullable column without default
// value when altering a table we add all columns as nullable and
// change them right after to not nullable column
Schema::table('twofaccounts', function (Blueprint $table) {
$table->string('otp_type', 10)->nullable();
$table->text('secret')->nullable();
$table->string('algorithm', 20)->nullable();
$table->unsignedTinyInteger('digits')->nullable();
$table->unsignedInteger('period')->nullable();
$table->unsignedBigInteger('counter')->nullable();
});
Schema::table('twofaccounts', function (Blueprint $table){
$table->string('otp_type')->nullable(false)->change();
$table->string('secret')->nullable(false)->change();
$table->string('algorithm')->nullable(false)->change();
$table->string('digits')->nullable(false)->change();
});
Schema::table('twofaccounts', function (Blueprint $table) {
$table->renameColumn('uri', 'legacy_uri');