|
- <?php
-
- use App\Models\ColumnName;
- use App\Util\MigrationHelper;
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
-
- return new class extends Migration
- {
- /**
- * Run the migrations.
- */
- public function up(): void
- {
-
- MigrationHelper::createTable('users', $this->schema(false));
- MigrationHelper::createTable('user_histories', $this->schema(true));
- }
-
- /**
- * Reverse the migrations.
- */
- public function down(): void
- {
- Schema::dropIfExists('users');
- Schema::dropIfExists('user_histories');
- }
-
- private function schema(bool $forHistory)
- {
-
- return function (Blueprint $table, MigrationHelper $helper) use ($forHistory) {
- $helper->baseColumn()
- ->contractId();
-
- $table->string('email')->comment("Email")->nullable();
- $table->string('password')->comment("ログインパスワード")->nullable();
- $table->unsignedTinyInteger("role")->comment("認可")->nullable();
- $table->string('name')->comment("氏名")->nullable();
-
-
- $helper->index(1, [ColumnName::CONTRACT_ID]);
-
- if ($forHistory) {
- $helper->index(2, ['email']);
- } else {
- $helper->unique(1, ['email']);
- }
- };
- }
- };
|