diff --git a/db/migrations/20260701113522_add_box_monetary_value_weight.php b/db/migrations/20260701113522_add_box_monetary_value_weight.php new file mode 100644 index 00000000..54880723 --- /dev/null +++ b/db/migrations/20260701113522_add_box_monetary_value_weight.php @@ -0,0 +1,69 @@ +table('stock') + ->addColumn('weight_display_unit_id', 'integer', [ + 'null' => true, + 'default' => 1, // kilogram + 'signed' => false, + 'after' => 'size_id', + ]) + ->addColumn('weight', 'decimal', [ + 'null' => true, + 'default' => null, + 'signed' => false, + // Values for DECIMAL columns are stored using a binary format + // that packs nine decimal digits into 4 bytes + 'precision' => 36, + 'scale' => 18, + 'after' => 'weight_display_unit_id', + ]) + ->addColumn('monetary_value', 'decimal', [ + 'null' => true, + 'default' => null, + 'signed' => false, + 'precision' => 36, + 'scale' => 18, + 'after' => 'weight', + ]) + ->save() + ; + $this->table('stock') + ->addForeignKey('weight_display_unit_id', 'units', 'id', [ + 'delete' => 'RESTRICT', 'update' => 'CASCADE', + ]) + ->save() + ; + $this->table('camps') + ->addColumn('currency', 'string', [ + 'null' => false, + 'default' => 'EUR', + 'limit' => 15, + 'collation' => 'utf8_general_ci', + 'encoding' => 'utf8', + 'after' => 'currencyname', + ]) + ->save() + ; + } + + public function down(): void + { + $this->table('stock') + ->dropForeignKey('weight_display_unit_id') + ->removeColumn('weight_display_unit_id') + ->removeColumn('weight') + ->removeColumn('monetary_value') + ->save() + ; + $this->table('camps') + ->removeColumn('currency') + ->save() + ; + } +}