From d393b39d982ca8444d893f3e2b9631addd450aec Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 26 May 2025 11:35:18 +0200 Subject: [PATCH] fix: :card_file_box: update database relations --- database/factories/AppUserFactory.php | 2 +- database/factories/ContactFactory.php | 53 +------ ...23_03_14_150900_create_app_users_table.php | 12 +- ...023_03_14_150900_create_contacts_table.php | 9 +- ..._03_14_150900_create_directories_table.php | 9 +- ...23_03_14_150900_create_documents_table.php | 9 +- ...023_03_14_150900_create_settings_table.php | 11 +- .../2023_03_14_150900_create_users_table.php | 42 +----- ...901_add_foreign_keys_to_contacts_table.php | 44 +----- ..._add_foreign_keys_to_directories_table.php | 44 +----- ...01_add_foreign_keys_to_documents_table.php | 44 +----- .../2023_03_14_152343_create_jobs_table.php | 9 +- ..._03_14_152416_create_failed_jobs_table.php | 9 +- ...23_03_20_105223_update_directory_table.php | 7 +- ...03_20_110635_add_pivot_directory_table.php | 4 +- ...23_03_24_171035_update_app_users_table.php | 19 +-- .../2023_03_27_112237_update_users_table.php | 9 +- ...023_04_05_093932_update_document_table.php | 5 +- ...023_04_18_144609_update_settings_table.php | 7 +- .../2023_04_18_153753_create_tags_table.php | 4 +- ...23_04_18_153812_create_taggables_table.php | 4 +- ...023_04_18_172743_update_contacts_table.php | 7 +- ..._07_17_154420_create_formularies_table.php | 4 +- ...2023_08_22_093330_seed_mandatory_forms.php | 27 ---- ...54_add_missing_remember_token_to_users.php | 17 +-- ...23_08_25_093125_upgrade_contacts_table.php | 74 +++++----- ...5_19_141630_alter_type_documents_table.php | 62 -------- ...0_144302_update_tables_for_multitenant.php | 62 +++++++- ..._05_21_131902_create_tenant_user_table.php | 2 +- .../2025_05_26_091952_alter_relations.php | 99 +++++++++++++ database/seeders/AppUserSeeder.php | 9 +- database/seeders/ContactSeeder.php | 2 +- database/seeders/DatabaseSeeder.php | 4 +- database/seeders/DirectorySeeder.php | 12 +- database/seeders/FormularySeeder.php | 5 +- database/seeders/MandatoryFormularySeeder.php | 108 -------------- database/seeders/MigrationSeeder.php | 2 +- database/seeders/SettingSeeder.php | 137 ------------------ database/seeders/TagSeeder.php | 9 +- 39 files changed, 267 insertions(+), 731 deletions(-) delete mode 100644 database/migrations/2023_08_22_093330_seed_mandatory_forms.php delete mode 100644 database/migrations/2025_05_19_141630_alter_type_documents_table.php create mode 100644 database/migrations/2025_05_26_091952_alter_relations.php delete mode 100644 database/seeders/MandatoryFormularySeeder.php delete mode 100644 database/seeders/SettingSeeder.php diff --git a/database/factories/AppUserFactory.php b/database/factories/AppUserFactory.php index c7d728d..138c319 100644 --- a/database/factories/AppUserFactory.php +++ b/database/factories/AppUserFactory.php @@ -32,7 +32,7 @@ class AppUserFactory extends Factory 'email' => $this->faker->unique()->safeEmail(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'status' => $this->faker->boolean(75), - 'role' => collect(AppUserRolesEnum::toArray())->random(), + 'role' => collect(AppUserRolesEnum::cases())->random(), 'tenant_id' => Tenant::query()->first('id'), ]; } diff --git a/database/factories/ContactFactory.php b/database/factories/ContactFactory.php index df75bc7..b75cb3c 100644 --- a/database/factories/ContactFactory.php +++ b/database/factories/ContactFactory.php @@ -2,11 +2,7 @@ namespace Database\Factories; -use App\Enums\Formularies\InputTypeEnum; -use App\Lib\Inputs\Definition\InputData; use App\Models\Contact; -use App\Models\Formulary; -use App\Models\Tenant; use Illuminate\Database\Eloquent\Factories\Factory; class ContactFactory extends Factory @@ -25,13 +21,11 @@ class ContactFactory extends Factory */ public function definition(): array { - /** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Formulary> */ - $formularies = $this->factoryForModel(Formulary::class)->count($this->faker->numberBetween(3, 9))->make(); return [ 'email' => $this->faker->unique()->email(), - 'lastname' => $this->faker->boolean() ? $this->faker->unique()->lastName() : '', - 'firstname' => $this->faker->boolean() ? $this->faker->unique()->firstName() : '', - 'phone' => $this->faker->boolean() ? $this->faker->unique()->phoneNumber() : '', + 'lastname' => $this->faker->boolean() ? $this->faker->unique()->lastName() : null, + 'firstname' => $this->faker->boolean() ? $this->faker->unique()->firstName() : null, + 'phone' => $this->faker->boolean() ? $this->faker->unique()->phoneNumber() : null, 'notes' => $this->faker->boolean() ? $this->faker->text() : null, 'visits' => \collect(range(0, $this->faker->numberBetween(1, 5)))->mapWithKeys(function () { return [ @@ -39,46 +33,7 @@ class ContactFactory extends Factory 'note' => $this->faker->text() ]; }), - 'data' => $formularies->map(function (Formulary $formulary) { - $inputClass = $formulary->type->inputTypes(); - $details = \collect($formulary->details)->map(function (array $details) { - return $details['fr']; - }); - - $data = $this->faker->words(3, true); - - if ($formulary->type->equals(InputTypeEnum::email)) { - $data = $this->faker->unique()->email(); - } - if ($formulary->type->equals(InputTypeEnum::phone)) { - $data = $this->faker->phoneNumber(); - } - if ( - in_array($formulary->type->value, [ - InputTypeEnum::selectMultiple->value(), - InputTypeEnum::checkbox->value() - ]) - ) { - $data = \collect($details->random(min($details->count(), 2)))->all(); - } - if ( - in_array($formulary->type->value(), [ - InputTypeEnum::select->value(), - InputTypeEnum::radio->value() - ]) - ) { - $data = $details->random(); - } - - return $inputClass::from(InputData::make( - $formulary->placeholder['fr'], - $formulary->slug, - $formulary->type, - $data, - $formulary->required - ), $formulary->required); - }), - 'tenant_id' => Tenant::query()->first('id'), + 'data' => null, ]; } } diff --git a/database/migrations/2023_03_14_150900_create_app_users_table.php b/database/migrations/2023_03_14_150900_create_app_users_table.php index abdcc68..98db63f 100644 --- a/database/migrations/2023_03_14_150900_create_app_users_table.php +++ b/database/migrations/2023_03_14_150900_create_app_users_table.php @@ -2,8 +2,6 @@ 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,14 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - 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(); @@ -39,7 +31,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('app_users'); } diff --git a/database/migrations/2023_03_14_150900_create_contacts_table.php b/database/migrations/2023_03_14_150900_create_contacts_table.php index cc2e6c0..996272c 100644 --- a/database/migrations/2023_03_14_150900_create_contacts_table.php +++ b/database/migrations/2023_03_14_150900_create_contacts_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - if (Schema::hasTable('contacts')) { - Log::debug('already has contacts'); - return; - } Schema::create('contacts', function (Blueprint $table) { $table->string('id', 50)->primary(); $table->string('email'); @@ -44,7 +39,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('contacts'); } diff --git a/database/migrations/2023_03_14_150900_create_directories_table.php b/database/migrations/2023_03_14_150900_create_directories_table.php index 9915227..c0149e3 100644 --- a/database/migrations/2023_03_14_150900_create_directories_table.php +++ b/database/migrations/2023_03_14_150900_create_directories_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - if (Schema::hasTable('directories')) { - Log::debug('already has directories'); - return; - } Schema::create('directories', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); @@ -33,7 +28,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('directories'); } diff --git a/database/migrations/2023_03_14_150900_create_documents_table.php b/database/migrations/2023_03_14_150900_create_documents_table.php index 62161eb..bfca110 100644 --- a/database/migrations/2023_03_14_150900_create_documents_table.php +++ b/database/migrations/2023_03_14_150900_create_documents_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - if (Schema::hasTable('documents')) { - Log::debug('already has documents'); - return; - } Schema::create('documents', function (Blueprint $table) { $table->bigIncrements('id'); $table->char('uuid', 36)->nullable(); @@ -37,7 +32,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('documents'); } diff --git a/database/migrations/2023_03_14_150900_create_settings_table.php b/database/migrations/2023_03_14_150900_create_settings_table.php index 8fe1a7a..5ddf29c 100644 --- a/database/migrations/2023_03_14_150900_create_settings_table.php +++ b/database/migrations/2023_03_14_150900_create_settings_table.php @@ -2,7 +2,6 @@ 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 @@ -12,16 +11,12 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - if (Schema::hasTable('settings')) { - Log::debug('already has settings'); - return; - } Schema::create('settings', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('key')->unique(); - $table->text('value')->default(''); + $table->text('value'); $table->integer('type'); $table->timestamps(); }); @@ -32,7 +27,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('settings'); } diff --git a/database/migrations/2023_03_14_150900_create_users_table.php b/database/migrations/2023_03_14_150900_create_users_table.php index 517bd69..a897319 100644 --- a/database/migrations/2023_03_14_150900_create_users_table.php +++ b/database/migrations/2023_03_14_150900_create_users_table.php @@ -1,12 +1,7 @@ getDoctrineSchemaManager() - ->listTableColumns('users') - )->mapWithKeys(function (Column $column) { - return [$column->getName() => $column]; - }); - if (Schema::hasTable('users')) { - Log::debug('already has users'); - - if ($columns->has('role')) { - Log::debug('already has role column'); - return; - } - Log::debug('adding role'); - if (!Type::hasType('integer')) { - Type::addType('integer', SmallIntType::class); - } - Schema::table('users', function (Blueprint $table) { - $table->smallInteger('role')->nullable()->after('remember_token'); - }); - DB::table('users')->get()->each(function (object $user) { - DB::table('users')->where('id', $user->id) - ->update(['role' => in_array($user->email, [ - 'informatique.internet@ldc.fr', - 'equipe.web@ldc.fr' - ]) ? 1 : 2]); - }); - Schema::table('users', function (Blueprint $table) { - $table->smallInteger('role')->change(); - }); - return; - } //end if Schema::create('users', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name', 100)->default('0'); @@ -67,7 +29,7 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('users'); } diff --git a/database/migrations/2023_03_14_150901_add_foreign_keys_to_contacts_table.php b/database/migrations/2023_03_14_150901_add_foreign_keys_to_contacts_table.php index 30d8012..288f78f 100644 --- a/database/migrations/2023_03_14_150901_add_foreign_keys_to_contacts_table.php +++ b/database/migrations/2023_03_14_150901_add_foreign_keys_to_contacts_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - 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'); }); @@ -28,45 +23,10 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::table('contacts', function (Blueprint $table) { $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; - } }; diff --git a/database/migrations/2023_03_14_150901_add_foreign_keys_to_directories_table.php b/database/migrations/2023_03_14_150901_add_foreign_keys_to_directories_table.php index a9c399d..f70c6d9 100644 --- a/database/migrations/2023_03_14_150901_add_foreign_keys_to_directories_table.php +++ b/database/migrations/2023_03_14_150901_add_foreign_keys_to_directories_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - 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'); }); @@ -28,45 +23,10 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::table('directories', function (Blueprint $table) { $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; - } }; diff --git a/database/migrations/2023_03_14_150901_add_foreign_keys_to_documents_table.php b/database/migrations/2023_03_14_150901_add_foreign_keys_to_documents_table.php index dfaa2a9..f9f8167 100644 --- a/database/migrations/2023_03_14_150901_add_foreign_keys_to_documents_table.php +++ b/database/migrations/2023_03_14_150901_add_foreign_keys_to_documents_table.php @@ -2,7 +2,6 @@ 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 @@ -12,12 +11,8 @@ return new class extends Migration * * @return void */ - public function up() + public function up(): void { - 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'); }); @@ -28,45 +23,10 @@ return new class extends Migration * * @return void */ - public function down() + public function down(): void { Schema::table('documents', function (Blueprint $table) { $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; - } }; diff --git a/database/migrations/2023_03_14_152343_create_jobs_table.php b/database/migrations/2023_03_14_152343_create_jobs_table.php index de4b6a8..c631c90 100644 --- a/database/migrations/2023_03_14_152343_create_jobs_table.php +++ b/database/migrations/2023_03_14_152343_create_jobs_table.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; class CreateJobsTable extends Migration @@ -12,12 +11,8 @@ class CreateJobsTable extends Migration * * @return void */ - public function up() + public function up(): void { - if (Schema::hasTable('jobs')) { - Log::debug('already has jobs'); - return; - } Schema::create('jobs', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('queue')->index(); @@ -34,7 +29,7 @@ class CreateJobsTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('jobs'); } diff --git a/database/migrations/2023_03_14_152416_create_failed_jobs_table.php b/database/migrations/2023_03_14_152416_create_failed_jobs_table.php index 013f280..bd6f594 100644 --- a/database/migrations/2023_03_14_152416_create_failed_jobs_table.php +++ b/database/migrations/2023_03_14_152416_create_failed_jobs_table.php @@ -2,7 +2,6 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; class CreateFailedJobsTable extends Migration @@ -12,12 +11,8 @@ class CreateFailedJobsTable extends Migration * * @return void */ - public function up() + public function up(): void { - 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(); @@ -34,7 +29,7 @@ class CreateFailedJobsTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('failed_jobs'); } diff --git a/database/migrations/2023_03_20_105223_update_directory_table.php b/database/migrations/2023_03_20_105223_update_directory_table.php index 8add158..5bc3941 100644 --- a/database/migrations/2023_03_20_105223_update_directory_table.php +++ b/database/migrations/2023_03_20_105223_update_directory_table.php @@ -1,6 +1,7 @@ UPDATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong @@ -23,7 +24,7 @@ class UpdateDirectoryTable extends Migration $table->renameColumn('parent', 'directory_id'); $table->json('name')->change(); $table->boolean('is_system')->after('needAuthorization')->comment('Le dossier est-il administrable ?'); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); Directory::each(function (Directory $model) { @@ -39,7 +40,7 @@ class UpdateDirectoryTable extends Migration * * @return void */ - public function down() + public function down(): void { // * APP_USER->CREATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong diff --git a/database/migrations/2023_03_20_110635_add_pivot_directory_table.php b/database/migrations/2023_03_20_110635_add_pivot_directory_table.php index c3809f2..3572e01 100644 --- a/database/migrations/2023_03_20_110635_add_pivot_directory_table.php +++ b/database/migrations/2023_03_20_110635_add_pivot_directory_table.php @@ -11,7 +11,7 @@ class AddPivotDirectoryTable extends Migration * * @return void */ - public function up() + public function up(): void { Schema::create('directorables', function (Blueprint $table) { $table->foreignId('directory_id')->references('id')->on('directories'); @@ -25,7 +25,7 @@ class AddPivotDirectoryTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('directorables'); } diff --git a/database/migrations/2023_03_24_171035_update_app_users_table.php b/database/migrations/2023_03_24_171035_update_app_users_table.php index c102ae5..4434e66 100644 --- a/database/migrations/2023_03_24_171035_update_app_users_table.php +++ b/database/migrations/2023_03_24_171035_update_app_users_table.php @@ -3,10 +3,10 @@ use App\Enums\AppUserRolesEnum; use App\Models\AppUser; use App\Models\Directory; +use Carbon\Carbon; 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 @@ -16,7 +16,7 @@ class UpdateAppUsersTable extends Migration * * @return void */ - public function up() + public function up(): void { // * APP_USER->UPDATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong @@ -33,23 +33,12 @@ 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->unique(['email']); $table->renameColumn('surname', 'lastname'); $table->renameColumn('activated', 'status'); $table->integer('order')->after('role')->comment('Ordonnance des utilisateurs de l\'applications.'); $table->dropColumn('authorizedFolders'); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); AppUser::each(function (AppUser $appUserModel, int $key) use ($appUsersOld) { @@ -68,7 +57,7 @@ class UpdateAppUsersTable extends Migration * * @return void */ - public function down() + public function down(): void { // * APP_USER->ROLE DB::statement("ALTER TABLE app_users CHANGE COLUMN role role VARCHAR(50) NOT NULL"); diff --git a/database/migrations/2023_03_27_112237_update_users_table.php b/database/migrations/2023_03_27_112237_update_users_table.php index 016f71a..fe17a2f 100644 --- a/database/migrations/2023_03_27_112237_update_users_table.php +++ b/database/migrations/2023_03_27_112237_update_users_table.php @@ -1,6 +1,7 @@ renameColumn('name', 'firstname'); - $table->string('lastname')->nullable()->after('name'); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->string('lastname')->nullable()->after('firstname'); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); $usersNew = User::get(); @@ -39,7 +40,7 @@ class UpdateUsersTable extends Migration * * @return void */ - public function down() + public function down(): void { // * APP_USER->CREATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong diff --git a/database/migrations/2023_04_05_093932_update_document_table.php b/database/migrations/2023_04_05_093932_update_document_table.php index f7fa865..08ec031 100644 --- a/database/migrations/2023_04_05_093932_update_document_table.php +++ b/database/migrations/2023_04_05_093932_update_document_table.php @@ -2,6 +2,7 @@ use App\Enums\Documents\LangEnum; use App\Models\Document; +use Carbon\Carbon; use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\DB; @@ -42,13 +43,13 @@ class UpdateDocumentTable extends Migration Schema::table('documents', function (Blueprint $table) { $table->bigInteger('parent')->unsigned()->change(); $table->renameColumn('directory', 'directory_id'); - $table->unsignedBigInteger('document_id')->index()->nullable()->after('directory'); + $table->unsignedBigInteger('document_id')->index()->nullable()->after('directory_id'); $table->foreign(['document_id'])->references(['id'])->on('documents')->constrained(); $table->integer('order')->after('published')->comment('Ordonnance des documents.'); $table->string('type', 255)->change(); $table->integer('lang')->nullable()->change(); $table->renameColumn('published', 'status'); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); foreach ($this->documentsNew as $key => $documentNew) { $documentNew->document_id = diff --git a/database/migrations/2023_04_18_144609_update_settings_table.php b/database/migrations/2023_04_18_144609_update_settings_table.php index 7dfed7a..77b129c 100644 --- a/database/migrations/2023_04_18_144609_update_settings_table.php +++ b/database/migrations/2023_04_18_144609_update_settings_table.php @@ -1,6 +1,7 @@ UPDATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong @@ -33,7 +34,7 @@ class UpdateSettingsTable extends Migration Schema::table('settings', function (Blueprint $table) { $table->unique(['key']); $table->text('value')->nullable()->default(null)->change(); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); $settings = Setting::get(); @@ -60,7 +61,7 @@ class UpdateSettingsTable extends Migration * * @return void */ - public function down() + public function down(): void { // * APP_USER->CREATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong diff --git a/database/migrations/2023_04_18_153753_create_tags_table.php b/database/migrations/2023_04_18_153753_create_tags_table.php index d2d1a99..7199da9 100644 --- a/database/migrations/2023_04_18_153753_create_tags_table.php +++ b/database/migrations/2023_04_18_153753_create_tags_table.php @@ -11,7 +11,7 @@ class CreateTagsTable extends Migration * * @return void */ - public function up() + public function up(): void { Schema::create('tags', function (Blueprint $table) { $table->id(); @@ -27,7 +27,7 @@ class CreateTagsTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('tags'); } diff --git a/database/migrations/2023_04_18_153812_create_taggables_table.php b/database/migrations/2023_04_18_153812_create_taggables_table.php index afd2dac..24f849b 100644 --- a/database/migrations/2023_04_18_153812_create_taggables_table.php +++ b/database/migrations/2023_04_18_153812_create_taggables_table.php @@ -11,7 +11,7 @@ class CreateTaggablesTable extends Migration * * @return void */ - public function up() + public function up(): void { Schema::create('taggables', function (Blueprint $table) { $table->foreignId('tag_id')->references('id')->on('tags'); @@ -25,7 +25,7 @@ class CreateTaggablesTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('taggables'); } diff --git a/database/migrations/2023_04_18_172743_update_contacts_table.php b/database/migrations/2023_04_18_172743_update_contacts_table.php index 3b1c5ee..6d87a07 100644 --- a/database/migrations/2023_04_18_172743_update_contacts_table.php +++ b/database/migrations/2023_04_18_172743_update_contacts_table.php @@ -1,5 +1,6 @@ UPDATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong @@ -21,7 +22,7 @@ class UpdateContactsTable extends Migration Schema::table('contacts', function (Blueprint $table) { $table->renameColumn('user_id', 'app_user_id'); $table->renameColumn('name', 'lastname'); - $table->dateTime('created_at')->default('CURRENT_TIMESTAMP')->nullable()->change(); + $table->dateTime('created_at')->default(Carbon::now())->nullable()->change(); }); } @@ -30,7 +31,7 @@ class UpdateContactsTable extends Migration * * @return void */ - public function down() + public function down(): void { // * APP_USER->CREATED_AT //phpcs:ignore Generic.Files.LineLength.TooLong diff --git a/database/migrations/2023_07_17_154420_create_formularies_table.php b/database/migrations/2023_07_17_154420_create_formularies_table.php index 9d2ca9b..82c2df0 100644 --- a/database/migrations/2023_07_17_154420_create_formularies_table.php +++ b/database/migrations/2023_07_17_154420_create_formularies_table.php @@ -11,7 +11,7 @@ class CreateFormulariesTable extends Migration * * @return void */ - public function up() + public function up(): void { Schema::create('formularies', function (Blueprint $table) { $table->id(); @@ -33,7 +33,7 @@ class CreateFormulariesTable extends Migration * * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('formularies'); } diff --git a/database/migrations/2023_08_22_093330_seed_mandatory_forms.php b/database/migrations/2023_08_22_093330_seed_mandatory_forms.php deleted file mode 100644 index 1e084f0..0000000 --- a/database/migrations/2023_08_22_093330_seed_mandatory_forms.php +++ /dev/null @@ -1,27 +0,0 @@ -run(); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - // * DO NOTHING - } -} diff --git a/database/migrations/2023_08_22_171154_add_missing_remember_token_to_users.php b/database/migrations/2023_08_22_171154_add_missing_remember_token_to_users.php index c9832a0..de45a02 100644 --- a/database/migrations/2023_08_22_171154_add_missing_remember_token_to_users.php +++ b/database/migrations/2023_08_22_171154_add_missing_remember_token_to_users.php @@ -1,9 +1,7 @@ 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'); }); @@ -36,7 +23,7 @@ class AddMissingRememberTokenToUsers extends Migration * * @return void */ - public function down() + public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropRememberToken(); diff --git a/database/migrations/2023_08_25_093125_upgrade_contacts_table.php b/database/migrations/2023_08_25_093125_upgrade_contacts_table.php index 9322f9d..95325a6 100644 --- a/database/migrations/2023_08_25_093125_upgrade_contacts_table.php +++ b/database/migrations/2023_08_25_093125_upgrade_contacts_table.php @@ -18,49 +18,45 @@ class UpgradeContactsTable extends Migration * * @return void */ - public function up() + public function up(): void { - DB::transaction(function () { - $oldContacts = DB::table('contacts')->get(); - /** - * Keep columns, id, notes, visits, app_user_id - */ - Schema::table('contacts', function (Blueprint $table) { - $table->string('email')->comment('Email du contact, Form Status: System')->change(); - $table->string('lastname')->nullable()->comment('Nom du contact, Form Status: Locked')->change(); - $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->json('visits')->default('[]') - ->comment('Visite d\'un contact, Array<{title:string,note:string}>')->change(); + $oldContacts = DB::table('contacts')->get(); + /** + * Keep columns, id, notes, visits, app_user_id + */ + Schema::table('contacts', function (Blueprint $table) { + $table->string('email')->comment('Email du contact, Form Status: System')->change(); + $table->string('lastname')->nullable()->comment('Nom du contact, Form Status: Locked')->change(); + $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->json('visits')->comment('Visite d\'un contact, Array<{title:string,note:string}>')->change(); - $table->dropColumn('type'); - $table->dropColumn('other'); - $table->dropColumn('select1'); - $table->dropColumn('select2'); - $table->dropColumn('company'); - $table->dropColumn('address'); - $table->dropColumn('products'); - // * Just forget this column, dont migrate. - $table->dropColumn('card_url'); - $table->json('data')->after('phone') - ->comment('Array of \App\Lib\Inputs\Definition\InputData'); - }); + $table->dropColumn('type'); + $table->dropColumn('other'); + $table->dropColumn('select1'); + $table->dropColumn('select2'); + $table->dropColumn('company'); + $table->dropColumn('address'); + $table->dropColumn('products'); + // * Just forget this column, dont migrate. + $table->dropColumn('card_url'); + $table->json('data')->after('phone')->comment('Array of \App\Lib\Inputs\Definition\InputData'); + }); - /** @var \Illuminate\Support\Collection */ - $formularies = DB::table((new Formulary())->getTable())->pluck('slug')->flip(); + /** @var \Illuminate\Support\Collection */ + $formularies = DB::table((new Formulary())->getTable())->pluck('slug')->flip(); - $oldContacts->each(function (object $table) use ($formularies) { - $contact = Contact::query()->where('id', $table->id)->firstOrFail(); + $oldContacts->each(function (object $table) use ($formularies) { + $contact = Contact::query()->where('id', $table->id)->firstOrFail(); - // ! see this->getDataset. - $contact->data = collect($this->getInputs($table)) - // * FILTER CONTACT DATA WITH ACTUAL FORMULARY - ->filter(function (Input $input) use ($formularies) { - return $formularies->has($input->data->formSlug); - }); - $contact->saveQuietly(); - }); + // ! see this->getDataset. + $contact->data = collect($this->getInputs($table)) + // * FILTER CONTACT DATA WITH ACTUAL FORMULARY + ->filter(function (Input $input) use ($formularies) { + return $formularies->has($input->data->formSlug); + }); + $contact->saveQuietly(); }); } @@ -70,7 +66,7 @@ class UpgradeContactsTable extends Migration * @return void * @throws \RuntimeException Wont undo that. */ - public function down() + public function down(): void { throw new \RuntimeException('Wont undo that'); } diff --git a/database/migrations/2025_05_19_141630_alter_type_documents_table.php b/database/migrations/2025_05_19_141630_alter_type_documents_table.php deleted file mode 100644 index bf8d973..0000000 --- a/database/migrations/2025_05_19_141630_alter_type_documents_table.php +++ /dev/null @@ -1,62 +0,0 @@ -dropColumn('type'); - }); - Schema::table('documents', function (Blueprint $table) { - $table->tinyInteger('type')->comment('Document type.')->default(TypeEnum::pdf->value())->after('status'); - }); - Document::query()->get()->map(function (Document $document) { - switch (pathinfo($document->path, PATHINFO_EXTENSION)) { - case 'pdf': - $document->type = TypeEnum::pdf->value(); - break; - case 'mp4': - $document->type = TypeEnum::mp4->value(); - break; - } - $document->saveQuietly(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down(): void - { - Schema::table('documents', function (Blueprint $table) { - $table->dropColumn('type'); - }); - Schema::table('documents', function (Blueprint $table) { - $table->string('type')->after('title'); - }); - Document::query()->get()->map(function (Document $document) { - switch (pathinfo($document->path, PATHINFO_EXTENSION)) { - case 'pdf': - $document->type = TypeEnum::pdf->name(); - break; - case 'mp4': - $document->type = TypeEnum::mp4->name(); - break; - } - $document->saveQuietly(); - }); - } -}; diff --git a/database/migrations/2025_05_20_144302_update_tables_for_multitenant.php b/database/migrations/2025_05_20_144302_update_tables_for_multitenant.php index 2f551b3..6a8fda2 100644 --- a/database/migrations/2025_05_20_144302_update_tables_for_multitenant.php +++ b/database/migrations/2025_05_20_144302_update_tables_for_multitenant.php @@ -22,7 +22,7 @@ return new class extends Migration ['name' => 'documents', 'after' => 'title'], ]; - foreach ($tables as $entry) { + collect($tables)->map(function ($entry) { $tableName = $entry['name']; $after = $entry['after']; @@ -37,7 +37,32 @@ return new class extends Migration ->onUpdate('cascade') ->onDelete('cascade'); }); - } //end foreach + }); + + Schema::table('app_users', function (Blueprint $table) { + $table->dropUnique('app_users_email_unique'); + $table->unique(['tenant_id', 'email']); + }); + + Schema::table('documents', function (Blueprint $table) { + $table->dropUnique('documents_uuid_unique'); + $table->unique(['tenant_id', 'uuid']); + }); + + Schema::table('formularies', function (Blueprint $table) { + $table->dropUnique('formularies_slug_unique'); + $table->unique(['tenant_id', 'slug']); + }); + + Schema::table('settings', function (Blueprint $table) { + $table->dropUnique('settings_key_unique'); + $table->unique(['tenant_id', 'key']); + }); + + Schema::table('tags', function (Blueprint $table) { + $table->dropUnique('tags_slug_unique'); + $table->unique(['tenant_id', 'slug']); + }); } /** @@ -56,12 +81,41 @@ return new class extends Migration 'documents', ]; - foreach ($tables as $tableName) { + collect($tables)->map(function ($tableName) { Schema::table($tableName, function (Blueprint $table) use ($tableName) { $table->dropForeign($tableName . '_tenant_id_foreign'); + }); + }); + Schema::table('app_users', function (Blueprint $table) { + $table->dropUnique('app_users_tenant_id_email_unique'); + $table->unique(['email']); + }); + + Schema::table('documents', function (Blueprint $table) { + $table->dropUnique('documents_tenant_id_uuid_unique'); + $table->unique(['uuid']); + }); + + Schema::table('formularies', function (Blueprint $table) { + $table->dropUnique('formularies_tenant_id_slug_unique'); + $table->unique(['slug']); + }); + + Schema::table('settings', function (Blueprint $table) { + $table->dropUnique('settings_tenant_id_key_unique'); + $table->unique(['key']); + }); + + Schema::table('tags', function (Blueprint $table) { + $table->dropUnique('tags_tenant_id_slug_unique'); + $table->unique(['slug']); + }); + + collect($tables)->map(function ($tableName) { + Schema::table($tableName, function (Blueprint $table) { $table->dropColumn('tenant_id'); }); - } + }); } }; diff --git a/database/migrations/2025_05_21_131902_create_tenant_user_table.php b/database/migrations/2025_05_21_131902_create_tenant_user_table.php index 193fe33..f670e57 100644 --- a/database/migrations/2025_05_21_131902_create_tenant_user_table.php +++ b/database/migrations/2025_05_21_131902_create_tenant_user_table.php @@ -16,7 +16,7 @@ return new class extends Migration Schema::create('tenant_user', function (Blueprint $table) { $table->unsignedBigInteger('user_id'); $table->string('tenant_id', 255); - $table->primary(['user_id', 'tenant_id']); + $table->primary(['tenant_id']); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade'); }); diff --git a/database/migrations/2025_05_26_091952_alter_relations.php b/database/migrations/2025_05_26_091952_alter_relations.php new file mode 100644 index 0000000..16dc144 --- /dev/null +++ b/database/migrations/2025_05_26_091952_alter_relations.php @@ -0,0 +1,99 @@ +dropForeign(['user_id']); + $table->foreign('app_user_id') + ->references('id')->on('app_users') + ->onDelete('cascade'); + }); + Schema::table('directorables', function (Blueprint $table) { + $table->dropForeign(['directory_id']); + $table->foreign('directory_id') + ->references('id')->on('directories') + ->onDelete('cascade'); + }); + Schema::table('directories', function (Blueprint $table) { + $table->dropForeign('directories_parent_foreign'); + $table->foreign('directory_id') + ->references('id') + ->on('directories') + ->onDelete('cascade'); + }); + Schema::table('documents', function (Blueprint $table) { + $table->dropForeign('documents_directory_foreign'); + $table->foreign('directory_id') + ->references('id') + ->on('directories') + ->onDelete('cascade'); + $table->dropForeign('documents_document_id_foreign'); + $table->foreign('document_id') + ->references('id') + ->on('documents') + ->onDelete('cascade'); + $table->dropColumn('parent'); + }); + Schema::table('taggables', function (Blueprint $table) { + $table->dropForeign(['tag_id']); + $table->foreign('tag_id') + ->references('id')->on('tags') + ->onDelete('cascade'); + $table->dropForeign(['taggable_id']); + $table->foreign('taggable_id') + ->references('id')->on('documents') + ->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('contacts', function (Blueprint $table) { + $table->dropForeign(['app_user_id']); + $table->foreign('app_user_id') + ->references('id')->on('app_users'); + }); + Schema::table('directorables', function (Blueprint $table) { + $table->dropForeign(['directory_id']); + $table->foreign('directory_id') + ->references('id')->on('directories'); + }); + Schema::table('directories', function (Blueprint $table) { + $table->dropForeign(['directory_id']); + $table->foreign('directory_id') + ->references('id') + ->on('directories'); + }); + Schema::table('documents', function (Blueprint $table) { + $table->dropForeign(['directory_id']); + $table->foreign('directory_id') + ->references('id') + ->on('directories'); + $table->dropForeign(['document_id']); + $table->foreign('document_id') + ->references('id') + ->on('documents'); + }); + Schema::table('taggables', function (Blueprint $table) { + $table->dropForeign(['tag_id']); + $table->foreign('tag_id') + ->references('id')->on('tags'); + }); + } +}; diff --git a/database/seeders/AppUserSeeder.php b/database/seeders/AppUserSeeder.php index 0743d9f..cede390 100644 --- a/database/seeders/AppUserSeeder.php +++ b/database/seeders/AppUserSeeder.php @@ -12,13 +12,8 @@ class AppUserSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - $i = \intval(AppUser::query()->max('order')); - AppUser::factory(15)->make()->each(function (AppUser $appUser) use (&$i) { - $appUser->order = $i; - $appUser->saveOrFail(); - $i = $i + 1; - }); + AppUser::factory(15)->create(); } } diff --git a/database/seeders/ContactSeeder.php b/database/seeders/ContactSeeder.php index db4ecce..c673cdc 100644 --- a/database/seeders/ContactSeeder.php +++ b/database/seeders/ContactSeeder.php @@ -14,7 +14,7 @@ class ContactSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { DB::table((new Contact())->getTable())->truncate(); $appUsers = AppUser::all(); diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0f8db53..52d53ce 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -11,15 +11,13 @@ class DatabaseSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { $this->call([ TenantSeeder::class, AppUserSeeder::class, DirectorySeeder::class, - SettingSeeder::class, TagSeeder::class, - FormularySeeder::class, ContactSeeder::class, ]); } diff --git a/database/seeders/DirectorySeeder.php b/database/seeders/DirectorySeeder.php index da5db9c..bde2319 100644 --- a/database/seeders/DirectorySeeder.php +++ b/database/seeders/DirectorySeeder.php @@ -4,6 +4,7 @@ namespace Database\Seeders; use App\Models\AppUser; use App\Models\Directory; +use App\Models\Tenant; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; @@ -14,9 +15,8 @@ class DirectorySeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - $directory = new Directory(); $directory->name = [ "fr" => "Salon", @@ -28,14 +28,10 @@ class DirectorySeeder extends Seeder $directory->needAuthorization = 0; $directory->is_system = 1; $directory->order = 1; + $directory->tenant_id = Tenant::query()->first()->getKey(); $directory->saveOrFail(); - $i = 2; - Directory::factory(14)->make()->each(function (Directory $directory) use (&$i) { - $directory->order = $i; - $directory->saveOrFail(); - $i = $i + 1; - }); + Directory::factory(14)->create(); // Seeder for directory_authorizations table. $directories = Directory::query()->where('needAuthorization', true)->get(); diff --git a/database/seeders/FormularySeeder.php b/database/seeders/FormularySeeder.php index dd4fc23..5753c95 100644 --- a/database/seeders/FormularySeeder.php +++ b/database/seeders/FormularySeeder.php @@ -4,7 +4,6 @@ namespace Database\Seeders; use App\Models\Formulary; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; class FormularySeeder extends Seeder { @@ -13,10 +12,8 @@ class FormularySeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - DB::table((new Formulary())->getTable())->truncate(); - $this->call(MandatoryFormularySeeder::class); Formulary::factory(30)->create(); } } diff --git a/database/seeders/MandatoryFormularySeeder.php b/database/seeders/MandatoryFormularySeeder.php deleted file mode 100644 index d5953ff..0000000 --- a/database/seeders/MandatoryFormularySeeder.php +++ /dev/null @@ -1,108 +0,0 @@ -where('slug', 'firstname')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::text; - $formulary->name = "firstname"; - $formulary->slug = "firstname"; - $formulary->placeholder = ["fr" => "Prénom", "en" => "Firstname", "de" => "Vorname", "nl" => "Voornaam"]; - $formulary->details = null; - $formulary->required = false; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::locked; - $formulary->order = 1; - $formulary->saveOrFail(); - } - - if (!Formulary::query()->where('slug', 'lastname')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::text; - $formulary->name = "lastname"; - $formulary->slug = "lastname"; - $formulary->placeholder = ["fr" => "Nom", "en" => "Lastname", "de" => "Name", "nl" => "Naam"]; - $formulary->details = null; - $formulary->required = false; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::locked; - $formulary->order = 2; - $formulary->saveOrFail(); - } - - if (!Formulary::query()->where('slug', 'email')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::email; - $formulary->name = "email"; - $formulary->slug = "email"; - $formulary->placeholder = ["fr" => "E-mail", "en" => "E-mail", "de" => "E-mail", "nl" => "E-mail"]; - $formulary->details = null; - $formulary->required = true; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::system; - $formulary->order = 3; - $formulary->saveOrFail(); - } - - // * HERE FOR DATA MIGRATION - if (!Formulary::query()->where('slug', 'society')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::text; - $formulary->name = "society"; - $formulary->slug = "society"; - $formulary->placeholder = ["fr" => "Société", "en" => "Society", "de" => "Unternehmen", "nl" => "Bedrijf"]; - $formulary->details = null; - $formulary->required = false; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::default; - $formulary->order = 4; - $formulary->saveOrFail(); - } - - // * HERE FOR DATA MIGRATION - if (!Formulary::query()->where('slug', 'address')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::text; - $formulary->name = "address"; - $formulary->slug = "address"; - $formulary->placeholder = ["fr" => "Adresse", "en" => "Address", "de" => "Anschrift", "nl" => "Adres"]; - $formulary->details = null; - $formulary->required = false; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::default; - $formulary->order = 5; - $formulary->saveOrFail(); - } - - if (!Formulary::query()->where('slug', 'phone')->exists()) { - $formulary = new Formulary(); - $formulary->type = InputTypeEnum::phone; - $formulary->name = "phone"; - $formulary->slug = "phone"; - $formulary->placeholder = ["fr" => "Téléphone", "en" => "Phone", "de" => "Telefon", "nl" => "Telefoon"]; - $formulary->details = null; - $formulary->required = false; - $formulary->is_visible = true; - $formulary->status = InputStatusEnum::locked; - $formulary->order = 6; - $formulary->saveOrFail(); - } - - // * FIN Champs obligatoires - } -} diff --git a/database/seeders/MigrationSeeder.php b/database/seeders/MigrationSeeder.php index 5c2ef1e..7993d0c 100644 --- a/database/seeders/MigrationSeeder.php +++ b/database/seeders/MigrationSeeder.php @@ -12,7 +12,7 @@ class MigrationSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { DB::table('migrations')->truncate(); DB::table('migrations')->insert([ diff --git a/database/seeders/SettingSeeder.php b/database/seeders/SettingSeeder.php deleted file mode 100644 index 5ce5364..0000000 --- a/database/seeders/SettingSeeder.php +++ /dev/null @@ -1,137 +0,0 @@ -id = 1; - $setting->key = "version"; - $setting->value = 1; - $setting->type = 3; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 2; - $setting->key = "ShowIsActive"; - $setting->value = 0; - $setting->type = 4; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 3; - $setting->key = "MainColor"; - $setting->value = "#000000"; - $setting->type = 6; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 4; - $setting->key = "SquaredLogo"; - $setting->value = FileStorageHelper::storeFile( - $setting, - new \SplFileInfo(\resource_path( - '../database/factories/assets/settings/squared-logo-default.png' - )) - ); - $setting->type = 5; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 5; - $setting->key = "RectangleLogo"; - $setting->value = FileStorageHelper::storeFile( - $setting, - new \SplFileInfo(\resource_path( - '../database/factories/assets/settings/rectangle-logo-default.png' - )) - ); - $setting->type = 5; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 6; - $setting->key = "BackgroundImage"; - $setting->value = FileStorageHelper::storeFile( - $setting, - new \SplFileInfo(\resource_path( - '../database/factories/assets/settings/background-image-default.png' - )) - ); - $setting->type = 5; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 7; - $setting->key = "HomeButtonImage"; - $setting->value = FileStorageHelper::storeFile( - $setting, - new \SplFileInfo(\resource_path( - '../database/factories/assets/settings/home-button-image-default.png' - )) - ); - $setting->type = 5; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 8; - $setting->key = "Button1"; - $setting->value = collect(Directory::whereNull('directory_id')->pluck('id'))->random(); - $setting->type = 7; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 9; - $setting->key = "Button2"; - $setting->value = collect(Directory::whereNull('directory_id')->pluck('id'))->random(); - $setting->type = 7; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 10; - $setting->key = "Button3"; - $setting->value = collect(Directory::whereNull('directory_id')->pluck('id'))->random(); - $setting->type = 7; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 11; - $setting->key = "AppStoreUUID"; - $setting->value = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"; - $setting->type = 1; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 12; - $setting->key = "FormSelect1"; - $setting->value = "[{}]"; - $setting->type = 2; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 13; - $setting->key = "FormSelect2"; - $setting->value = "[{}]"; - $setting->type = 2; - $setting->saveOrFail(); - - $setting = new Setting(); - $setting->id = 14; - $setting->key = "FormCheck"; - $setting->value = "[{}]"; - $setting->type = 2; - $setting->saveOrFail(); - } -} diff --git a/database/seeders/TagSeeder.php b/database/seeders/TagSeeder.php index fc93018..829bba3 100644 --- a/database/seeders/TagSeeder.php +++ b/database/seeders/TagSeeder.php @@ -12,13 +12,8 @@ class TagSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - $i = 1; - Tag::factory(15)->make()->each(function (Tag $tag) use (&$i) { - $tag->order = $i; - $tag->saveOrFail(); - $i = $i + 1; - }); + Tag::factory(15)->create(); } }