fix migrations
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('orders')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('orders', 'provider_id')) {
|
||||
$table->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');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('products') || Schema::hasColumn('products', 'price_offset_percent')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('products', 'price_profit')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('customers') || Schema::hasColumn('customers', 'total_referrals')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('customers', 'referral_to_id')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('logs') || !Schema::hasColumn('logs', 'data')) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE `logs` MODIFY COLUMN `data` LONGTEXT NULL');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (!Schema::hasTable('logs') || !Schema::hasColumn('logs', 'data')) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE `logs` MODIFY COLUMN `data` TEXT NULL');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('products', 'order_limit_enabled')) {
|
||||
if (Schema::hasColumn('products', 'percent_fee_buy')) {
|
||||
$table->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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('products', 'show_in_assets')) {
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('products', 'show')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('products')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('products', 'use_last_price_if_zero')) {
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('products', 'show_in_assets')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (!Schema::hasTable('settings') || Schema::hasColumn('settings', 'type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('settings', 'description')) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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 اجرا و ثبت میشود)
|
||||
|
||||
Reference in New Issue
Block a user