diff --git a/composer.json b/composer.json index ac0b420..1a6df4d 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "kitloong/laravel-migrations-generator": "^7.1", "laravel/pail": "^1.2.2", "laravel/pint": "^1.13", "laravel/sail": "^1.41", diff --git a/composer.lock b/composer.lock index 3e67372..4b0f0aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "05c59fd15fab7bee856b9786a00e3fcd", + "content-hash": "592e08448fda5a7d5260d0ed24f8e7ce", "packages": [ { "name": "bacon/bacon-qr-code", @@ -7032,6 +7032,84 @@ }, "time": "2025-04-30T06:54:44+00:00" }, + { + "name": "kitloong/laravel-migrations-generator", + "version": "v7.1.2", + "source": { + "type": "git", + "url": "https://github.com/kitloong/laravel-migrations-generator.git", + "reference": "e46bdbe9308c211fd896cdc834b28d6b9f0dce3f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/kitloong/laravel-migrations-generator/zipball/e46bdbe9308c211fd896cdc834b28d6b9f0dce3f", + "reference": "e46bdbe9308c211fd896cdc834b28d6b9f0dce3f", + "shasum": "" + }, + "require": { + "ext-pdo": "*", + "illuminate/support": "^11.0|^12.0", + "php": "^8.2" + }, + "require-dev": { + "barryvdh/laravel-ide-helper": "^3.0", + "friendsofphp/php-cs-fixer": "^3.1", + "larastan/larastan": "^2.0|^3.0", + "mockery/mockery": "^1.0", + "orchestra/testbench": "^9.0|^10.0", + "phpmd/phpmd": "^2.10", + "phpstan/phpstan-mockery": "^1.0|^2.0", + "slevomat/coding-standard": "^8.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "KitLoong\\MigrationsGenerator\\MigrationsGeneratorServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "KitLoong\\MigrationsGenerator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kit Loong", + "email": "kitloong1008@gmail.com" + } + ], + "description": "Generates Laravel Migrations from an existing database", + "keywords": [ + "artisan", + "generator", + "laravel", + "lumen", + "migration", + "migrations" + ], + "support": { + "issues": "https://github.com/kitloong/laravel-migrations-generator/issues", + "source": "https://github.com/kitloong/laravel-migrations-generator/tree/v7.1.2" + }, + "funding": [ + { + "url": "https://www.buymeacoffee.com/kitloong", + "type": "buy_me_a_coffee" + }, + { + "url": "https://github.com/kitloong", + "type": "github" + } + ], + "time": "2025-02-27T12:06:46+00:00" + }, { "name": "laravel/pail", "version": "v1.2.3", diff --git a/database/migrations/0001_01_01_000000_create_users_table.php b/database/migrations/0001_01_01_000000_create_users_table.php deleted file mode 100644 index 31d7807..0000000 --- a/database/migrations/0001_01_01_000000_create_users_table.php +++ /dev/null @@ -1,51 +0,0 @@ -id(); - $table->string('name'); - $table->string('email')->unique(); - $table->timestamp('email_verified_at')->nullable(); - $table->string('password'); - $table->rememberToken(); - $table->foreignId('current_team_id')->nullable(); - $table->string('profile_photo_path', 2048)->nullable(); - $table->timestamps(); - }); - - Schema::create('password_reset_tokens', function (Blueprint $table) { - $table->string('email')->primary(); - $table->string('token'); - $table->timestamp('created_at')->nullable(); - }); - - Schema::create('sessions', function (Blueprint $table) { - $table->string('id')->primary(); - $table->foreignId('user_id')->nullable()->index(); - $table->string('ip_address', 45)->nullable(); - $table->text('user_agent')->nullable(); - $table->longText('payload'); - $table->integer('last_activity')->index(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('users'); - Schema::dropIfExists('password_reset_tokens'); - Schema::dropIfExists('sessions'); - } -}; diff --git a/database/migrations/2025_03_19_115944_add_two_factor_columns_to_users_table.php b/database/migrations/2025_03_19_115944_add_two_factor_columns_to_users_table.php deleted file mode 100644 index 45739ef..0000000 --- a/database/migrations/2025_03_19_115944_add_two_factor_columns_to_users_table.php +++ /dev/null @@ -1,42 +0,0 @@ -text('two_factor_secret') - ->after('password') - ->nullable(); - - $table->text('two_factor_recovery_codes') - ->after('two_factor_secret') - ->nullable(); - - $table->timestamp('two_factor_confirmed_at') - ->after('two_factor_recovery_codes') - ->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->dropColumn([ - 'two_factor_secret', - 'two_factor_recovery_codes', - 'two_factor_confirmed_at', - ]); - }); - } -}; diff --git a/database/migrations/2025_07_23_125354_create_files_table.php b/database/migrations/2025_07_23_125354_create_files_table.php deleted file mode 100644 index ef7816f..0000000 --- a/database/migrations/2025_07_23_125354_create_files_table.php +++ /dev/null @@ -1,28 +0,0 @@ -id(); - $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); - $table->string('file_path', 255)->comment('저장경로'); - $table->string('file_name', 255); - $table->integer('file_size')->nullable(); - $table->string('mime_type', 50)->nullable(); - $table->string('description', 255)->nullable(); - $table->timestamps(); - $table->softDeletes(); - }); - } - - public function down() - { - Schema::dropIfExists('files'); - } -}; diff --git a/database/migrations/2025_07_23_132617_create_board_comments_table.php b/database/migrations/2025_07_23_132617_create_board_comments_table.php deleted file mode 100644 index 1c5f8a5..0000000 --- a/database/migrations/2025_07_23_132617_create_board_comments_table.php +++ /dev/null @@ -1,31 +0,0 @@ -id()->comment('댓글 고유번호'); - $table->unsignedBigInteger('post_id')->comment('게시글 고유번호'); - $table->unsignedBigInteger('tenant_id')->comment('테넌트 고유번호'); - $table->unsignedBigInteger('user_id')->nullable()->comment('작성자 고유번호'); - $table->unsignedBigInteger('parent_id')->nullable()->comment('상위 댓글ID(대댓글)'); - $table->text('content')->comment('댓글 내용'); - $table->string('ip_address', 45)->nullable()->comment('작성자 IP'); - $table->string('status', 20)->default('active')->comment('상태'); - $table->timestamps(); - $table->softDeletes()->comment('삭제일시(Soft Delete)'); - - $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('tenant_id')->references('id')->on('tenants'); - $table->foreign('user_id')->references('id')->on('users'); - $table->foreign('parent_id')->references('id')->on('board_comments'); - }); - } - public function down(): void { - Schema::dropIfExists('board_comments'); - } -}; diff --git a/database/migrations/2025_07_23_160852_create_common_codes_table.php b/database/migrations/2025_07_23_160852_create_common_codes_table.php deleted file mode 100644 index 7758278..0000000 --- a/database/migrations/2025_07_23_160852_create_common_codes_table.php +++ /dev/null @@ -1,32 +0,0 @@ -json('attributes')->nullable()->comment('동적 속성')->after('parent_id'); - } - // 2. is_active 타입 및 코멘트 변경 - $table->tinyInteger('is_active')->default(1)->comment('사용여부')->change(); - }); - - // 3. 테이블 코멘트 - DB::statement("ALTER TABLE `common_codes` COMMENT = '공통코드 트리';"); - } - - public function down(): void - { - Schema::table('common_codes', function (Blueprint $table) { - if (Schema::hasColumn('common_codes', 'attributes')) { - $table->dropColumn('attributes'); - } - }); - } -}; diff --git a/database/migrations/2025_07_24_131242_update_files_table_for_common_usage.php b/database/migrations/2025_07_24_131242_update_files_table_for_common_usage.php deleted file mode 100644 index 8769762..0000000 --- a/database/migrations/2025_07_24_131242_update_files_table_for_common_usage.php +++ /dev/null @@ -1,37 +0,0 @@ -renameColumn('file_name', 'file_name_old'); // 잠시 백업 - - // 새로운 컬럼 추가 - $table->string('original_name', 255)->after('file_path')->comment('원본 파일명'); - $table->string('file_name', 255)->after('original_name')->comment('저장 파일명 (난수)'); - $table->string('target_table', 50)->after('description')->comment('연결된 테이블명'); - $table->unsignedBigInteger('target_id')->after('target_table')->comment('연결된 테이블의 PK ID'); - $table->unsignedBigInteger('uploaded_by')->nullable()->after('target_id')->comment('업로더 사용자 ID'); - }); - } - - public function down(): void - { - Schema::table('files', function (Blueprint $table) { - // 복구 시 이전 file_name 복원 - $table->string('file_name', 255)->after('file_path'); - $table->dropColumn([ - 'original_name', - 'target_table', - 'target_id', - 'uploaded_by' - ]); - }); - } -}; diff --git a/database/migrations/2025_07_24_180652_update_files_table_for_polymorphic_usage.php b/database/migrations/2025_07_24_180652_update_files_table_for_polymorphic_usage.php deleted file mode 100644 index a3b582d..0000000 --- a/database/migrations/2025_07_24_180652_update_files_table_for_polymorphic_usage.php +++ /dev/null @@ -1,32 +0,0 @@ -dropColumn(['target_table', 'target_id']); - - // Polymorphic 컬럼 추가 - $table->unsignedBigInteger('fileable_id')->after('description')->comment('Polymorphic - 연결된 모델의 PK'); - $table->string('fileable_type', 100)->after('fileable_id')->comment('Polymorphic - 연결된 모델 클래스명'); - }); - } - - public function down(): void - { - Schema::table('files', function (Blueprint $table) { - // Polymorphic 컬럼 제거 - $table->dropColumn(['fileable_id', 'fileable_type']); - - // 다시 기존 방식으로 복원 - $table->string('target_table', 50)->after('description')->comment('연결된 테이블명'); - $table->unsignedBigInteger('target_id')->after('target_table')->comment('연결된 테이블의 PK ID'); - }); - } -}; diff --git a/database/migrations/2025_07_25_150901_alter_log_session_id_length_to_128.php b/database/migrations/2025_07_25_150901_alter_log_session_id_length_to_128.php deleted file mode 100644 index 52fc61c..0000000 --- a/database/migrations/2025_07_25_150901_alter_log_session_id_length_to_128.php +++ /dev/null @@ -1,23 +0,0 @@ -string('id', 128)->change(); - }); - } - - public function down(): void - { - Schema::table('log_session', function (Blueprint $table) { - // id 컬럼 길이를 원래대로 40으로 복구 - $table->string('id', 40)->change(); - }); - } -}; diff --git a/database/migrations/2025_07_26_000818_create_roles_table.php b/database/migrations/2025_07_26_000818_create_roles_table.php deleted file mode 100644 index fed9fc2..0000000 --- a/database/migrations/2025_07_26_000818_create_roles_table.php +++ /dev/null @@ -1,36 +0,0 @@ -unsignedBigInteger('tenant_id')->nullable(false)->change(); - $table->string('name', 50)->comment('역할명')->change(); - $table->string('description', 255)->nullable()->comment('설명')->change(); - - // deleted_at 추가 (soft delete) - $table->softDeletes()->comment('삭제일시(소프트삭제)'); - }); - - // 2. (권장) 유니크 인덱스 보장: 한 테넌트 내에서 동일한 역할명 중복 불가 - Schema::table('roles', function (Blueprint $table) { - $table->unique(['tenant_id', 'name'], 'uk_roles_tenant_name'); - }); - } - - public function down(): void - { - Schema::table('roles', function (Blueprint $table) { - // 롤백시 soft delete 및 인덱스 제거 - $table->dropSoftDeletes(); - $table->dropUnique('uk_roles_tenant_name'); - }); - } -}; diff --git a/database/migrations/2025_07_26_000818_create_users_table.php b/database/migrations/2025_07_26_000818_create_users_table.php deleted file mode 100644 index e7fb099..0000000 --- a/database/migrations/2025_07_26_000818_create_users_table.php +++ /dev/null @@ -1,51 +0,0 @@ -unsignedBigInteger('tenant_id')->after('id')->comment('FK: 테넌트 ID')->default(1); // default 값은 마이그레이션 중 기존 데이터 보호용 - - // 2. 컬럼별 주석 보강 - $table->string('name', 255)->comment('회원 이름')->change(); - $table->string('email', 255)->comment('이메일')->change(); - $table->string('password', 255)->comment('비밀번호')->change(); - $table->string('profile_photo_path', 2048)->nullable()->comment('프로필 사진 경로')->change(); - $table->string('remember_token', 100)->nullable()->comment('자동로그인 토큰')->change(); - - // 3. soft delete 추가 - $table->softDeletes()->comment('삭제일시(소프트삭제)'); - - // 4. 유니크키 변경: (tenant_id, email)로 - $table->dropUnique(['email']); - $table->unique(['tenant_id', 'email'], 'uk_users_tenant_email'); - }); - - // FK 추가 (이미 tenants 테이블이 있어야 함) - Schema::table('users', function (Blueprint $table) { - $table->foreign('tenant_id')->references('id')->on('tenants'); - }); - } - - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - // 롤백: FK/유니크/컬럼 제거 - $table->dropForeign(['tenant_id']); - $table->dropUnique('uk_users_tenant_email'); - $table->dropColumn('tenant_id'); - $table->dropSoftDeletes(); - }); - - // 기존 유니크 복구 - Schema::table('users', function (Blueprint $table) { - $table->unique('email'); - }); - } -}; diff --git a/database/migrations/2025_07_26_011922_remove_tenant_id_from_users_table.php b/database/migrations/2025_07_26_011922_remove_tenant_id_from_users_table.php deleted file mode 100644 index c623758..0000000 --- a/database/migrations/2025_07_26_011922_remove_tenant_id_from_users_table.php +++ /dev/null @@ -1,26 +0,0 @@ -dropForeign('users_tenant_id_foreign'); - // 컬럼 삭제 - $table->dropColumn('tenant_id'); - }); - } - - public function down(): void - { - Schema::table('users', function (Blueprint $table) { - $table->unsignedBigInteger('tenant_id')->nullable()->comment('테넌트ID'); - $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('set null'); - }); - } -}; diff --git a/database/migrations/2025_03_24_184438_create_api_keys_table.php b/database/migrations/2025_07_26_051643_create_api_keys_table.php similarity index 67% rename from database/migrations/2025_03_24_184438_create_api_keys_table.php rename to database/migrations/2025_07_26_051643_create_api_keys_table.php index fbf89dc..cca23d4 100644 --- a/database/migrations/2025_03_24_184438_create_api_keys_table.php +++ b/database/migrations/2025_07_26_051643_create_api_keys_table.php @@ -12,10 +12,10 @@ public function up(): void { Schema::create('api_keys', function (Blueprint $table) { - $table->id(); - $table->string('key')->unique(); // API Key - $table->string('description')->nullable(); // 용도 설명 등 - $table->boolean('is_active')->default(true); // 키 활성 여부 + $table->bigIncrements('id'); + $table->string('key')->unique(); + $table->string('description')->nullable(); + $table->boolean('is_active')->default(true); $table->timestamps(); }); } diff --git a/database/migrations/2025_07_26_051643_create_board_comments_table.php b/database/migrations/2025_07_26_051643_create_board_comments_table.php new file mode 100644 index 0000000..8a9dd7e --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_board_comments_table.php @@ -0,0 +1,35 @@ +bigIncrements('id')->comment('댓글 고유번호'); + $table->unsignedBigInteger('post_id')->index('board_comments_post_id_foreign')->comment('게시글 고유번호'); + $table->unsignedBigInteger('tenant_id')->index('board_comments_tenant_id_foreign')->comment('테넌트 고유번호'); + $table->unsignedBigInteger('user_id')->nullable()->index('board_comments_user_id_foreign')->comment('작성자 고유번호'); + $table->unsignedBigInteger('parent_id')->nullable()->index('board_comments_parent_id_foreign')->comment('상위 댓글ID(대댓글)'); + $table->text('content')->comment('댓글 내용'); + $table->string('ip_address', 45)->nullable()->comment('작성자 IP'); + $table->string('status', 20)->default('active')->comment('상태'); + $table->timestamps(); + $table->softDeletes()->comment('삭제일시(Soft Delete)'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('board_comments'); + } +}; diff --git a/database/migrations/2025_07_23_132617_create_board_files_table.php b/database/migrations/2025_07_26_051643_create_board_files_table.php similarity index 50% rename from database/migrations/2025_07_23_132617_create_board_files_table.php rename to database/migrations/2025_07_26_051643_create_board_files_table.php index f9294b7..53c388a 100644 --- a/database/migrations/2025_07_23_132617_create_board_files_table.php +++ b/database/migrations/2025_07_26_051643_create_board_files_table.php @@ -6,20 +6,27 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('board_files', function (Blueprint $table) { - $table->id()->comment('첨부파일 고유번호'); - $table->unsignedBigInteger('post_id')->comment('게시글 고유번호'); - $table->string('file_path', 255)->comment('저장경로'); - $table->string('file_name', 255)->comment('원본 파일명'); + $table->bigIncrements('id')->comment('첨부파일 고유번호'); + $table->unsignedBigInteger('post_id')->index('board_files_post_id_foreign')->comment('게시글 고유번호'); + $table->string('file_path')->comment('저장경로'); + $table->string('file_name')->comment('원본 파일명'); $table->integer('file_size')->comment('파일 크기(Byte)'); $table->string('file_type', 100)->nullable()->comment('파일 MIME 타입'); $table->timestamps(); - - $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); }); } - public function down(): void { + + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('board_files'); } }; diff --git a/database/migrations/2025_07_23_132616_create_board_settings_table.php b/database/migrations/2025_07_26_051643_create_board_settings_table.php similarity index 79% rename from database/migrations/2025_07_23_132616_create_board_settings_table.php rename to database/migrations/2025_07_26_051643_create_board_settings_table.php index 3d1e8c4..a99e89b 100644 --- a/database/migrations/2025_07_23_132616_create_board_settings_table.php +++ b/database/migrations/2025_07_26_051643_create_board_settings_table.php @@ -6,9 +6,13 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('board_settings', function (Blueprint $table) { - $table->id()->comment('커스텀필드 고유번호'); + $table->bigIncrements('id')->comment('커스텀필드 고유번호'); $table->unsignedBigInteger('board_id')->comment('게시판 고유번호'); $table->string('name', 100)->comment('필드명'); $table->string('field_key', 50)->comment('필드키'); @@ -19,10 +23,14 @@ public function up(): void { $table->timestamps(); $table->unique(['board_id', 'field_key']); - $table->foreign('board_id')->references('id')->on('boards'); }); } - public function down(): void { + + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('board_settings'); } }; diff --git a/database/migrations/2025_07_23_132401_create_boards_table.php b/database/migrations/2025_07_26_051643_create_boards_table.php similarity index 78% rename from database/migrations/2025_07_23_132401_create_boards_table.php rename to database/migrations/2025_07_26_051643_create_boards_table.php index 9744ccb..1ab76bd 100644 --- a/database/migrations/2025_07_23_132401_create_boards_table.php +++ b/database/migrations/2025_07_26_051643_create_boards_table.php @@ -6,13 +6,17 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('boards', function (Blueprint $table) { - $table->id()->comment('게시판 고유번호'); + $table->bigIncrements('id')->comment('게시판 고유번호'); $table->unsignedBigInteger('tenant_id')->comment('테넌트 고유번호'); $table->string('board_code', 30)->comment('게시판 코드'); $table->string('name', 100)->comment('게시판 이름'); - $table->string('description', 255)->nullable()->comment('게시판 설명'); + $table->string('description')->nullable()->comment('게시판 설명'); $table->string('editor_type', 20)->default('wysiwyg')->comment('에디터 유형'); $table->boolean('allow_files')->default(true)->comment('파일첨부 허용 여부'); $table->integer('max_file_count')->default(5)->comment('최대 첨부파일 수'); @@ -22,10 +26,14 @@ public function up(): void { $table->timestamps(); $table->unique(['tenant_id', 'board_code']); - $table->foreign('tenant_id')->references('id')->on('tenants'); }); } - public function down(): void { + + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('boards'); } }; diff --git a/database/migrations/2025_07_23_125357_create_bom_items_table.php b/database/migrations/2025_07_26_051643_create_bom_items_table.php similarity index 70% rename from database/migrations/2025_07_23_125357_create_bom_items_table.php rename to database/migrations/2025_07_26_051643_create_bom_items_table.php index 83ddb02..1fa57cf 100644 --- a/database/migrations/2025_07_23_125357_create_bom_items_table.php +++ b/database/migrations/2025_07_26_051643_create_bom_items_table.php @@ -6,13 +6,16 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('bom_items', function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); - $table->unsignedBigInteger('bom_id')->comment('BOM ID'); - $table->unsignedBigInteger('parent_id')->nullable()->comment('상위 BOM Item'); + $table->unsignedBigInteger('bom_id')->index('bom_items_bom_id_foreign')->comment('BOM ID'); + $table->unsignedBigInteger('parent_id')->nullable()->index('bom_items_parent_id_foreign')->comment('상위 BOM Item'); $table->string('item_type', 20)->comment('item 종류: part, product, bom'); $table->unsignedBigInteger('ref_id')->comment('참조 ID'); $table->decimal('quantity', 18, 4)->default(1); @@ -20,13 +23,13 @@ public function up() $table->integer('sort_order')->default(0); $table->timestamps(); $table->softDeletes(); - - $table->foreign('bom_id')->references('id')->on('boms'); - $table->foreign('parent_id')->references('id')->on('bom_items'); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('bom_items'); } diff --git a/database/migrations/2025_07_23_125356_create_boms_table.php b/database/migrations/2025_07_26_051643_create_boms_table.php similarity index 51% rename from database/migrations/2025_07_23_125356_create_boms_table.php rename to database/migrations/2025_07_26_051643_create_boms_table.php index 284e81a..1da7472 100644 --- a/database/migrations/2025_07_23_125356_create_boms_table.php +++ b/database/migrations/2025_07_26_051643_create_boms_table.php @@ -6,31 +6,34 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('boms', function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); - $table->unsignedBigInteger('product_id')->comment('제품ID'); + $table->unsignedBigInteger('product_id')->index('boms_product_id_foreign')->comment('제품ID'); $table->string('code', 30)->comment('BOM코드'); $table->string('name', 100)->comment('BOM명'); - $table->unsignedBigInteger('category_id')->comment('카테고리ID(common_codes)'); + $table->unsignedBigInteger('category_id')->index('boms_category_id_foreign')->comment('카테고리ID(common_codes)'); $table->json('attributes')->nullable()->comment('동적 속성'); - $table->string('description', 255)->nullable()->comment('설명'); - $table->boolean('is_default')->default(0)->comment('기본BOM여부'); - $table->boolean('is_active')->default(1)->comment('사용여부'); - $table->unsignedBigInteger('image_file_id')->nullable()->comment('첨부파일ID'); + $table->string('description')->nullable()->comment('설명'); + $table->boolean('is_default')->default(false)->comment('기본BOM여부'); + $table->boolean('is_active')->default(true)->comment('사용여부'); + $table->unsignedBigInteger('image_file_id')->nullable()->index('boms_image_file_id_foreign')->comment('첨부파일ID'); $table->timestamps(); $table->softDeletes(); $table->unique(['tenant_id', 'product_id', 'code']); - $table->foreign('product_id')->references('id')->on('products'); - $table->foreign('category_id')->references('id')->on('common_codes'); - $table->foreign('image_file_id')->references('id')->on('files'); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('boms'); } diff --git a/database/migrations/0001_01_01_000001_create_cache_table.php b/database/migrations/2025_07_26_051643_create_cache_locks_table.php similarity index 71% rename from database/migrations/0001_01_01_000001_create_cache_table.php rename to database/migrations/2025_07_26_051643_create_cache_locks_table.php index b9c106b..e320c41 100644 --- a/database/migrations/0001_01_01_000001_create_cache_table.php +++ b/database/migrations/2025_07_26_051643_create_cache_locks_table.php @@ -11,12 +11,6 @@ */ public function up(): void { - Schema::create('cache', function (Blueprint $table) { - $table->string('key')->primary(); - $table->mediumText('value'); - $table->integer('expiration'); - }); - Schema::create('cache_locks', function (Blueprint $table) { $table->string('key')->primary(); $table->string('owner'); @@ -29,7 +23,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('cache'); Schema::dropIfExists('cache_locks'); } }; diff --git a/database/migrations/2025_07_26_051643_create_cache_table.php b/database/migrations/2025_07_26_051643_create_cache_table.php new file mode 100644 index 0000000..960ce18 --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_cache_table.php @@ -0,0 +1,28 @@ +string('key')->primary(); + $table->mediumText('value'); + $table->integer('expiration'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('cache'); + } +}; diff --git a/database/migrations/2025_07_23_125353_create_common_codes_table.php b/database/migrations/2025_07_26_051643_create_common_codes_table.php similarity index 63% rename from database/migrations/2025_07_23_125353_create_common_codes_table.php rename to database/migrations/2025_07_26_051643_create_common_codes_table.php index 715a581..f328597 100644 --- a/database/migrations/2025_07_23_125353_create_common_codes_table.php +++ b/database/migrations/2025_07_26_051643_create_common_codes_table.php @@ -6,27 +6,34 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('common_codes', function (Blueprint $table) { - $table->id(); + $table->comment('공통코드 트리'); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->nullable()->comment('멀티테넌시'); $table->string('code_group', 30)->default('category')->comment('코드 그룹'); $table->string('code', 20)->comment('코드값'); $table->string('name', 100)->comment('이름'); - $table->unsignedBigInteger('parent_id')->nullable()->comment('상위코드ID(트리)'); - $table->string('description', 255)->nullable()->comment('설명'); + $table->unsignedBigInteger('parent_id')->nullable()->index('common_codes_parent_id_foreign')->comment('상위코드ID(트리)'); + $table->json('attributes')->nullable()->comment('동적 속성'); + $table->string('description')->nullable()->comment('설명'); $table->tinyInteger('is_active')->default(1)->comment('사용여부'); $table->integer('sort_order')->default(0)->comment('정렬순서'); $table->timestamps(); $table->softDeletes(); - $table->unique(['tenant_id','code_group','code']); - $table->foreign('parent_id')->references('id')->on('common_codes'); + $table->unique(['tenant_id', 'code_group', 'code']); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('common_codes'); } diff --git a/database/migrations/2025_07_26_051643_create_failed_jobs_table.php b/database/migrations/2025_07_26_051643_create_failed_jobs_table.php new file mode 100644 index 0000000..08606bd --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_failed_jobs_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('uuid')->unique(); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('failed_jobs'); + } +}; diff --git a/database/migrations/2025_07_26_051643_create_files_table.php b/database/migrations/2025_07_26_051643_create_files_table.php new file mode 100644 index 0000000..cfa5afb --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_files_table.php @@ -0,0 +1,39 @@ +bigIncrements('id'); + $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); + $table->string('file_path')->comment('저장경로'); + $table->string('original_name')->comment('원본 파일명'); + $table->string('file_name')->comment('저장 파일명 (난수)'); + $table->string('file_name_old'); + $table->integer('file_size')->nullable(); + $table->string('mime_type', 50)->nullable(); + $table->string('description')->nullable(); + $table->unsignedBigInteger('fileable_id')->comment('Polymorphic - 연결된 모델의 PK'); + $table->string('fileable_type', 100)->comment('Polymorphic - 연결된 모델 클래스명'); + $table->unsignedBigInteger('uploaded_by')->nullable()->comment('업로더 사용자 ID'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('files'); + } +}; diff --git a/database/migrations/0001_01_01_000002_create_jobs_table.php b/database/migrations/2025_07_26_051643_create_job_batches_table.php similarity index 52% rename from database/migrations/0001_01_01_000002_create_jobs_table.php rename to database/migrations/2025_07_26_051643_create_job_batches_table.php index 425e705..50e38c2 100644 --- a/database/migrations/0001_01_01_000002_create_jobs_table.php +++ b/database/migrations/2025_07_26_051643_create_job_batches_table.php @@ -11,16 +11,6 @@ */ public function up(): void { - Schema::create('jobs', function (Blueprint $table) { - $table->id(); - $table->string('queue')->index(); - $table->longText('payload'); - $table->unsignedTinyInteger('attempts'); - $table->unsignedInteger('reserved_at')->nullable(); - $table->unsignedInteger('available_at'); - $table->unsignedInteger('created_at'); - }); - Schema::create('job_batches', function (Blueprint $table) { $table->string('id')->primary(); $table->string('name'); @@ -33,16 +23,6 @@ public function up(): void $table->integer('created_at'); $table->integer('finished_at')->nullable(); }); - - Schema::create('failed_jobs', function (Blueprint $table) { - $table->id(); - $table->string('uuid')->unique(); - $table->text('connection'); - $table->text('queue'); - $table->longText('payload'); - $table->longText('exception'); - $table->timestamp('failed_at')->useCurrent(); - }); } /** @@ -50,8 +30,6 @@ public function up(): void */ public function down(): void { - Schema::dropIfExists('jobs'); Schema::dropIfExists('job_batches'); - Schema::dropIfExists('failed_jobs'); } }; diff --git a/database/migrations/2025_07_26_051643_create_jobs_table.php b/database/migrations/2025_07_26_051643_create_jobs_table.php new file mode 100644 index 0000000..6098d9b --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_jobs_table.php @@ -0,0 +1,32 @@ +bigIncrements('id'); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('jobs'); + } +}; diff --git a/database/migrations/2025_07_26_051643_create_log_session_table.php b/database/migrations/2025_07_26_051643_create_log_session_table.php new file mode 100644 index 0000000..505b39f --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_log_session_table.php @@ -0,0 +1,32 @@ +comment('세션정보 저장 테이블'); + $table->string('id', 128)->primary(); + $table->string('ip_address', 45)->default('0')->comment('IP 주소'); + $table->string('user_agent', 120)->comment('User Agent'); + $table->integer('last_activity')->default(0)->index('last_activity_idx')->comment('마지막 활동 시간'); + $table->string('timestamp', 50)->comment('타임스탬프'); + $table->text('data')->comment('세션 데이터'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('log_session'); + } +}; diff --git a/database/migrations/2025_07_23_140449_create_menus_table.php b/database/migrations/2025_07_26_051643_create_menus_table.php similarity index 78% rename from database/migrations/2025_07_23_140449_create_menus_table.php rename to database/migrations/2025_07_26_051643_create_menus_table.php index dd7b621..8c4d6a2 100644 --- a/database/migrations/2025_07_23_140449_create_menus_table.php +++ b/database/migrations/2025_07_26_051643_create_menus_table.php @@ -6,24 +6,31 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('menus', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 메뉴 ID'); $table->unsignedBigInteger('tenant_id')->nullable()->index()->comment('FK: 테넌트 ID(null=공용메뉴)'); $table->unsignedBigInteger('parent_id')->nullable()->index()->comment('상위 메뉴 ID'); $table->string('name', 100)->comment('메뉴명'); - $table->string('url', 255)->nullable()->comment('메뉴 URL'); + $table->string('url')->nullable()->comment('메뉴 URL'); $table->boolean('is_active')->default(true)->comment('활성여부(1=활성,0=비활성)'); $table->integer('sort_order')->default(0)->comment('정렬순서'); $table->boolean('hidden')->default(false)->comment('숨김여부'); $table->boolean('is_external')->default(false)->comment('외부링크여부'); - $table->string('external_url', 255)->nullable()->comment('외부링크 URL'); + $table->string('external_url')->nullable()->comment('외부링크 URL'); $table->string('icon', 50)->nullable()->comment('아이콘명'); $table->timestamps(); }); } - public function down() + + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('menus'); } diff --git a/database/migrations/2025_07_23_125353_create_parts_table.php b/database/migrations/2025_07_26_051643_create_parts_table.php similarity index 62% rename from database/migrations/2025_07_23_125353_create_parts_table.php rename to database/migrations/2025_07_26_051643_create_parts_table.php index e03dae9..fe5ba50 100644 --- a/database/migrations/2025_07_23_125353_create_parts_table.php +++ b/database/migrations/2025_07_26_051643_create_parts_table.php @@ -6,29 +6,33 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('parts', function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); $table->string('code', 30)->comment('부품코드'); $table->string('name', 100)->comment('부품명'); - $table->unsignedBigInteger('category_id')->comment('카테고리ID(common_codes)'); - $table->unsignedBigInteger('part_type_id')->nullable()->comment('부품타입ID(common_codes)'); + $table->unsignedBigInteger('category_id')->index('parts_category_id_foreign')->comment('카테고리ID(common_codes)'); + $table->unsignedBigInteger('part_type_id')->nullable()->index('parts_part_type_id_foreign')->comment('부품타입ID(common_codes)'); $table->string('unit', 20)->nullable()->comment('단위'); $table->json('attributes')->nullable()->comment('동적 속성'); - $table->string('description', 255)->nullable()->comment('설명'); + $table->string('description')->nullable()->comment('설명'); $table->tinyInteger('is_active')->default(1)->comment('사용여부'); $table->timestamps(); $table->softDeletes(); - $table->unique(['tenant_id','code']); - $table->foreign('category_id')->references('id')->on('common_codes'); - $table->foreign('part_type_id')->references('id')->on('common_codes'); + $table->unique(['tenant_id', 'code']); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('parts'); } diff --git a/database/migrations/2025_07_26_051643_create_password_reset_tokens_table.php b/database/migrations/2025_07_26_051643_create_password_reset_tokens_table.php new file mode 100644 index 0000000..81a7229 --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_password_reset_tokens_table.php @@ -0,0 +1,28 @@ +string('email')->primary(); + $table->string('token'); + $table->timestamp('created_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('password_reset_tokens'); + } +}; diff --git a/database/migrations/2025_07_23_144844_create_payments_table.php b/database/migrations/2025_07_26_051643_create_payments_table.php similarity index 66% rename from database/migrations/2025_07_23_144844_create_payments_table.php rename to database/migrations/2025_07_26_051643_create_payments_table.php index e736ffd..32b55a0 100644 --- a/database/migrations/2025_07_23_144844_create_payments_table.php +++ b/database/migrations/2025_07_26_051643_create_payments_table.php @@ -6,11 +6,15 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('payments', function (Blueprint $table) { - $table->id()->comment('PK'); - $table->foreignId('subscription_id')->constrained('subscriptions')->comment('구독ID'); - $table->decimal('amount', 12, 2)->comment('결제금액'); + $table->bigIncrements('id')->comment('PK'); + $table->unsignedBigInteger('subscription_id')->index('payments_subscription_id_foreign'); + $table->decimal('amount', 12)->comment('결제금액'); $table->string('payment_method', 30)->comment('결제수단'); $table->string('transaction_id', 100)->nullable()->comment('PG 거래ID'); $table->dateTime('paid_at')->comment('결제일시'); @@ -21,7 +25,11 @@ public function up(): void { }); } - public function down(): void { + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('payments'); } }; diff --git a/database/migrations/2025_03_19_115956_create_personal_access_tokens_table.php b/database/migrations/2025_07_26_051643_create_personal_access_tokens_table.php similarity index 79% rename from database/migrations/2025_03_19_115956_create_personal_access_tokens_table.php rename to database/migrations/2025_07_26_051643_create_personal_access_tokens_table.php index e828ad8..2978f38 100644 --- a/database/migrations/2025_03_19_115956_create_personal_access_tokens_table.php +++ b/database/migrations/2025_07_26_051643_create_personal_access_tokens_table.php @@ -12,14 +12,17 @@ public function up(): void { Schema::create('personal_access_tokens', function (Blueprint $table) { - $table->id(); - $table->morphs('tokenable'); + $table->bigIncrements('id'); + $table->string('tokenable_type'); + $table->unsignedBigInteger('tokenable_id'); $table->string('name'); $table->string('token', 64)->unique(); $table->text('abilities')->nullable(); $table->timestamp('last_used_at')->nullable(); $table->timestamp('expires_at')->nullable(); $table->timestamps(); + + $table->index(['tokenable_type', 'tokenable_id']); }); } diff --git a/database/migrations/2025_07_23_144843_create_plans_table.php b/database/migrations/2025_07_26_051643_create_plans_table.php similarity index 74% rename from database/migrations/2025_07_23_144843_create_plans_table.php rename to database/migrations/2025_07_26_051643_create_plans_table.php index 0554513..1b502bd 100644 --- a/database/migrations/2025_07_23_144843_create_plans_table.php +++ b/database/migrations/2025_07_26_051643_create_plans_table.php @@ -6,13 +6,17 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('plans', function (Blueprint $table) { - $table->id()->comment('PK'); + $table->bigIncrements('id')->comment('PK'); $table->string('name')->comment('플랜명'); $table->string('code', 30)->unique()->comment('플랜 코드'); $table->text('description')->nullable()->comment('설명'); - $table->decimal('price', 12, 2)->comment('월 요금'); + $table->decimal('price', 12)->comment('월 요금'); $table->string('billing_cycle', 20)->default('monthly')->comment('청구 주기'); $table->json('features')->nullable()->comment('제공 기능/제한사항'); $table->boolean('is_active')->default(true)->comment('사용여부'); @@ -21,7 +25,11 @@ public function up(): void { }); } - public function down(): void { + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('plans'); } }; diff --git a/database/migrations/2025_07_23_132617_create_post_custom_field_values_table.php b/database/migrations/2025_07_26_051643_create_post_custom_field_values_table.php similarity index 59% rename from database/migrations/2025_07_23_132617_create_post_custom_field_values_table.php rename to database/migrations/2025_07_26_051643_create_post_custom_field_values_table.php index f611e9b..62bf8c2 100644 --- a/database/migrations/2025_07_23_132617_create_post_custom_field_values_table.php +++ b/database/migrations/2025_07_26_051643_create_post_custom_field_values_table.php @@ -6,20 +6,27 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('post_custom_field_values', function (Blueprint $table) { - $table->id()->comment('필드값 고유번호'); + $table->bigIncrements('id')->comment('필드값 고유번호'); $table->unsignedBigInteger('post_id')->comment('게시글 고유번호'); - $table->unsignedBigInteger('field_id')->comment('커스텀필드 고유번호'); + $table->unsignedBigInteger('field_id')->index('post_custom_field_values_field_id_foreign')->comment('커스텀필드 고유번호'); $table->text('value')->nullable()->comment('필드값'); $table->timestamps(); $table->unique(['post_id', 'field_id']); - $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('field_id')->references('id')->on('board_settings'); }); } - public function down(): void { + + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('post_custom_field_values'); } }; diff --git a/database/migrations/2025_07_23_132616_create_posts_table.php b/database/migrations/2025_07_26_051643_create_posts_table.php similarity index 67% rename from database/migrations/2025_07_23_132616_create_posts_table.php rename to database/migrations/2025_07_26_051643_create_posts_table.php index bfdc105..432b49c 100644 --- a/database/migrations/2025_07_23_132616_create_posts_table.php +++ b/database/migrations/2025_07_26_051643_create_posts_table.php @@ -6,30 +6,36 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('posts', function (Blueprint $table) { - $table->id()->comment('게시글 고유번호'); + $table->bigIncrements('id')->comment('게시글 고유번호'); $table->unsignedBigInteger('tenant_id')->comment('테넌트 고유번호'); - $table->unsignedBigInteger('board_id')->comment('게시판 고유번호'); + $table->unsignedBigInteger('board_id')->index('posts_board_id_foreign')->comment('게시판 고유번호'); $table->unsignedBigInteger('user_id')->nullable()->comment('작성자 고유번호'); - $table->string('title', 255)->comment('제목'); + $table->string('title')->comment('제목'); $table->longText('content')->comment('내용'); $table->string('editor_type', 20)->default('wysiwyg')->comment('에디터 유형'); $table->string('ip_address', 45)->nullable()->comment('작성자 IP'); $table->boolean('is_notice')->default(false)->comment('공지글 여부'); $table->boolean('is_secret')->default(false)->comment('비밀글 여부'); $table->integer('views')->default(0)->comment('조회수'); - $table->string('status', 20)->default('active')->comment('상태'); + $table->string('status', 20)->default('active')->index()->comment('상태'); $table->timestamps(); $table->softDeletes()->comment('삭제일시(Soft Delete)'); $table->index(['tenant_id', 'board_id']); - $table->index('status'); - $table->foreign('tenant_id')->references('id')->on('tenants'); - $table->foreign('board_id')->references('id')->on('boards'); }); } - public function down(): void { + + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('posts'); } }; diff --git a/database/migrations/2025_07_23_125354_create_price_histories_table.php b/database/migrations/2025_07_26_051643_create_price_histories_table.php similarity index 75% rename from database/migrations/2025_07_23_125354_create_price_histories_table.php rename to database/migrations/2025_07_26_051643_create_price_histories_table.php index eefc1d2..1b9c376 100644 --- a/database/migrations/2025_07_23_125354_create_price_histories_table.php +++ b/database/migrations/2025_07_26_051643_create_price_histories_table.php @@ -6,10 +6,13 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('price_histories', function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); $table->string('item_type_code', 20)->comment('대상구분(product/part/bom 등, code_group=price_item_type)'); $table->unsignedBigInteger('item_id')->comment('대상ID'); @@ -20,14 +23,14 @@ public function up() $table->timestamps(); $table->softDeletes(); - $table->index( - ['tenant_id', 'item_type_code', 'item_id', 'started_at'], - 'idx_price_histories_main' - ); + $table->index(['tenant_id', 'item_type_code', 'item_id', 'started_at'], 'idx_price_histories_main'); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('price_histories'); } diff --git a/database/migrations/2025_07_23_125353_create_products_table.php b/database/migrations/2025_07_26_051643_create_products_table.php similarity index 62% rename from database/migrations/2025_07_23_125353_create_products_table.php rename to database/migrations/2025_07_26_051643_create_products_table.php index 4602b37..3ab6e13 100644 --- a/database/migrations/2025_07_23_125353_create_products_table.php +++ b/database/migrations/2025_07_26_051643_create_products_table.php @@ -6,26 +6,31 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('products', function (Blueprint $table) { - $table->id(); + $table->bigIncrements('id'); $table->unsignedBigInteger('tenant_id')->comment('멀티테넌시'); $table->string('code', 30)->comment('제품코드'); $table->string('name', 100)->comment('제품명'); - $table->unsignedBigInteger('category_id')->comment('카테고리ID(common_codes)'); + $table->unsignedBigInteger('category_id')->index('products_category_id_foreign')->comment('카테고리ID(common_codes)'); $table->json('attributes')->nullable()->comment('동적 속성'); - $table->string('description', 255)->nullable()->comment('설명'); + $table->string('description')->nullable()->comment('설명'); $table->tinyInteger('is_active')->default(1)->comment('사용여부'); $table->timestamps(); $table->softDeletes(); - $table->unique(['tenant_id','code']); - $table->foreign('category_id')->references('id')->on('common_codes'); + $table->unique(['tenant_id', 'code']); }); } - public function down() + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('products'); } diff --git a/database/migrations/2025_07_23_140450_create_role_menu_permissions_table.php b/database/migrations/2025_07_26_051643_create_role_menu_permissions_table.php similarity index 76% rename from database/migrations/2025_07_23_140450_create_role_menu_permissions_table.php rename to database/migrations/2025_07_26_051643_create_role_menu_permissions_table.php index 8249ba0..984257d 100644 --- a/database/migrations/2025_07_23_140450_create_role_menu_permissions_table.php +++ b/database/migrations/2025_07_26_051643_create_role_menu_permissions_table.php @@ -6,12 +6,15 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('role_menu_permissions', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 역할-메뉴 권한 ID'); $table->unsignedBigInteger('role_id')->comment('FK: 역할 ID'); - $table->unsignedBigInteger('menu_id')->comment('FK: 메뉴 ID'); + $table->unsignedBigInteger('menu_id')->index('role_menu_permissions_menu_id_foreign')->comment('FK: 메뉴 ID'); $table->boolean('access')->default(false)->comment('메뉴 접근 권한'); $table->boolean('read')->default(false)->comment('조회 권한'); $table->boolean('write')->default(false)->comment('등록/수정/삭제 권한'); @@ -20,11 +23,13 @@ public function up() $table->timestamps(); $table->unique(['role_id', 'menu_id']); - $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); - $table->foreign('menu_id')->references('id')->on('menus')->onDelete('cascade'); }); } - public function down() + + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('role_menu_permissions'); } diff --git a/database/migrations/2025_07_23_140449_create_roles_table.php b/database/migrations/2025_07_26_051643_create_roles_table.php similarity index 51% rename from database/migrations/2025_07_23_140449_create_roles_table.php rename to database/migrations/2025_07_26_051643_create_roles_table.php index 9146ba8..abaf342 100644 --- a/database/migrations/2025_07_23_140449_create_roles_table.php +++ b/database/migrations/2025_07_26_051643_create_roles_table.php @@ -6,17 +6,27 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('roles', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 역할 ID'); - $table->unsignedBigInteger('tenant_id')->nullable()->index()->comment('FK: 테넌트 ID(null=공용역할)'); + $table->unsignedBigInteger('tenant_id')->index(); $table->string('name', 50)->comment('역할명'); - $table->string('description', 255)->nullable()->comment('설명'); + $table->string('description')->nullable()->comment('설명'); $table->timestamps(); + $table->softDeletes()->comment('삭제일시(소프트삭제)'); + + $table->unique(['tenant_id', 'name'], 'uk_roles_tenant_name'); }); } - public function down() + + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('roles'); } diff --git a/database/migrations/2025_07_26_051643_create_sessions_table.php b/database/migrations/2025_07_26_051643_create_sessions_table.php new file mode 100644 index 0000000..4b8efda --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_sessions_table.php @@ -0,0 +1,31 @@ +string('id')->primary(); + $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations/2025_07_23_144843_create_subscriptions_table.php b/database/migrations/2025_07_26_051643_create_subscriptions_table.php similarity index 61% rename from database/migrations/2025_07_23_144843_create_subscriptions_table.php rename to database/migrations/2025_07_26_051643_create_subscriptions_table.php index d07eea7..b2d9e26 100644 --- a/database/migrations/2025_07_23_144843_create_subscriptions_table.php +++ b/database/migrations/2025_07_26_051643_create_subscriptions_table.php @@ -6,11 +6,15 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('subscriptions', function (Blueprint $table) { - $table->id()->comment('PK'); - $table->foreignId('tenant_id')->constrained('tenants')->comment('테넌트ID'); - $table->foreignId('plan_id')->constrained('plans')->comment('플랜ID'); + $table->bigIncrements('id')->comment('PK'); + $table->unsignedBigInteger('tenant_id')->index('subscriptions_tenant_id_foreign'); + $table->unsignedBigInteger('plan_id')->index('subscriptions_plan_id_foreign'); $table->date('started_at')->comment('구독 시작일'); $table->date('ended_at')->nullable()->comment('구독 종료일(해지시)'); $table->string('status', 20)->default('active')->comment('상태(active, canceled, expired 등)'); @@ -19,7 +23,11 @@ public function up(): void { }); } - public function down(): void { + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('subscriptions'); } }; diff --git a/database/migrations/2025_07_23_132400_create_tenants_table.php b/database/migrations/2025_07_26_051643_create_tenants_table.php similarity index 58% rename from database/migrations/2025_07_23_132400_create_tenants_table.php rename to database/migrations/2025_07_26_051643_create_tenants_table.php index 28beda5..71c58e5 100644 --- a/database/migrations/2025_07_23_132400_create_tenants_table.php +++ b/database/migrations/2025_07_26_051643_create_tenants_table.php @@ -6,14 +6,26 @@ return new class extends Migration { - public function up(): void { + /** + * Run the migrations. + */ + public function up(): void + { Schema::create('tenants', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK'); - $table->string('name', 100)->comment('회사/조직명'); + $table->string('company_name', 100)->comment('회사/조직명'); $table->string('code', 50)->unique()->comment('테넌트 코드'); $table->string('email', 80)->nullable()->comment('대표 이메일'); $table->string('phone', 20)->nullable()->comment('대표 전화번호'); - $table->string('address', 255)->nullable()->comment('주소'); + $table->string('address')->nullable()->comment('주소'); + $table->string('business_num', 12)->nullable()->comment('사업자등록번호(10자리)'); + $table->string('corp_reg_no', 13)->nullable()->comment('법인등록번호(13자리, 법인만)'); + $table->string('ceo_name', 50)->nullable()->comment('대표자명'); + $table->string('homepage')->nullable()->comment('홈페이지 주소'); + $table->string('fax', 30)->nullable()->comment('팩스번호'); + $table->string('logo')->nullable()->comment('회사 로고 이미지 경로'); + $table->text('admin_memo')->nullable()->comment('관리자 메모/비고'); + $table->json('options')->nullable()->comment('회사별 옵션 정보(확장용 JSON)'); $table->string('tenant_st_code', 20)->default('trial')->comment('테넌트 상태(trial,active,suspended,cancelled)'); $table->unsignedBigInteger('plan_id')->nullable()->comment('현재 요금제(플랜) ID'); $table->unsignedBigInteger('subscription_id')->nullable()->comment('현재 구독 정보 ID'); @@ -24,14 +36,14 @@ public function up(): void { $table->string('billing_tp_code', 20)->default('monthly')->comment('결제 주기(monthly,yearly)'); $table->timestamps(); $table->softDeletes(); - - // FK는 필요시 추가 - // $table->foreign('plan_id')->references('id')->on('plans'); - // $table->foreign('subscription_id')->references('id')->on('subscriptions'); }); } - public function down(): void { + /** + * Reverse the migrations. + */ + public function down(): void + { Schema::dropIfExists('tenants'); } }; diff --git a/database/migrations/2025_07_23_140449_create_user_menu_permissions_table.php b/database/migrations/2025_07_26_051643_create_user_menu_permissions_table.php similarity index 76% rename from database/migrations/2025_07_23_140449_create_user_menu_permissions_table.php rename to database/migrations/2025_07_26_051643_create_user_menu_permissions_table.php index 8ec19b6..5139e22 100644 --- a/database/migrations/2025_07_23_140449_create_user_menu_permissions_table.php +++ b/database/migrations/2025_07_26_051643_create_user_menu_permissions_table.php @@ -6,12 +6,15 @@ return new class extends Migration { - public function up() + /** + * Run the migrations. + */ + public function up(): void { Schema::create('user_menu_permissions', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 사용자-메뉴 권한 ID'); $table->unsignedBigInteger('user_id')->comment('FK: 사용자 ID'); - $table->unsignedBigInteger('menu_id')->comment('FK: 메뉴 ID'); + $table->unsignedBigInteger('menu_id')->index('user_menu_permissions_menu_id_foreign')->comment('FK: 메뉴 ID'); $table->boolean('access')->default(false)->comment('메뉴 접근 권한'); $table->boolean('read')->default(false)->comment('조회 권한'); $table->boolean('write')->default(false)->comment('등록/수정/삭제 권한'); @@ -20,11 +23,13 @@ public function up() $table->timestamps(); $table->unique(['user_id', 'menu_id']); - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('menu_id')->references('id')->on('menus')->onDelete('cascade'); }); } - public function down() + + /** + * Reverse the migrations. + */ + public function down(): void { Schema::dropIfExists('user_menu_permissions'); } diff --git a/database/migrations/2025_07_26_000819_create_user_roles_table.php b/database/migrations/2025_07_26_051643_create_user_roles_table.php similarity index 69% rename from database/migrations/2025_07_26_000819_create_user_roles_table.php rename to database/migrations/2025_07_26_051643_create_user_roles_table.php index b9f5f28..daf926e 100644 --- a/database/migrations/2025_07_26_000819_create_user_roles_table.php +++ b/database/migrations/2025_07_26_051643_create_user_roles_table.php @@ -6,24 +6,27 @@ return new class extends Migration { + /** + * Run the migrations. + */ public function up(): void { Schema::create('user_roles', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 회원별 역할 매핑 ID'); $table->unsignedBigInteger('user_id')->comment('FK: 회원ID'); - $table->unsignedBigInteger('tenant_id')->comment('FK: 테넌트ID'); - $table->unsignedBigInteger('role_id')->comment('FK: 역할ID'); + $table->unsignedBigInteger('tenant_id')->index('user_roles_tenant_id_foreign')->comment('FK: 테넌트ID'); + $table->unsignedBigInteger('role_id')->index('user_roles_role_id_foreign')->comment('FK: 역할ID'); $table->timestamp('assigned_at')->nullable()->comment('역할 할당일'); $table->timestamps(); $table->softDeletes()->comment('삭제일시(소프트삭제)'); $table->unique(['user_id', 'tenant_id', 'role_id'], 'uk_user_tenant_role'); - $table->foreign('user_id')->references('id')->on('users'); - $table->foreign('tenant_id')->references('id')->on('tenants'); - $table->foreign('role_id')->references('id')->on('roles'); }); } + /** + * Reverse the migrations. + */ public function down(): void { Schema::dropIfExists('user_roles'); diff --git a/database/migrations/2025_07_26_000819_create_user_tenants_table.php b/database/migrations/2025_07_26_051643_create_user_tenants_table.php similarity index 71% rename from database/migrations/2025_07_26_000819_create_user_tenants_table.php rename to database/migrations/2025_07_26_051643_create_user_tenants_table.php index 44753d1..a725d5e 100644 --- a/database/migrations/2025_07_26_000819_create_user_tenants_table.php +++ b/database/migrations/2025_07_26_051643_create_user_tenants_table.php @@ -4,25 +4,30 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ + /** + * Run the migrations. + */ public function up(): void { Schema::create('user_tenants', function (Blueprint $table) { $table->bigIncrements('id')->comment('PK: 회원-테넌트 소속 ID'); $table->unsignedBigInteger('user_id')->comment('FK: 회원ID'); - $table->unsignedBigInteger('tenant_id')->comment('FK: 테넌트ID'); - $table->boolean('is_active')->default(1)->comment('활성화 여부'); + $table->unsignedBigInteger('tenant_id')->index('user_tenants_tenant_id_foreign')->comment('FK: 테넌트ID'); + $table->boolean('is_active')->default(true)->comment('활성화 여부'); $table->timestamp('joined_at')->nullable()->comment('소속일시'); $table->timestamp('left_at')->nullable()->comment('탈퇴일시'); $table->timestamps(); $table->softDeletes()->comment('삭제일시(소프트삭제)'); $table->unique(['user_id', 'tenant_id'], 'uk_user_tenant'); - $table->foreign('user_id')->references('id')->on('users'); - $table->foreign('tenant_id')->references('id')->on('tenants'); }); } + /** + * Reverse the migrations. + */ public function down(): void { Schema::dropIfExists('user_tenants'); diff --git a/database/migrations/2025_07_26_051643_create_users_table.php b/database/migrations/2025_07_26_051643_create_users_table.php new file mode 100644 index 0000000..014270e --- /dev/null +++ b/database/migrations/2025_07_26_051643_create_users_table.php @@ -0,0 +1,42 @@ +bigIncrements('id'); + $table->string('user_id', 100)->unique()->comment('회원 아이디'); + $table->string('phone', 30)->nullable()->comment('회원 전화번호'); + $table->json('options')->nullable()->comment('회사별 옵션 정보(계좌, 사번 등)'); + $table->string('name')->comment('회원 이름'); + $table->string('email')->unique('uk_users_tenant_email')->comment('이메일'); + $table->timestamp('email_verified_at')->nullable(); + $table->string('password')->comment('비밀번호'); + $table->timestamp('last_login_at')->nullable()->comment('마지막 로그인 일시'); + $table->text('two_factor_secret')->nullable(); + $table->text('two_factor_recovery_codes')->nullable(); + $table->timestamp('two_factor_confirmed_at')->nullable(); + $table->rememberToken()->comment('자동로그인 토큰'); + $table->unsignedBigInteger('current_team_id')->nullable(); + $table->string('profile_photo_path', 2048)->nullable()->comment('프로필 사진 경로'); + $table->timestamps(); + $table->softDeletes()->comment('삭제일시(소프트삭제)'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('users'); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_comments_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_comments_table.php new file mode 100644 index 0000000..b67781d --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_comments_table.php @@ -0,0 +1,34 @@ +foreign(['parent_id'])->references(['id'])->on('board_comments')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['post_id'])->references(['id'])->on('posts')->onUpdate('no action')->onDelete('cascade'); + $table->foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('board_comments', function (Blueprint $table) { + $table->dropForeign('board_comments_parent_id_foreign'); + $table->dropForeign('board_comments_post_id_foreign'); + $table->dropForeign('board_comments_tenant_id_foreign'); + $table->dropForeign('board_comments_user_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_files_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_files_table.php new file mode 100644 index 0000000..445dbbc --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_files_table.php @@ -0,0 +1,28 @@ +foreign(['post_id'])->references(['id'])->on('posts')->onUpdate('no action')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('board_files', function (Blueprint $table) { + $table->dropForeign('board_files_post_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_settings_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_settings_table.php new file mode 100644 index 0000000..33384b5 --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_board_settings_table.php @@ -0,0 +1,28 @@ +foreign(['board_id'])->references(['id'])->on('boards')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('board_settings', function (Blueprint $table) { + $table->dropForeign('board_settings_board_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_boards_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_boards_table.php new file mode 100644 index 0000000..0952994 --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_boards_table.php @@ -0,0 +1,28 @@ +foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('boards', function (Blueprint $table) { + $table->dropForeign('boards_tenant_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_bom_items_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_bom_items_table.php new file mode 100644 index 0000000..c704bdd --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_bom_items_table.php @@ -0,0 +1,30 @@ +foreign(['bom_id'])->references(['id'])->on('boms')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['parent_id'])->references(['id'])->on('bom_items')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('bom_items', function (Blueprint $table) { + $table->dropForeign('bom_items_bom_id_foreign'); + $table->dropForeign('bom_items_parent_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_boms_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_boms_table.php new file mode 100644 index 0000000..dd69b68 --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_boms_table.php @@ -0,0 +1,32 @@ +foreign(['category_id'])->references(['id'])->on('common_codes')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['image_file_id'])->references(['id'])->on('files')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['product_id'])->references(['id'])->on('products')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('boms', function (Blueprint $table) { + $table->dropForeign('boms_category_id_foreign'); + $table->dropForeign('boms_image_file_id_foreign'); + $table->dropForeign('boms_product_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_common_codes_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_common_codes_table.php new file mode 100644 index 0000000..b2e2b9a --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_common_codes_table.php @@ -0,0 +1,28 @@ +foreign(['parent_id'])->references(['id'])->on('common_codes')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('common_codes', function (Blueprint $table) { + $table->dropForeign('common_codes_parent_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_parts_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_parts_table.php new file mode 100644 index 0000000..5b9fa50 --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_parts_table.php @@ -0,0 +1,30 @@ +foreign(['category_id'])->references(['id'])->on('common_codes')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['part_type_id'])->references(['id'])->on('common_codes')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('parts', function (Blueprint $table) { + $table->dropForeign('parts_category_id_foreign'); + $table->dropForeign('parts_part_type_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_payments_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_payments_table.php new file mode 100644 index 0000000..5b011be --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_payments_table.php @@ -0,0 +1,28 @@ +foreign(['subscription_id'])->references(['id'])->on('subscriptions')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('payments', function (Blueprint $table) { + $table->dropForeign('payments_subscription_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_post_custom_field_values_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_post_custom_field_values_table.php new file mode 100644 index 0000000..cf168ea --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_post_custom_field_values_table.php @@ -0,0 +1,30 @@ +foreign(['field_id'])->references(['id'])->on('board_settings')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['post_id'])->references(['id'])->on('posts')->onUpdate('no action')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('post_custom_field_values', function (Blueprint $table) { + $table->dropForeign('post_custom_field_values_field_id_foreign'); + $table->dropForeign('post_custom_field_values_post_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_posts_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_posts_table.php new file mode 100644 index 0000000..19b87aa --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_posts_table.php @@ -0,0 +1,30 @@ +foreign(['board_id'])->references(['id'])->on('boards')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('posts', function (Blueprint $table) { + $table->dropForeign('posts_board_id_foreign'); + $table->dropForeign('posts_tenant_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_products_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_products_table.php new file mode 100644 index 0000000..a961e5c --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_products_table.php @@ -0,0 +1,28 @@ +foreign(['category_id'])->references(['id'])->on('common_codes')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('products', function (Blueprint $table) { + $table->dropForeign('products_category_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_role_menu_permissions_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_role_menu_permissions_table.php new file mode 100644 index 0000000..83e619b --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_role_menu_permissions_table.php @@ -0,0 +1,30 @@ +foreign(['menu_id'])->references(['id'])->on('menus')->onUpdate('no action')->onDelete('cascade'); + $table->foreign(['role_id'])->references(['id'])->on('roles')->onUpdate('no action')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('role_menu_permissions', function (Blueprint $table) { + $table->dropForeign('role_menu_permissions_menu_id_foreign'); + $table->dropForeign('role_menu_permissions_role_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_subscriptions_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_subscriptions_table.php new file mode 100644 index 0000000..c6c2fac --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_subscriptions_table.php @@ -0,0 +1,30 @@ +foreign(['plan_id'])->references(['id'])->on('plans')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('subscriptions', function (Blueprint $table) { + $table->dropForeign('subscriptions_plan_id_foreign'); + $table->dropForeign('subscriptions_tenant_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_menu_permissions_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_menu_permissions_table.php new file mode 100644 index 0000000..970b89f --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_menu_permissions_table.php @@ -0,0 +1,30 @@ +foreign(['menu_id'])->references(['id'])->on('menus')->onUpdate('no action')->onDelete('cascade'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('no action')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_menu_permissions', function (Blueprint $table) { + $table->dropForeign('user_menu_permissions_menu_id_foreign'); + $table->dropForeign('user_menu_permissions_user_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_roles_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_roles_table.php new file mode 100644 index 0000000..a280255 --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_roles_table.php @@ -0,0 +1,32 @@ +foreign(['role_id'])->references(['id'])->on('roles')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_roles', function (Blueprint $table) { + $table->dropForeign('user_roles_role_id_foreign'); + $table->dropForeign('user_roles_tenant_id_foreign'); + $table->dropForeign('user_roles_user_id_foreign'); + }); + } +}; diff --git a/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_tenants_table.php b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_tenants_table.php new file mode 100644 index 0000000..2cf136d --- /dev/null +++ b/database/migrations/2025_07_26_051646_add_foreign_keys_to_user_tenants_table.php @@ -0,0 +1,30 @@ +foreign(['tenant_id'])->references(['id'])->on('tenants')->onUpdate('no action')->onDelete('no action'); + $table->foreign(['user_id'])->references(['id'])->on('users')->onUpdate('no action')->onDelete('no action'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_tenants', function (Blueprint $table) { + $table->dropForeign('user_tenants_tenant_id_foreign'); + $table->dropForeign('user_tenants_user_id_foreign'); + }); + } +};