added pargar 3
This commit is contained in:
@@ -6,6 +6,18 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/** @param list<string> $candidates */
|
||||
private function firstExistingColumn(string $table, array $candidates): ?string
|
||||
{
|
||||
foreach ($candidates as $column) {
|
||||
if (Schema::hasColumn($table, $column)) {
|
||||
return $column;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('pargar_sync_logs')) {
|
||||
@@ -28,14 +40,36 @@ return new class extends Migration
|
||||
}
|
||||
|
||||
if (Schema::hasTable('customers') && ! Schema::hasColumn('customers', 'pargar_account_id')) {
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->string('pargar_account_id', 64)->nullable()->after('moshtari_code');
|
||||
$afterColumn = $this->firstExistingColumn('customers', [
|
||||
'moshtari_code',
|
||||
'tahesab_id',
|
||||
'finance_code',
|
||||
'pargar_id',
|
||||
'mobile',
|
||||
]);
|
||||
|
||||
Schema::table('customers', function (Blueprint $table) use ($afterColumn) {
|
||||
if ($afterColumn !== null) {
|
||||
$table->string('pargar_account_id', 64)->nullable()->after($afterColumn);
|
||||
} else {
|
||||
$table->string('pargar_account_id', 64)->nullable();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (Schema::hasTable('orders') && ! Schema::hasColumn('orders', 'pargar_confirmed_at')) {
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
$table->timestamp('pargar_confirmed_at')->nullable()->after('pay_at');
|
||||
$afterColumn = $this->firstExistingColumn('orders', [
|
||||
'pay_at',
|
||||
'sts',
|
||||
'updated_at',
|
||||
]);
|
||||
|
||||
Schema::table('orders', function (Blueprint $table) use ($afterColumn) {
|
||||
if ($afterColumn !== null) {
|
||||
$table->timestamp('pargar_confirmed_at')->nullable()->after($afterColumn);
|
||||
} else {
|
||||
$table->timestamp('pargar_confirmed_at')->nullable();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user