Make Migrations compatible with old COM APPS
This commit is contained in:
parent
a6bc3f8f06
commit
76556e9f2e
16 changed files with 201 additions and 4 deletions
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +15,12 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('migrations')->truncate();
|
||||
Log::debug('truncate migrations');
|
||||
if (Schema::hasTable('app_users')) {
|
||||
Log::debug('already has app_users');
|
||||
return;
|
||||
}
|
||||
Schema::create('app_users', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('email')->unique();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('contacts')) {
|
||||
Log::debug('already has contacts');
|
||||
return;
|
||||
}
|
||||
Schema::create('contacts', function (Blueprint $table) {
|
||||
$table->string('id', 50)->primary();
|
||||
$table->string('email');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('directories')) {
|
||||
Log::debug('already has directories');
|
||||
return;
|
||||
}
|
||||
Schema::create('directories', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('documents')) {
|
||||
Log::debug('already has documents');
|
||||
return;
|
||||
}
|
||||
Schema::create('documents', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->char('uuid', 36)->nullable();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('settings')) {
|
||||
Log::debug('already has settings');
|
||||
return;
|
||||
}
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('key')->unique();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('users')) {
|
||||
Log::debug('already has users');
|
||||
return;
|
||||
}
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name', 100)->default('0');
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->hasForeign('contacts', 'user_id', 'app_users', 'id')) {
|
||||
Log::debug('already has foreign user_id');
|
||||
return;
|
||||
}
|
||||
Schema::table('contacts', function (Blueprint $table) {
|
||||
$table->foreign(['user_id'])->references(['id'])->on('app_users');
|
||||
});
|
||||
|
|
@ -29,4 +34,39 @@ return new class extends Migration
|
|||
$table->dropForeign('contacts_user_id_foreign');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a foreign key exists
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param string $foreignTable
|
||||
* @param string $foreignColumn
|
||||
* @return boolean
|
||||
*/
|
||||
private function hasForeign(
|
||||
string $table,
|
||||
string $column,
|
||||
string $foreignTable,
|
||||
string $foreignColumn
|
||||
) {
|
||||
|
||||
// * Get the foreign keys for the table
|
||||
$fkColumns = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->listTableForeignKeys($table);
|
||||
|
||||
// * Check if the foreign key exists
|
||||
foreach ($fkColumns as $fkColumn) {
|
||||
if (
|
||||
$fkColumn->getLocalColumns()[0] == $column &&
|
||||
$fkColumn->getForeignColumns()[0] == $foreignColumn &&
|
||||
$fkColumn->getForeignTableName() == $foreignTable
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->hasForeign('directories', 'parent', 'directories', 'id')) {
|
||||
Log::debug('already has foreign parent');
|
||||
return;
|
||||
}
|
||||
Schema::table('directories', function (Blueprint $table) {
|
||||
$table->foreign(['parent'])->references(['id'])->on('directories');
|
||||
});
|
||||
|
|
@ -29,4 +34,39 @@ return new class extends Migration
|
|||
$table->dropForeign('directories_parent_foreign');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a foreign key exists
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param string $foreignTable
|
||||
* @param string $foreignColumn
|
||||
* @return boolean
|
||||
*/
|
||||
private function hasForeign(
|
||||
string $table,
|
||||
string $column,
|
||||
string $foreignTable,
|
||||
string $foreignColumn
|
||||
) {
|
||||
|
||||
// * Get the foreign keys for the table
|
||||
$fkColumns = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->listTableForeignKeys($table);
|
||||
|
||||
// * Check if the foreign key exists
|
||||
foreach ($fkColumns as $fkColumn) {
|
||||
if (
|
||||
$fkColumn->getLocalColumns()[0] == $column &&
|
||||
$fkColumn->getForeignColumns()[0] == $foreignColumn &&
|
||||
$fkColumn->getForeignTableName() == $foreignTable
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if ($this->hasForeign('documents', 'directory', 'directories', 'id')) {
|
||||
Log::debug('already has foreign directory');
|
||||
return;
|
||||
}
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->foreign(['directory'])->references(['id'])->on('directories');
|
||||
});
|
||||
|
|
@ -29,4 +34,39 @@ return new class extends Migration
|
|||
$table->dropForeign('documents_directory_foreign');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a foreign key exists
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @param string $foreignTable
|
||||
* @param string $foreignColumn
|
||||
* @return boolean
|
||||
*/
|
||||
private function hasForeign(
|
||||
string $table,
|
||||
string $column,
|
||||
string $foreignTable,
|
||||
string $foreignColumn
|
||||
) {
|
||||
|
||||
// * Get the foreign keys for the table
|
||||
$fkColumns = Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->listTableForeignKeys($table);
|
||||
|
||||
// * Check if the foreign key exists
|
||||
foreach ($fkColumns as $fkColumn) {
|
||||
if (
|
||||
$fkColumn->getLocalColumns()[0] == $column &&
|
||||
$fkColumn->getForeignColumns()[0] == $foreignColumn &&
|
||||
$fkColumn->getForeignTableName() == $foreignTable
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateJobsTable extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ class CreateJobsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('jobs')) {
|
||||
Log::debug('already has jobs');
|
||||
return;
|
||||
}
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('queue')->index();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFailedJobsTable extends Migration
|
||||
|
|
@ -13,6 +14,10 @@ class CreateFailedJobsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasTable('failed_jobs')) {
|
||||
Log::debug('already has failed_jobs');
|
||||
return;
|
||||
}
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('uuid')->unique();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Models\Directory;
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateAppUsersTable extends Migration
|
||||
|
|
@ -32,8 +33,17 @@ class UpdateAppUsersTable extends Migration
|
|||
$appUsersOld = AppUser::get();
|
||||
|
||||
// * OTHERS
|
||||
try {
|
||||
Schema::table('app_users', function (Blueprint $table) {
|
||||
$table->dropUnique('email');
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
Log::debug('Failed to drop email unique');
|
||||
Schema::table('app_users', function (Blueprint $table) {
|
||||
$table->dropUnique(['email']);
|
||||
});
|
||||
}
|
||||
Schema::table('app_users', function (Blueprint $table) {
|
||||
$table->dropUnique('email');
|
||||
$table->unique(['email']);
|
||||
$table->renameColumn('surname', 'lastname');
|
||||
$table->renameColumn('activated', 'status');
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ class UpdateDocumentTable extends Migration
|
|||
DB::statement('ALTER TABLE `documents` CHANGE `updated_at` `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
|
||||
|
||||
self::updateData();
|
||||
Schema::disableForeignKeyConstraints();
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->bigInteger('parent')->unsigned()->change();
|
||||
$table->renameColumn('directory', 'directory_id');
|
||||
$table->dropColumn('parent');
|
||||
$table->unsignedBigInteger('document_id')->index()->nullable()->after('directory');
|
||||
$table->foreign(['document_id'])->references(['id'])->on('documents')->constrained();
|
||||
$table->integer('order')->after('published')->comment('Ordonnance des documents.');
|
||||
|
|
@ -48,6 +48,7 @@ class UpdateDocumentTable extends Migration
|
|||
$table->renameColumn('published', 'status');
|
||||
$table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change();
|
||||
});
|
||||
Schema::enableForeignKeyConstraints();
|
||||
foreach ($this->documentsNew as $key => $documentNew) {
|
||||
$documentNew->document_id =
|
||||
($this->documentsOld[$key]->parent !== null) ? intval($this->documentsOld[$key]->parent) : null;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use App\Models\Setting;
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class UpdateSettingsTable extends Migration
|
||||
|
|
@ -19,8 +20,17 @@ class UpdateSettingsTable extends Migration
|
|||
//phpcs:ignore Generic.Files.LineLength.TooLong
|
||||
DB::statement('ALTER TABLE `settings` CHANGE `updated_at` `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
|
||||
|
||||
try {
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropUnique('data_key_unique');
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
Log::debug('Failed to drop data_key_unique');
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropUnique('settings_key_unique');
|
||||
});
|
||||
}
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->dropUnique('data_key_unique');
|
||||
$table->unique(['key']);
|
||||
$table->text('value')->nullable()->default(null)->change();
|
||||
$table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddMissingRememberTokenToUsers extends Migration
|
||||
|
|
@ -13,6 +15,17 @@ class AddMissingRememberTokenToUsers extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
$columns = collect(
|
||||
Schema::getConnection()
|
||||
->getDoctrineSchemaManager()
|
||||
->listTableColumns('users')
|
||||
)->mapWithKeys(function (Column $column) {
|
||||
return [$column->getName() => $column];
|
||||
});
|
||||
if ($columns->has('remember_token')) {
|
||||
Log::debug('already has remember_token column');
|
||||
return;
|
||||
}
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->rememberToken()->after('password');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class UpgradeContactsTable extends Migration
|
|||
$table->string('firstname')->nullable()->comment('Prénom du contact, Form Status: Locked')->change();
|
||||
$table->string('phone')->nullable()->comment('Téléphone du contact, Form Status: Locked')->change();
|
||||
$table->text('notes')->nullable()->comment('Notes sur un contact')->change();
|
||||
$table->text('visits')->default('[]')
|
||||
$table->json('visits')->default('[]')
|
||||
->comment('Visite d\'un contact, Array<{title:string,note:string}>')->change();
|
||||
|
||||
$table->dropColumn('type');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue