diff --git a/database/migrations/2026_08_15_200000_split_reject_price_type.php b/database/migrations/2026_08_15_200000_split_reject_price_type.php index 4a22407..b892f75 100644 --- a/database/migrations/2026_08_15_200000_split_reject_price_type.php +++ b/database/migrations/2026_08_15_200000_split_reject_price_type.php @@ -7,10 +7,10 @@ { public function up(): void { - // 1. Modify enum columns FIRST to include new values (MySQL only) if (DB::getDriverName() === 'mysql') { - DB::statement("ALTER TABLE product_prices MODIFY COLUMN type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject_capital','reject_selling') NOT NULL"); - DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject_capital','reject_selling') NOT NULL"); + // 1. Add new values to ENUM but KEEP 'reject' (so existing rows aren't truncated) + DB::statement("ALTER TABLE product_prices MODIFY COLUMN type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject','reject_capital','reject_selling') NOT NULL"); + DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject','reject_capital','reject_selling') NOT NULL"); } // 2. product_prices: rename 'reject' → 'reject_selling' @@ -37,11 +37,23 @@ public function up(): void DB::table('orders') ->where('price_type', 'reject') ->update(['price_type' => 'reject_selling']); + + // 5. Remove 'reject' from ENUM (data already migrated) + if (DB::getDriverName() === 'mysql') { + DB::statement("ALTER TABLE product_prices MODIFY COLUMN type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject_capital','reject_selling') NOT NULL"); + DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject_capital','reject_selling') NOT NULL"); + } } public function down(): void { - // 1. Rename data back FIRST while ENUM still allows new values + if (DB::getDriverName() === 'mysql') { + // 1. Add 'reject' back to ENUM but KEEP new values (so updates work) + DB::statement("ALTER TABLE product_prices MODIFY COLUMN type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject','reject_capital','reject_selling') NOT NULL"); + DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject','reject_capital','reject_selling') NOT NULL"); + } + + // 2. Rename data back DB::table('product_prices') ->where('type', 'reject_selling') ->update(['type' => 'reject']); @@ -50,12 +62,12 @@ public function down(): void ->where('price_type', 'reject_selling') ->update(['price_type' => 'reject']); - // 2. Delete reject_capital rows + // 3. Delete reject_capital rows DB::table('product_prices') ->where('type', 'reject_capital') ->delete(); - // 3. Modify enum columns to remove new values (MySQL only) + // 4. Remove new values from ENUM if (DB::getDriverName() === 'mysql') { DB::statement("ALTER TABLE product_prices MODIFY COLUMN type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject') NOT NULL"); DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject') NOT NULL");