From 1763a04665b030ea89ec815e2bb915d269640bd8 Mon Sep 17 00:00:00 2001 From: adonis Date: Wed, 10 Jun 2026 20:59:43 +0330 Subject: [PATCH] fix migrations --- ...01_add_provider_fields_to_orders_table.php | 48 ++++++++++++++++ ...price_offset_percent_to_products_table.php | 34 +++++++++++ ...add_total_referrals_to_customers_table.php | 34 +++++++++++ ..._06_000002_alter_logs_data_to_longtext.php | 26 +++++++++ ..._order_limit_columns_to_products_table.php | 56 +++++++++++++++++++ ...1_add_show_in_assets_to_products_table.php | 41 ++++++++++++++ ...e_last_price_if_zero_to_products_table.php | 41 ++++++++++++++ ...0002_add_type_column_to_settings_table.php | 34 +++++++++++ database/sql/baseline_migrations.sql | 12 +++- 9 files changed, 323 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2026_05_25_163201_add_provider_fields_to_orders_table.php create mode 100644 database/migrations/2026_06_02_000001_add_price_offset_percent_to_products_table.php create mode 100644 database/migrations/2026_06_06_000001_add_total_referrals_to_customers_table.php create mode 100644 database/migrations/2026_06_06_000002_alter_logs_data_to_longtext.php create mode 100644 database/migrations/2026_06_06_000003_add_order_limit_columns_to_products_table.php create mode 100644 database/migrations/2026_06_09_000001_add_show_in_assets_to_products_table.php create mode 100644 database/migrations/2026_06_10_000001_add_use_last_price_if_zero_to_products_table.php create mode 100644 database/migrations/2026_06_10_000002_add_type_column_to_settings_table.php diff --git a/database/migrations/2026_05_25_163201_add_provider_fields_to_orders_table.php b/database/migrations/2026_05_25_163201_add_provider_fields_to_orders_table.php new file mode 100644 index 0000000..d05cadd --- /dev/null +++ b/database/migrations/2026_05_25_163201_add_provider_fields_to_orders_table.php @@ -0,0 +1,48 @@ +unsignedBigInteger('provider_id')->nullable()->after('id'); + $table->index('provider_id'); + } + + if (!Schema::hasColumn('orders', 'total_price_montzar')) { + if (Schema::hasColumn('orders', 'total_price')) { + $table->decimal('total_price_montzar', 20, 4)->nullable()->after('total_price'); + } else { + $table->decimal('total_price_montzar', 20, 4)->nullable(); + } + } + }); + } + + public function down(): void + { + if (!Schema::hasTable('orders')) { + return; + } + + Schema::table('orders', function (Blueprint $table) { + if (Schema::hasColumn('orders', 'total_price_montzar')) { + $table->dropColumn('total_price_montzar'); + } + + if (Schema::hasColumn('orders', 'provider_id')) { + $table->dropIndex(['provider_id']); + $table->dropColumn('provider_id'); + } + }); + } +}; diff --git a/database/migrations/2026_06_02_000001_add_price_offset_percent_to_products_table.php b/database/migrations/2026_06_02_000001_add_price_offset_percent_to_products_table.php new file mode 100644 index 0000000..9a077f1 --- /dev/null +++ b/database/migrations/2026_06_02_000001_add_price_offset_percent_to_products_table.php @@ -0,0 +1,34 @@ +decimal('price_offset_percent', 8, 2)->default(0)->after('price_profit'); + } else { + $table->decimal('price_offset_percent', 8, 2)->default(0); + } + }); + } + + public function down(): void + { + if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'price_offset_percent')) { + return; + } + + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('price_offset_percent'); + }); + } +}; diff --git a/database/migrations/2026_06_06_000001_add_total_referrals_to_customers_table.php b/database/migrations/2026_06_06_000001_add_total_referrals_to_customers_table.php new file mode 100644 index 0000000..f34a740 --- /dev/null +++ b/database/migrations/2026_06_06_000001_add_total_referrals_to_customers_table.php @@ -0,0 +1,34 @@ +unsignedInteger('total_referrals')->default(0)->after('referral_to_id'); + } else { + $table->unsignedInteger('total_referrals')->default(0); + } + }); + } + + public function down(): void + { + if (!Schema::hasTable('customers') || !Schema::hasColumn('customers', 'total_referrals')) { + return; + } + + Schema::table('customers', function (Blueprint $table) { + $table->dropColumn('total_referrals'); + }); + } +}; diff --git a/database/migrations/2026_06_06_000002_alter_logs_data_to_longtext.php b/database/migrations/2026_06_06_000002_alter_logs_data_to_longtext.php new file mode 100644 index 0000000..ee5920a --- /dev/null +++ b/database/migrations/2026_06_06_000002_alter_logs_data_to_longtext.php @@ -0,0 +1,26 @@ +boolean('order_limit_enabled')->default(false)->after('percent_fee_buy'); + } else { + $table->boolean('order_limit_enabled')->default(false); + } + } + + if (!Schema::hasColumn('products', 'min_order_cash')) { + if (Schema::hasColumn('products', 'order_limit_enabled')) { + $table->unsignedBigInteger('min_order_cash')->nullable()->after('order_limit_enabled'); + } else { + $table->unsignedBigInteger('min_order_cash')->nullable(); + } + } + + if (!Schema::hasColumn('products', 'max_order_cash')) { + if (Schema::hasColumn('products', 'min_order_cash')) { + $table->unsignedBigInteger('max_order_cash')->nullable()->after('min_order_cash'); + } else { + $table->unsignedBigInteger('max_order_cash')->nullable(); + } + } + }); + } + + public function down(): void + { + if (!Schema::hasTable('products')) { + return; + } + + Schema::table('products', function (Blueprint $table) { + foreach (['max_order_cash', 'min_order_cash', 'order_limit_enabled'] as $column) { + if (Schema::hasColumn('products', $column)) { + $table->dropColumn($column); + } + } + }); + } +}; diff --git a/database/migrations/2026_06_09_000001_add_show_in_assets_to_products_table.php b/database/migrations/2026_06_09_000001_add_show_in_assets_to_products_table.php new file mode 100644 index 0000000..f117d2a --- /dev/null +++ b/database/migrations/2026_06_09_000001_add_show_in_assets_to_products_table.php @@ -0,0 +1,41 @@ +boolean('show_in_assets')->default(false)->after('show'); + } else { + $table->boolean('show_in_assets')->default(false); + } + }); + } else { + DB::statement( + 'ALTER TABLE `products` MODIFY COLUMN `show_in_assets` TINYINT(1) NOT NULL DEFAULT 0' + ); + } + } + + public function down(): void + { + if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'show_in_assets')) { + return; + } + + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('show_in_assets'); + }); + } +}; diff --git a/database/migrations/2026_06_10_000001_add_use_last_price_if_zero_to_products_table.php b/database/migrations/2026_06_10_000001_add_use_last_price_if_zero_to_products_table.php new file mode 100644 index 0000000..ae81312 --- /dev/null +++ b/database/migrations/2026_06_10_000001_add_use_last_price_if_zero_to_products_table.php @@ -0,0 +1,41 @@ +boolean('use_last_price_if_zero')->default(false)->after('show_in_assets'); + } else { + $table->boolean('use_last_price_if_zero')->default(false); + } + }); + } else { + DB::statement( + 'ALTER TABLE `products` MODIFY COLUMN `use_last_price_if_zero` TINYINT(1) NOT NULL DEFAULT 0' + ); + } + } + + public function down(): void + { + if (!Schema::hasTable('products') || !Schema::hasColumn('products', 'use_last_price_if_zero')) { + return; + } + + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('use_last_price_if_zero'); + }); + } +}; diff --git a/database/migrations/2026_06_10_000002_add_type_column_to_settings_table.php b/database/migrations/2026_06_10_000002_add_type_column_to_settings_table.php new file mode 100644 index 0000000..cbf4251 --- /dev/null +++ b/database/migrations/2026_06_10_000002_add_type_column_to_settings_table.php @@ -0,0 +1,34 @@ +string('type', 64)->nullable()->after('description'); + } else { + $table->string('type', 64)->nullable(); + } + }); + } + + public function down(): void + { + if (!Schema::hasTable('settings') || !Schema::hasColumn('settings', 'type')) { + return; + } + + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +}; diff --git a/database/sql/baseline_migrations.sql b/database/sql/baseline_migrations.sql index 670fc1c..378ce1a 100644 --- a/database/sql/baseline_migrations.sql +++ b/database/sql/baseline_migrations.sql @@ -1,8 +1,11 @@ -- ============================================================================= --- baseline migrations — برای دیتابیس‌هایی که schema از قبل دارند (مثل groosy) +-- baseline migrations — فقط برای DB موجود که schema کامل دارد -- ============================================================================= --- بعد از import یا روی DB موجود اجرا کنید تا Laravel schema dump را دوباره --- load نکند و فقط migrationهای جدید با php artisan migrate اجرا شوند. +-- معمولاً لازم نیست! فقط php artisan migrate بزنید. +-- migrationها idempotent هستند — اگر ستون باشد skip می‌شود. +-- +-- این فایل فقط وقتی لازم است که migrations خالی باشد و نمی‌خواهید +-- Laravel فایل database/schema/mysql-schema.sql را دوباره load کند. -- -- USE `نام_دیتابیس`; -- ============================================================================= @@ -11,3 +14,6 @@ TRUNCATE TABLE `migrations`; INSERT INTO `migrations` (`migration`, `batch`) VALUES ('0000_00_00_000000_baseline_schema', 1); + +-- بعد: php artisan migrate +-- (۸ migration incremental اجرا و ثبت می‌شود)