diff --git a/src/Database/migrations/2018_12_23_120000_create_shoppingcart_table.php b/src/Database/migrations/2018_12_23_120000_create_shoppingcart_table.php index 80e402f..8f29a69 100644 --- a/src/Database/migrations/2018_12_23_120000_create_shoppingcart_table.php +++ b/src/Database/migrations/2018_12_23_120000_create_shoppingcart_table.php @@ -13,12 +13,20 @@ class CreateShoppingcartTable extends Migration public function up() { Schema::create(Config::get('cart.database.tables.cart'), function (Blueprint $table) { - $table->string('identifier'); - $table->string('instance'); - $table->longText('content'); - $table->nullableTimestamps(); + /* Primary identifier of the cart, i.e. uinque user id */ + $table->string('identifier')->index(); + /* Instance of the cart to allow for multiple carts per identifier */ + $table->string('instance')->index(); + + /* Make primary key a combination of booth */ $table->primary(['identifier', 'instance']); + + /* Content of the cart */ + $table->longText('content'); + + /* Allow empty timestamps */ + $table->nullableTimestamps(); }); } diff --git a/src/Database/migrations/2022_02_06_194000_create_shoppingcart_items_table.php b/src/Database/migrations/2022_02_06_194000_create_shoppingcart_items_table.php index 0ba0c45..938f811 100644 --- a/src/Database/migrations/2022_02_06_194000_create_shoppingcart_items_table.php +++ b/src/Database/migrations/2022_02_06_194000_create_shoppingcart_items_table.php @@ -2,6 +2,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Schema; class CreateShoppingcartItemsTable extends Migration @@ -12,6 +13,25 @@ class CreateShoppingcartItemsTable extends Migration public function up() { Schema::create(Config::get('cart.database.tables.cart_item'), function (Blueprint $table) { + /* RowID of the CartItem, based on id and options */ + $table->string('row_id', 32)->index(); + + /* Relation CartItem to Cart */ + $table->unsignedBigInteger('cart_id'); + $table->foreign('cart_id')->references('id')->on(Config::get('cart.database.tables.cart')); + + /* Make id and rowid primary so there can not be duplicates */ + $table->primary(['cart_id', 'row_id']); + + /* The price of the CartItem */ + $table->unsignedBigInteger('price')->nullable(); + $table->unsignedFloat('discount_rate')->nullable(); + $table->unsignedBigInteger('discount_fixed')->nullable(); + $table->unsignedFloat('taxRate')->nullable(); + + /* Custom-Options of the CartItem */ + $table->json('options'); + $table->timestamps(); }); }