From 099a342a20307938264258775f26557a50ccdb6c Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sun, 16 Aug 2026 21:14:35 +0700 Subject: [PATCH] feat: update migration to modify enum columns and rename 'reject' to 'reject_selling' in product_prices and orders --- ...6_08_15_200000_split_reject_price_type.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) 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 9934284..4a22407 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,12 +7,18 @@ { public function up(): void { - // 1. product_prices: rename 'reject' → 'reject_selling', then add 'reject_capital' rows + // 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"); + } + + // 2. product_prices: rename 'reject' → 'reject_selling' DB::table('product_prices') ->where('type', 'reject') ->update(['type' => 'reject_selling']); - // Insert reject_capital rows (price = 0) for each variant that now has reject_selling + // 3. Insert reject_capital rows (price = 0) for each variant that now has reject_selling $rejectSellingPrices = DB::table('product_prices') ->where('type', 'reject_selling') ->get(); @@ -27,25 +33,15 @@ public function up(): void ]); } - // 2. orders: rename 'reject' → 'reject_selling' + // 4. orders: rename 'reject' → 'reject_selling' DB::table('orders') ->where('price_type', 'reject') ->update(['price_type' => 'reject_selling']); - - // 3. Modify enum columns to reflect 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"); - } } public function down(): void { - // Reverse: rename back and clean up - DB::table('product_prices') - ->where('type', 'reject_capital') - ->delete(); - + // 1. Rename data back FIRST while ENUM still allows new values DB::table('product_prices') ->where('type', 'reject_selling') ->update(['type' => 'reject']); @@ -54,6 +50,12 @@ public function down(): void ->where('price_type', 'reject_selling') ->update(['price_type' => 'reject']); + // 2. Delete reject_capital rows + DB::table('product_prices') + ->where('type', 'reject_capital') + ->delete(); + + // 3. Modify enum columns to remove 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') NOT NULL"); DB::statement("ALTER TABLE orders MODIFY COLUMN price_type ENUM('distributor','agent','sub_agent','wholesale','retail','tiktok','shopee','capital','reject') NOT NULL");