fix: 🗃️ update database relations
This commit is contained in:
parent
b13a4ced30
commit
d393b39d98
39 changed files with 267 additions and 731 deletions
|
|
@ -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'),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Types\SmallIntType;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
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
|
||||
|
|
@ -16,41 +11,8 @@ return new class extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
$columns = collect(
|
||||
Schema::getConnection()
|
||||
->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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Directory;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -13,7 +14,7 @@ class UpdateDirectoryTable extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
// * APP_USER->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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -13,7 +14,7 @@ class UpdateUsersTable extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
$usersOld = User::get();
|
||||
|
||||
|
|
@ -21,8 +22,8 @@ class UpdateUsersTable extends Migration
|
|||
DB::statement('ALTER TABLE `users` CHANGE `updated_at` `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->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
|
||||
|
|
|
|||
|
|
@ -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 =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -14,7 +15,7 @@ class UpdateSettingsTable extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
// * APP_USER->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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
|
@ -12,7 +13,7 @@ class UpdateContactsTable extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
// * APP_USER->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
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Database\Seeders\MandatoryFormularySeeder;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class SeedMandatoryForms extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
(new MandatoryFormularySeeder())->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// * DO NOTHING
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
<?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,19 +11,8 @@ class AddMissingRememberTokenToUsers extends Migration
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
public function up(): void
|
||||
{
|
||||
$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');
|
||||
});
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<string,integer> */
|
||||
$formularies = DB::table((new Formulary())->getTable())->pluck('slug')->flip();
|
||||
/** @var \Illuminate\Support\Collection<string,integer> */
|
||||
$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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Documents\TypeEnum;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('documents', function (Blueprint $table) {
|
||||
$table->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();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -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');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
|
|
|
|||
99
database/migrations/2025_05_26_091952_alter_relations.php
Normal file
99
database/migrations/2025_05_26_091952_alter_relations.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('contacts', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Enums\Formularies\InputStatusEnum;
|
||||
use App\Enums\Formularies\InputTypeEnum;
|
||||
use App\Models\Formulary;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MandatoryFormularySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// * Champs obligatoires
|
||||
if (!Formulary::query()->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
|
||||
}
|
||||
}
|
||||
|
|
@ -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([
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Models\Directory;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SettingSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$setting = new Setting();
|
||||
$setting->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue