Skip to content

Commit f23c70a

Browse files
authored
DB migration for box monetary value and stock (#831)
1 parent aa2976f commit f23c70a

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
use Phinx\Migration\AbstractMigration;
4+
5+
class AddBoxMonetaryValueWeight extends AbstractMigration
6+
{
7+
public function up(): void
8+
{
9+
$this->table('stock')
10+
->addColumn('weight_display_unit_id', 'integer', [
11+
'null' => true,
12+
'default' => 1, // kilogram
13+
'signed' => false,
14+
'after' => 'size_id',
15+
])
16+
->addColumn('weight', 'decimal', [
17+
'null' => true,
18+
'default' => null,
19+
'signed' => false,
20+
// Values for DECIMAL columns are stored using a binary format
21+
// that packs nine decimal digits into 4 bytes
22+
'precision' => 36,
23+
'scale' => 18,
24+
'after' => 'weight_display_unit_id',
25+
])
26+
->addColumn('monetary_value', 'decimal', [
27+
'null' => true,
28+
'default' => null,
29+
'signed' => false,
30+
'precision' => 36,
31+
'scale' => 18,
32+
'after' => 'weight',
33+
])
34+
->save()
35+
;
36+
$this->table('stock')
37+
->addForeignKey('weight_display_unit_id', 'units', 'id', [
38+
'delete' => 'RESTRICT', 'update' => 'CASCADE',
39+
])
40+
->save()
41+
;
42+
$this->table('camps')
43+
->addColumn('currency', 'string', [
44+
'null' => false,
45+
'default' => 'EUR',
46+
'limit' => 15,
47+
'collation' => 'utf8_general_ci',
48+
'encoding' => 'utf8',
49+
'after' => 'currencyname',
50+
])
51+
->save()
52+
;
53+
}
54+
55+
public function down(): void
56+
{
57+
$this->table('stock')
58+
->dropForeignKey('weight_display_unit_id')
59+
->removeColumn('weight_display_unit_id')
60+
->removeColumn('weight')
61+
->removeColumn('monetary_value')
62+
->save()
63+
;
64+
$this->table('camps')
65+
->removeColumn('currency')
66+
->save()
67+
;
68+
}
69+
}

0 commit comments

Comments
 (0)