-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the
currency
field to the orders table
- Loading branch information
1 parent
d398e8d
commit a03e544
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
resources/database/migrations/2023_07_10_115351_add_currency_field_to_the_orders_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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() | ||
{ | ||
Schema::table('orders', function (Blueprint $table) { | ||
$table->char('currency', 3)->nullable()->after('language'); | ||
}); | ||
|
||
// Set default value for `currency` on existing records | ||
$currencyInConfig = config('vanilo.foundation.currency.code'); | ||
if (is_string($currencyInConfig) && 3 === strlen($currencyInConfig)) { | ||
DB::update('UPDATE orders set currency = ?', [$currencyInConfig]); | ||
} | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::table('orders', function (Blueprint $table) { | ||
$table->dropColumn('currency'); | ||
}); | ||
} | ||
}; |