the browser-facing portion of osu!
1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5use Illuminate\Database\Migrations\Migration;
6use Illuminate\Database\Schema\Blueprint;
7
8class StoreBaseTables extends Migration
9{
10 /**
11 * Run the migrations.
12 *
13 * @return void
14 */
15 public function up()
16 {
17 $builder = Schema::connection('mysql-store');
18
19 $builder->create('addresses', function (Blueprint $table) {
20 $table->increments('address_id');
21 $table->integer('user_id')->unsigned()->nullable()->index('user_id');
22 $table->string('first_name', 256)->nullable();
23 $table->string('last_name', 256)->nullable();
24 $table->string('street', 2048)->nullable();
25 $table->string('city', 128)->nullable();
26 $table->string('state', 128)->nullable();
27 $table->string('zip', 128)->nullable();
28 $table->string('country_code', 2)->nullable();
29 $table->string('phone', 96)->nullable();
30 $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
31 $table->softDeletes();
32 $table->timestamp('updated_at')->nullable();
33 });
34
35 $builder->create('orders', function (Blueprint $table) {
36 $table->increments('order_id');
37 $table->integer('user_id')->unsigned();
38 $table->enum('status', ['incart', 'checkout', 'paid', 'shipped', 'cancelled', 'delivered'])->default('incart');
39 $table->integer('address_id')->unsigned()->nullable();
40 $table->string('tracking_code', 1024)->nullable();
41 $table->timestamp('shipped_at')->nullable();
42 $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
43 $table->softDeletes();
44 $table->timestamp('updated_at')->nullable();
45
46 $table->index('user_id', 'user_id');
47 $table->index('address_id', 'address_id');
48 $table->index('status', 'status');
49 $table->foreign('address_id', 'orders_ibfk_1')->references('address_id')->on('addresses')->onUpdate('RESTRICT')->onDelete('SET NULL');
50 });
51 $builder->getConnection()->statement('ALTER TABLE `orders` COMMENT = \'stores orders in all states (including cart contents).\';');
52
53 $builder->create('order_items', function (Blueprint $table) {
54 $table->increments('id');
55 $table->integer('order_id')->unsigned();
56 $table->integer('product_id')->unsigned();
57 $table->integer('quantity')->unsigned()->default(1);
58 $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
59 $table->softDeletes();
60 $table->timestamp('updated_at')->nullable();
61 $table->unique(['order_id', 'product_id'], 'order_id_product_id');
62 $table->foreign('order_id', 'FK_order_items_orders')->references('order_id')->on('orders')->onUpdate('RESTRICT')->onDelete('CASCADE');
63 });
64
65 $builder->create('products', function (Blueprint $table) {
66 $table->increments('product_id');
67 $table->string('name');
68 $table->text('description')->nullable();
69 $table->string('image')->nullable();
70 $table->decimal('cost', 10)->nullable();
71 $table->integer('weight')->nullable()->default(0);
72 $table->decimal('base_shipping', 10)->default(5.00);
73 $table->decimal('next_shipping', 10)->default(1.00);
74 $table->integer('stock')->nullable()->default(0);
75 $table->boolean('max_quantity')->unsigned()->default(10);
76 $table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
77 $table->softDeletes();
78 $table->timestamp('updated_at')->nullable();
79 });
80 }
81
82 /**
83 * Reverse the migrations.
84 *
85 * @return void
86 */
87 public function down()
88 {
89 $builder = Schema::connection('mysql-store');
90
91 $builder->drop('products');
92 $builder->drop('order_items');
93 $builder->drop('orders');
94 $builder->drop('addresses');
95 }
96}