├── Blog.md ├── LICENSE ├── README.md └── shop ├── README.md ├── laravel └── migrations │ ├── 2014_10_05_021330_create_password_resets_table.php │ ├── 2019_08_19_000000_create_failed_jobs_table.php │ ├── 2020_09_05_024331_create_files_table.php │ ├── 2020_09_05_024333_create_users_table.php │ ├── 2020_09_05_024524_create_categories_table.php │ ├── 2020_09_05_024536_create_products_table.php │ ├── 2020_09_05_024550_create_comments_table.php │ ├── 2020_09_05_024602_create_orders_table.php │ ├── 2020_09_05_024615_create_order_items_table.php │ ├── 2020_09_05_024630_create_order_status_table.php │ ├── 2020_09_05_024645_create_invoices_table.php │ ├── 2020_09_05_024659_create_refunds_table.php │ ├── 2020_09_05_024721_create_payment_transactiobs_table.php │ ├── 2020_09_05_024805_create_accounting_transactions_table.php │ ├── 2020_09_05_024806_create_discounts_table.php │ └── 2020_09_05_044906_add_foreign_to_files_table.php └── mysql.sql /Blog.md: -------------------------------------------------------------------------------- 1 | # Blog database schema 2 | 3 | ## Users 4 | | # | Name | Type | Default | Index | 5 | | ---- | ------------- |------------- | ----- | ----- | 6 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 7 | | 2 | [Avatar Id](#files) | Unsigned Integer | Null | Foreign key on files | 8 | | 3 | Name | String(64) | Not Null | | 9 | | 4 | Username | Char(32) | Null | Unique | 10 | | 5 | Email | Char(128) | Null | Unique | 11 | | 6 | Mobile | Char(16) | Null | Unique | 12 | | 7 | Password | String(64) | Not Null | | 13 | | 8 | Is Admin | Boolean | False | | 14 | | 9 | Disabled | Boolean | True | | 15 | | 10 | Description | Text | Null | | 16 | | 11 | Created At | Timestamp | Current Timestamp | | 17 | | 12 | Updated At | Timestamp | Current Timestamp | | 18 | | 13 | Deleted At | Timestamp | Null | | 19 | 20 | * [Never save password without hashing](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) 21 | 22 | 23 | ## Categories 24 | | # | Name | Type | Default | Index | 25 | | ---- | ------------- |------------- | ----- | ----- | 26 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 27 | | 2 | [Parent Id](#Categories) | Unsigned Integer | Null | Foreign key on categories | 28 | | 3 | Name | String(64) | Not Null | | 29 | | 4 | Slug | String(128) | Not Null | Unique | 30 | | 5 | Disabled | Boolean | True | | 31 | | 6 | Created At | Timestamp | Current Timestamp | | 32 | | 7 | Updated At | Timestamp | Current Timestamp | | 33 | | 8 | Deleted At | Timestamp | Null | | 34 | 35 | ## Posts 36 | | # | Name | Type | Default | Index | 37 | | ---- | ------------- |------------- | ----- | ----- | 38 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 39 | | 2 | [Author Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 40 | | 3 | [Category Id](#categories) | Unsigned Integer | Not Null | Foreign key on categories | 41 | | 4 | [Thumbnail Id](#files) | Unsigned Integer | Null | Foreign key on files | 42 | | 5 | Title | String(128) | Not Null | | 43 | | 6 | Summary | Text | Null | | 44 | | 7 | Body | Text | Not Null | | 45 | | 8 | Meta Description | String(512) | Null | | 46 | | 9 | Keywords | String(512) | Null | | 47 | | 10 | Comment Count | Unsigned Integer | 0 | | 48 | | 11 | Visit Count | Unsigned Integer | 0 | | 49 | | 12 | Slug | String(128) | Not Null | Unique | 50 | | 13 | Created At | Timestamp | Current Timestamp | | 51 | | 14 | Updated At | Timestamp | Current Timestamp | | 52 | | 15 | Published At | Timestamp | Null | | 53 | | 16 | Deleted At | Timestamp | Null | | 54 | 55 | ## Comments 56 | | # | Name | Type | Default | Index | 57 | | ---- | ------------- |------------- | ----- | ----- | 58 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 59 | | 2 | [Post Id](#posts) | Unsigned Integer | Not Null | Foreign key on posts | 60 | | 3 | [Reply To Id](#comments) | Unsigned Integer | Null | Foreign key on comments | 61 | | 4 | [Author Id](#users) | Unsigned Integer | Null | Foreign key on users | 62 | | 5 | Author Name | String(64) | Null | | 63 | | 6 | Body | Text | Not Null | | 64 | | 7 | Created At | Timestamp | Current Timestamp | | 65 | | 8 | Updated At | Timestamp | Current Timestamp | | 66 | | 9 | Published At | Timestamp | Null | | 67 | | 10 | Deleted At | Timestamp | Null | | 68 | 69 | ## Files 70 | | # | Name | Type | Default | Index | 71 | | ---- | ------------- |------------- | ----- | ----- | 72 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 73 | | 2 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 74 | | 3 | [Post Id](#posts) | Unsigned Integer | Not Null | Foreign key on posts | 75 | | 4 | Name | String(64) | Not Null | | 76 | | 5 | Path | String(64) | Not Null | Unique | 77 | | 6 | Published | Boolean | False | | 78 | | 7 | Created At | Timestamp | Current Timestamp | | 79 | | 8 | Updated At | Timestamp | Current Timestamp | | 80 | | 9 | Deleted At | Timestamp | Null | | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mahdi Bagheri 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Database schema for general application 2 | 3 | ## Notes 4 | * Use plural table name => *users* 5 | * Always use an auto increment column => *id* 6 | * Use lower case for table columns => *username* 7 | * Use snake_case for table columns => *created_at* 8 | * Default values should give less access for example if there is a *disabled* field the default value should be *true* 9 | * You shouldn't go to code for understanding data structure and vice versa 10 | 11 | 12 | [Blog database schema](./Blog.md) 13 | 14 | [Shop database schema](./shop) 15 | 16 | ## Future development 17 | * ACL: access control list 18 | * Ticketing (support) 19 | * Add SQL file 20 | * Add migration 21 | * Add Models 22 | -------------------------------------------------------------------------------- /shop/README.md: -------------------------------------------------------------------------------- 1 | # Shop database schema 2 | 3 | ## Users 4 | | # | Name | Type | Default | Index | 5 | | ---- | ------------- |------------- | ----- | ----- | 6 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 7 | | 2 | [Avatar Id](#files) | Unsigned Integer | Null | Foreign key on files | 8 | | 3 | Name | String(64) | Not Null | | 9 | | 4 | Username | Char(32) | Null | Unique | 10 | | 5 | Email | Char(128) | Null | Unique | 11 | | 6 | Email Verified At | Timestamp | Current Timestamp | | 12 | | 7 | Mobile | Char(16) | Null | Unique | 13 | | 8 | Mobile Verified At | Timestamp | Current Timestamp | | 14 | | 9 | Balance | Unsigned Integer | 0 | | 15 | | 10 | Password | String(64) | Not Null | | 16 | | 11 | Is Admin | Boolean | False | | 17 | | 12 | Disabled | Boolean | True | | 18 | | 13 | Description | Text | Null | | 19 | | 14 | Created At | Timestamp | Current Timestamp | | 20 | | 15 | Updated At | Timestamp | Current Timestamp | | 21 | | 16 | Deleted At | Timestamp | Null | | 22 | 23 | * [Never save password without hashing](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html) 24 | 25 | ## Categories 26 | | # | Name | Type | Default | Index | 27 | | ---- | ------------- |------------- | ----- | ----- | 28 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 29 | | 2 | [Parent Id](#Categories) | Unsigned Integer | Null | Foreign key on categories | 30 | | 3 | Name | String(128) | Not Null | | 31 | | 4 | Slug | String(128) | Not Null | Unique | 32 | | 5 | Disabled | Boolean | True | | 33 | | 6 | Created At | Timestamp | Current Timestamp | | 34 | | 7 | Updated At | Timestamp | Current Timestamp | | 35 | | 8 | Deleted At | Timestamp | Null | | 36 | 37 | ## Products 38 | | # | Name | Type | Default | Index | 39 | | ---- | ------------- |------------- | ----- | ----- | 40 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 41 | | 2 | [Category Id](#categories) | Unsigned Integer | Null | Foreign key on categories | 42 | | 3 | [Thumbnail Id](#files) | Unsigned Integer | Null | Foreign key on files | 43 | | 4 | Name | String(128) | Not Null | | 44 | | 5 | Slug | String(128) | Not Null | Unique | 45 | | 6 | Summary | String(256) | Null | | 46 | | 7 | Description | Text | Not Null | | 47 | | 8 | Price | Unsigned Integer | Not Null | | 48 | | 9 | Quantity | Unsigned Integer | 0 | | 49 | | 10 | Priority | Unsigned Integer | 0 | | 50 | | 11 | Disabled | Boolean | True | | 51 | | 12 | Created At | Timestamp | Current Timestamp | | 52 | | 13 | Updated At | Timestamp | Current Timestamp | | 53 | | 14 | Deleted At | Timestamp | Null | | 54 | 55 | ## Comments 56 | | # | Name | Type | Default | Index | 57 | | ---- | ------------- |------------- | ----- | ----- | 58 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 59 | | 2 | [Product Id](#products) | Unsigned Integer | Not Null | Foreign key on products | 60 | | 3 | [Reply To Id](#comments) | Unsigned Integer | Null | Foreign key on comments | 61 | | 4 | [Author Id](#users) | Unsigned Integer | Null | Foreign key on users | 62 | | 5 | Author Name | String(64) | Null | | 63 | | 6 | Body | Text | Not Null | | 64 | | 7 | Created At | Timestamp | Current Timestamp | | 65 | | 8 | Updated At | Timestamp | Current Timestamp | | 66 | | 9 | Published At | Timestamp | Null | | 67 | | 10 | Deleted At | Timestamp | Null | | 68 | 69 | ## Orders 70 | | # | Name | Type | Default | Index | 71 | | ---- | ------------- |------------- | ----- | ----- | 72 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 73 | | 2 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 74 | | 3 | Tracking Code | String(32) | Not Null | Unique | 75 | | 4 | Item Count | Unsigned Integer | 0 | | 76 | | 5 | Items Price | Unsigned Integer | 0 | | 77 | | 6 | Delivery Cost | Unsigned Integer | 0 | | 78 | | 7 | Value Added Tax | Unsigned Integer | 0 | | 79 | | 8 | Discount | Unsigned Integer | 0 | | 80 | | 9 | Total Price | Unsigned Integer | 0 | | 81 | | 10 | Cash On Delivery | Boolean | False | | 82 | | 11 | [State](#order-state-enum) | Enum | Not Null | | 83 | | 12 | Created At | Timestamp | Current Timestamp | | 84 | | 13 | Updated At | Timestamp | Current Timestamp | | 85 | 86 | ## Order Items 87 | | # | Name | Type | Default | Index | 88 | | ---- | ------------- |------------- | ----- | ----- | 89 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 90 | | 2 | [Order Id](#orders) | Unsigned Integer | Not Null | Foreign key on orders | 91 | | 3 | [Product Id](#products) | Unsigned Integer | Not Null | Foreign key on products | 92 | | 4 | Count | Unsigned Integer | 0 | | 93 | | 5 | Price | Unsigned Integer | 0 | | 94 | | 6 | Total Price | Unsigned Integer | 0 | | 95 | | 7 | Created At | Timestamp | Current Timestamp | | 96 | | 8 | Updated At | Timestamp | Current Timestamp | | 97 | 98 | ## Order Activity 99 | | # | Name | Type | Default | Index | 100 | | ---- | ------------- |------------- | ----- | ----- | 101 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 102 | | 2 | [Order Id](#orders) | Unsigned Integer | Not Null | Foreign key on orders | 103 | | 3 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 104 | | 4 | [State](#order-state-enum) | Enum | Not Null | | 105 | | 5 | Description | Text | Null | | 106 | | 6 | Created At | Timestamp | Current Timestamp | | 107 | 108 | ## Order State Enum 109 | | Name | Description 110 | | ------------- |------------- | 111 | | Waiting | | 112 | | Paying | | 113 | | Paid | | 114 | | Sent | | 115 | | Canceled | | 116 | 117 | ## Invoices 118 | | # | Name | Type | Default | Index | 119 | | ---- | ------------- |------------- | ----- | ----- | 120 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 121 | | 2 | [Issuer Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 122 | | 3 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 123 | | 6 | Amount | Unsigned Integer | Not Null | | 124 | | 7 | Tracking Code | String(64) | Not Null | Unique | 125 | | 8 | Slug | String(128) | Not Null | Unique | 126 | | 9 | Title | String(128) | Not Null | | 127 | | 10 | Description | Text | Null | | 128 | | 11 | Paid At | Timestamp | Null | | 129 | | 12 | Expired At | Timestamp | Null | | 130 | | 13 | Created At | Timestamp | Current Timestamp | | 131 | | 14 | Updated At | Timestamp | Current Timestamp | | 132 | 133 | ## Refunds 134 | payback money to users 135 | | # | Name | Type | Default | Index | 136 | | ---- | ------------- |------------- | ----- | ----- | 137 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 138 | | 2 | [Issuer Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 139 | | 3 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 140 | | 4 | Amount | Unsigned Integer | Not Null | | 141 | | 5 | Tracking Code | String(64) | Not Null | Unique | 142 | | 6 | Slug | String(128) | Not Null | Unique | 143 | | 7 | Title | String(128) | Not Null | | 144 | | 8 | Description | Text | Null | | 145 | | 9 | Paid At | Timestamp | Null | | 146 | | 10 | Created At | Timestamp | Current Timestamp | | 147 | 148 | ## Payment Transactions 149 | | # | Name | Type | Default | Index | 150 | | ---- | ------------- |------------- | ----- | ----- | 151 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 152 | | 2 | [User Id](#users) | Unsigned Integer | Null | Foreign key on users | 153 | | 3 | [Invoice Id](#invoices) | Unsigned Integer | Not Null | Foreign key on invoices | 154 | | 4 | [Payment Method](#transaction-payment-method) | Enum | Not Null | | 155 | | 5 | Bank Name | String(64) | Null | | 156 | | 6 | Account | String(64) | Null | | 157 | | 7 | Card Number | String(128) | Null | | 158 | | 8 | IBAN | String(128) | Null | | 159 | | 9 | Amount | Unsigned Integer | Not Null | | 160 | | 10 | [Status](#transaction-status) | Enum | Not Null | | 161 | | 11 | Reference Number | String(64) | Null | | 162 | | 12 | Details | Text | Null | | 163 | | 13 | Description | Text | Null | | 164 | | 14 | Created At | Timestamp | Current Timestamp | | 165 | 166 | * Store bank transaction response to details(JSON, XML, ...) 167 | 168 | ## Transaction Payment Method 169 | | Name | Description 170 | | ------------- |------------- | 171 | | Card | | 172 | | Account | | 173 | | ACH | | 174 | | IPG | Internet Payment Gateway | 175 | | USSD | | 176 | | Credit | | 177 | | Cash | | 178 | 179 | ## Transaction Status 180 | | Name | Description 181 | | ------------- |------------- | 182 | | Pending | | 183 | | Success | | 184 | | Failed | | 185 | 186 | ## Accounting Transactions 187 | | # | Name | Type | Default | Index | 188 | | ---- | ------------- |------------- | ----- | ----- | 189 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 190 | | 2 | [User Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 191 | | 3 | [Invoice Id](#invoices) | Unsigned Integer | Null | Foreign key on invoices | 192 | | 4 | [Order Id](#orders) | Unsigned Integer | Null | Foreign key on orders | 193 | | 5 | Increase | Unsigned Integer | Null | | 194 | | 6 | Decrease | Unsigned Integer | 0 | | 195 | | 7 | Description | Text | Null | | 196 | | 8 | Created At | Timestamp | Current Timestamp | | 197 | 198 | ## Discounts 199 | | # | Name | Type | Default | Index | 200 | | ---- | ------------- |------------- | ----- | ----- | 201 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 202 | | 2 | [Issuer Id](#users) | Unsigned Integer | Not Null | Foreign key on users | 203 | | 3 | [User Id](#users) | Unsigned Integer | Null | Foreign key on users | 204 | | 4 | Code | String(64) | Not Null | Unique | 205 | | 5 | Title | String(64) | Not Null | | 206 | | 6 | Count | Unsigned Integer | Null | | 207 | | 7 | Used Count | Unsigned Integer | 0 | | 208 | | 8 | Amount | Unsigned Integer | Not Null | | 209 | | 9 | Description | Text | Null | | 210 | | 10 | Started At | Timestamp | Current Timestamp | | 211 | | 11 | Expired At | Timestamp | Null | | 212 | | 12 | Created At | Timestamp | Current Timestamp | | 213 | 214 | ## Files 215 | | # | Name | Type | Default | Index | 216 | | ---- | ------------- |------------- | ----- | ----- | 217 | | 1 | Id | Unsigned Integer | Auto Increment | Primary key | 218 | | 2 | [User Id](#users) | Unsigned Integer | Null | Foreign key on users | 219 | | 3 | [Product Id](#products) | Unsigned Integer | Null | Foreign key on products | 220 | | 4 | Name | String(64) | Not Null | | 221 | | 5 | Type | String(32) | Not Null | MIME type | 222 | | 6 | Path | String(128) | Not Null | Unique | 223 | | 7 | Hash | String(32) | Not Null | | 224 | | 8 | Disabled | Boolean | False | | 225 | | 9 | Priority | Unsigned Integer | 0 | | 226 | | 10 | Created At | Timestamp | Current Timestamp | | 227 | | 11 | Updated At | Timestamp | Current Timestamp | | 228 | | 12 | Deleted At | Timestamp | Null | | 229 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2014_10_05_021330_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('mobile')->index(); 19 | $table->string('token'); 20 | $table->timestamp('created_at')->nullable(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('password_resets'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->text('connection'); 19 | $table->text('queue'); 20 | $table->longText('payload'); 21 | $table->longText('exception'); 22 | $table->timestamp('failed_at')->useCurrent(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('failed_jobs'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024331_create_files_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('user_id')->nullable(); 19 | $table->unsignedBigInteger('product_id')->nullable(); 20 | $table->string('name', 64); 21 | $table->string('type', 32); 22 | $table->string('path', 128)->unique(); 23 | $table->string('hash', 32); 24 | $table->boolean('disabled')->default(false); 25 | $table->unsignedInteger('priority')->default(0); 26 | $table->timestamps(); 27 | $table->softDeletes('deleted_at', 0); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('files'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024333_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('avatar_id')->nullable(); 19 | $table->string('name', 64); 20 | $table->string('username', 32)->unique()->nullable()->index(); 21 | $table->string('email', 128)->unique()->nullable()->index(); 22 | $table->timestamp('email_verified_at')->nullable(); 23 | $table->string('mobile', 16)->unique()->nullable()->index(); 24 | $table->timestamp('mobile_verified_at')->nullable(); 25 | $table->unsignedInteger('balance')->default(0); 26 | $table->string('password'); 27 | $table->boolean('is_admin')->default(false); 28 | $table->boolean('disabled')->default(true); 29 | $table->text('description')->nullable(); 30 | $table->rememberToken(); 31 | $table->timestamps(); 32 | $table->softDeletes('deleted_at', 0); 33 | 34 | $table->foreign('avatar_id')->references('id')->on('files'); 35 | }); 36 | } 37 | 38 | /** 39 | * Reverse the migrations. 40 | * 41 | * @return void 42 | */ 43 | public function down() 44 | { 45 | Schema::dropIfExists('users'); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024524_create_categories_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('parent_id')->nullable(); 19 | $table->string('name', 128); 20 | $table->string('slug', 128)->unique()->index(); 21 | $table->boolean('disabled')->default(false); 22 | $table->timestamps(); 23 | $table->softDeletes('deleted_at', 0); 24 | 25 | $table->foreign('parent_id')->references('id')->on('categories'); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('categories'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024536_create_products_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('category_id')->nullable(); 19 | $table->unsignedBigInteger('thumbnail_id')->nullable(); 20 | $table->string('name', 128); 21 | $table->string('slug', 128)->unique(); 22 | $table->string('summary', 256)->nullable(); 23 | $table->text('description')->nullable(); 24 | $table->unsignedInteger('price'); 25 | $table->unsignedInteger('quantity')->default(0); 26 | $table->unsignedInteger('priority')->default(0); 27 | $table->boolean('disabled')->default(true); 28 | $table->timestamps(); 29 | $table->softDeletes('deleted_at', 0); 30 | 31 | $table->foreign('category_id')->references('id')->on('categories'); 32 | $table->foreign('thumbnail_id')->references('id')->on('files'); 33 | }); 34 | } 35 | 36 | /** 37 | * Reverse the migrations. 38 | * 39 | * @return void 40 | */ 41 | public function down() 42 | { 43 | Schema::dropIfExists('products'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024550_create_comments_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('product_id'); 19 | $table->unsignedBigInteger('reply_to_id')->nullable(); 20 | $table->unsignedBigInteger('author_id')->nullable(); 21 | $table->string('author_name', 64)->nullable(); 22 | $table->text('body'); 23 | $table->timestamps(); 24 | $table->timestamp('published_at')->nullable(); 25 | $table->softDeletes('deleted_at', 0); 26 | 27 | $table->foreign('product_id')->references('id')->on('products'); 28 | $table->foreign('reply_to_id')->references('id')->on('comments'); 29 | $table->foreign('author_id')->references('id')->on('users'); 30 | }); 31 | } 32 | 33 | /** 34 | * Reverse the migrations. 35 | * 36 | * @return void 37 | */ 38 | public function down() 39 | { 40 | Schema::dropIfExists('comments'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024602_create_orders_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('user_id'); 19 | $table->string('tracking_code', 32)->unique(); 20 | $table->unsignedInteger('item_count')->default(0); 21 | $table->unsignedInteger('item_price')->default(0); 22 | $table->unsignedInteger('delivery_cost')->default(0); 23 | $table->unsignedInteger('value_added_tax')->default(0); 24 | $table->unsignedInteger('discount')->default(0); 25 | $table->unsignedInteger('total_price')->default(0); 26 | $table->boolean('pending')->default(true); 27 | $table->boolean('cash_on_delivery')->default(false); 28 | $table->timestamps(); 29 | 30 | $table->foreign('user_id')->references('id')->on('users'); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::dropIfExists('orders'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024615_create_order_items_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('order_id'); 19 | $table->unsignedBigInteger('product_id'); 20 | $table->unsignedInteger('count')->default(0); 21 | $table->unsignedInteger('price')->default(0); 22 | $table->unsignedInteger('total_price')->default(0); 23 | $table->timestamps(); 24 | 25 | $table->foreign('order_id')->references('id')->on('orders'); 26 | $table->foreign('product_id')->references('id')->on('products'); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('order_items'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024630_create_order_status_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('order_id'); 19 | $table->unsignedBigInteger('user_id'); 20 | $table->enum('state', ['waiting', 'paying', 'paid', 'sent', 'canceled']); 21 | $table->text('description')->nullable(); 22 | $table->timestamp('created_at')->useCurrent(); 23 | 24 | $table->foreign('order_id')->references('id')->on('orders'); 25 | $table->foreign('user_id')->references('id')->on('users'); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('order_status'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024645_create_invoices_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('issuer_id'); 19 | $table->unsignedBigInteger('user_id'); 20 | $table->unsignedInteger('amount'); 21 | $table->string('tracking_code', 64)->unique(); 22 | $table->string('slug', 128)->unique(); 23 | $table->string('title', 128); 24 | $table->text('description')->nullable(); 25 | $table->timestamp('paid_at')->nullable(); 26 | $table->timestamp('expired_at')->nullable(); 27 | $table->timestamps(); 28 | 29 | $table->foreign('issuer_id')->references('id')->on('users'); 30 | $table->foreign('user_id')->references('id')->on('users'); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::dropIfExists('invoices'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024659_create_refunds_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('issuer_id'); 19 | $table->unsignedBigInteger('user_id'); 20 | $table->unsignedInteger('amount'); 21 | $table->string('tracking_code', 64)->unique(); 22 | $table->string('slug', 128)->unique(); 23 | $table->string('title', 128); 24 | $table->text('description')->nullable(); 25 | $table->timestamp('paid_at')->nullable(); 26 | $table->timestamp('created_at')->useCurrent(); 27 | 28 | $table->foreign('issuer_id')->references('id')->on('users'); 29 | $table->foreign('user_id')->references('id')->on('users'); 30 | }); 31 | } 32 | 33 | /** 34 | * Reverse the migrations. 35 | * 36 | * @return void 37 | */ 38 | public function down() 39 | { 40 | Schema::dropIfExists('refunds'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024721_create_payment_transactiobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('user_id')->nullable(); 19 | $table->unsignedBigInteger('invoice_id'); 20 | $table->enum('payment_method', ['card', 'account', 'ach', 'ipg', 'ussd', 'credit' , 'cash']); 21 | $table->string('bank_name', 64)->nullable(); 22 | $table->string('account', 64)->nullable(); 23 | $table->string('card_number', 128)->nullable(); 24 | $table->string('iban', 128)->nullable(); 25 | $table->unsignedInteger('amount'); 26 | $table->enum('status', ['pending', 'success', 'failed']); 27 | $table->string('reference_number', 64)->nullable(); 28 | $table->text('details')->nullable(); 29 | $table->text('description')->nullable(); 30 | $table->timestamp('created_at')->useCurrent(); 31 | 32 | $table->foreign('user_id')->references('id')->on('users'); 33 | $table->foreign('invoice_id')->references('id')->on('invoices'); 34 | }); 35 | } 36 | 37 | /** 38 | * Reverse the migrations. 39 | * 40 | * @return void 41 | */ 42 | public function down() 43 | { 44 | Schema::dropIfExists('payment_transactiobs'); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024805_create_accounting_transactions_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('user_id'); 19 | $table->unsignedBigInteger('invoice_id')->nullable(); 20 | $table->unsignedBigInteger('order_id')->nullable(); 21 | $table->unsignedInteger('increase')->nullable(); 22 | $table->unsignedInteger('decrease')->nullable(); 23 | $table->text('description')->nullable(); 24 | $table->timestamp('created_at')->useCurrent(); 25 | 26 | $table->foreign('user_id')->references('id')->on('users'); 27 | $table->foreign('invoice_id')->references('id')->on('invoices'); 28 | $table->foreign('order_id')->references('id')->on('orders'); 29 | }); 30 | } 31 | 32 | /** 33 | * Reverse the migrations. 34 | * 35 | * @return void 36 | */ 37 | public function down() 38 | { 39 | Schema::dropIfExists('accounting_transactions'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_024806_create_discounts_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unsignedBigInteger('issuer_id'); 19 | $table->unsignedBigInteger('user_id')->nullable(); 20 | $table->string('code', 64)->unique(); 21 | $table->string('title', 64); 22 | $table->unsignedInteger('count')->nullable(); 23 | $table->unsignedInteger('used_count')->default(0); 24 | $table->unsignedInteger('amount'); 25 | $table->text('description')->nullable(); 26 | $table->timestamp('started_at'); 27 | $table->timestamp('expired_at')->nullable(); 28 | $table->timestamp('created_at')->useCurrent(); 29 | 30 | $table->foreign('issuer_id')->references('id')->on('users'); 31 | $table->foreign('user_id')->references('id')->on('users'); 32 | }); 33 | } 34 | 35 | /** 36 | * Reverse the migrations. 37 | * 38 | * @return void 39 | */ 40 | public function down() 41 | { 42 | Schema::dropIfExists('discounts'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /shop/laravel/migrations/2020_09_05_044906_add_foreign_to_files_table.php: -------------------------------------------------------------------------------- 1 | foreign('user_id')->references('id')->on('users'); 18 | $table->foreign('product_id')->references('id')->on('products'); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::table('files', function (Blueprint $table) { 30 | $table->dropForeign(['user_id', 'product_id']); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /shop/mysql.sql: -------------------------------------------------------------------------------- 1 | -- Adminer 4.7.5 MySQL dump 2 | 3 | SET NAMES utf8; 4 | SET time_zone = '+00:00'; 5 | SET foreign_key_checks = 0; 6 | SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; 7 | 8 | SET NAMES utf8mb4; 9 | 10 | DROP TABLE IF EXISTS `accounting_transactions`; 11 | CREATE TABLE `accounting_transactions` ( 12 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 13 | `user_id` bigint(20) unsigned NOT NULL, 14 | `invoice_id` bigint(20) unsigned DEFAULT NULL, 15 | `order_id` bigint(20) unsigned DEFAULT NULL, 16 | `increase` int(10) unsigned DEFAULT NULL, 17 | `decrease` int(10) unsigned DEFAULT NULL, 18 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 19 | `created_at` timestamp NOT NULL DEFAULT current_timestamp(), 20 | PRIMARY KEY (`id`), 21 | KEY `accounting_transactions_user_id_foreign` (`user_id`), 22 | KEY `accounting_transactions_invoice_id_foreign` (`invoice_id`), 23 | KEY `accounting_transactions_order_id_foreign` (`order_id`), 24 | CONSTRAINT `accounting_transactions_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`), 25 | CONSTRAINT `accounting_transactions_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`), 26 | CONSTRAINT `accounting_transactions_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 27 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 28 | 29 | 30 | DROP TABLE IF EXISTS `categories`; 31 | CREATE TABLE `categories` ( 32 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 33 | `parent_id` bigint(20) unsigned DEFAULT NULL, 34 | `name` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 35 | `slug` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 36 | `disabled` tinyint(1) NOT NULL DEFAULT 0, 37 | `created_at` timestamp NULL DEFAULT NULL, 38 | `updated_at` timestamp NULL DEFAULT NULL, 39 | `deleted_at` timestamp NULL DEFAULT NULL, 40 | PRIMARY KEY (`id`), 41 | UNIQUE KEY `categories_slug_unique` (`slug`), 42 | KEY `categories_parent_id_foreign` (`parent_id`), 43 | CONSTRAINT `categories_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `categories` (`id`) 44 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 45 | 46 | 47 | DROP TABLE IF EXISTS `comments`; 48 | CREATE TABLE `comments` ( 49 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 50 | `product_id` bigint(20) unsigned NOT NULL, 51 | `reply_to_id` bigint(20) unsigned DEFAULT NULL, 52 | `author_id` bigint(20) unsigned DEFAULT NULL, 53 | `author_name` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 54 | `body` text COLLATE utf8mb4_unicode_ci NOT NULL, 55 | `created_at` timestamp NULL DEFAULT NULL, 56 | `updated_at` timestamp NULL DEFAULT NULL, 57 | `published_at` timestamp NULL DEFAULT NULL, 58 | `deleted_at` timestamp NULL DEFAULT NULL, 59 | PRIMARY KEY (`id`), 60 | KEY `comments_product_id_foreign` (`product_id`), 61 | KEY `comments_reply_to_id_foreign` (`reply_to_id`), 62 | KEY `comments_author_id_foreign` (`author_id`), 63 | CONSTRAINT `comments_author_id_foreign` FOREIGN KEY (`author_id`) REFERENCES `users` (`id`), 64 | CONSTRAINT `comments_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`), 65 | CONSTRAINT `comments_reply_to_id_foreign` FOREIGN KEY (`reply_to_id`) REFERENCES `comments` (`id`) 66 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 67 | 68 | 69 | DROP TABLE IF EXISTS `discounts`; 70 | CREATE TABLE `discounts` ( 71 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 72 | `issuer_id` bigint(20) unsigned NOT NULL, 73 | `user_id` bigint(20) unsigned DEFAULT NULL, 74 | `code` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 75 | `title` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 76 | `count` int(10) unsigned DEFAULT NULL, 77 | `used_count` int(10) unsigned NOT NULL DEFAULT 0, 78 | `amount` int(10) unsigned NOT NULL, 79 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 80 | `started_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), 81 | `expired_at` timestamp NULL DEFAULT NULL, 82 | `created_at` timestamp NOT NULL DEFAULT current_timestamp(), 83 | PRIMARY KEY (`id`), 84 | UNIQUE KEY `discounts_code_unique` (`code`), 85 | KEY `discounts_issuer_id_foreign` (`issuer_id`), 86 | KEY `discounts_user_id_foreign` (`user_id`), 87 | CONSTRAINT `discounts_issuer_id_foreign` FOREIGN KEY (`issuer_id`) REFERENCES `users` (`id`), 88 | CONSTRAINT `discounts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 89 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 90 | 91 | 92 | DROP TABLE IF EXISTS `failed_jobs`; 93 | CREATE TABLE `failed_jobs` ( 94 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 95 | `connection` text COLLATE utf8mb4_unicode_ci NOT NULL, 96 | `queue` text COLLATE utf8mb4_unicode_ci NOT NULL, 97 | `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL, 98 | `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL, 99 | `failed_at` timestamp NOT NULL DEFAULT current_timestamp(), 100 | PRIMARY KEY (`id`) 101 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 102 | 103 | 104 | DROP TABLE IF EXISTS `files`; 105 | CREATE TABLE `files` ( 106 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 107 | `user_id` bigint(20) unsigned DEFAULT NULL, 108 | `product_id` bigint(20) unsigned DEFAULT NULL, 109 | `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 110 | `type` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, 111 | `path` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 112 | `hash` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, 113 | `disabled` tinyint(1) NOT NULL DEFAULT 0, 114 | `priority` int(10) unsigned NOT NULL DEFAULT 0, 115 | `created_at` timestamp NULL DEFAULT NULL, 116 | `updated_at` timestamp NULL DEFAULT NULL, 117 | `deleted_at` timestamp NULL DEFAULT NULL, 118 | PRIMARY KEY (`id`), 119 | UNIQUE KEY `files_path_unique` (`path`), 120 | KEY `files_user_id_foreign` (`user_id`), 121 | KEY `files_product_id_foreign` (`product_id`), 122 | CONSTRAINT `files_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`), 123 | CONSTRAINT `files_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 124 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 125 | 126 | 127 | DROP TABLE IF EXISTS `invoices`; 128 | CREATE TABLE `invoices` ( 129 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 130 | `issuer_id` bigint(20) unsigned NOT NULL, 131 | `user_id` bigint(20) unsigned NOT NULL, 132 | `amount` int(10) unsigned NOT NULL, 133 | `tracking_code` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 134 | `slug` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 135 | `title` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 136 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 137 | `paid_at` timestamp NULL DEFAULT NULL, 138 | `expired_at` timestamp NULL DEFAULT NULL, 139 | `created_at` timestamp NULL DEFAULT NULL, 140 | `updated_at` timestamp NULL DEFAULT NULL, 141 | PRIMARY KEY (`id`), 142 | UNIQUE KEY `invoices_tracking_code_unique` (`tracking_code`), 143 | UNIQUE KEY `invoices_slug_unique` (`slug`), 144 | KEY `invoices_issuer_id_foreign` (`issuer_id`), 145 | KEY `invoices_user_id_foreign` (`user_id`), 146 | CONSTRAINT `invoices_issuer_id_foreign` FOREIGN KEY (`issuer_id`) REFERENCES `users` (`id`), 147 | CONSTRAINT `invoices_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 148 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 149 | 150 | 151 | DROP TABLE IF EXISTS `orders`; 152 | CREATE TABLE `orders` ( 153 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 154 | `user_id` bigint(20) unsigned NOT NULL, 155 | `tracking_code` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, 156 | `item_count` int(10) unsigned NOT NULL DEFAULT 0, 157 | `item_price` int(10) unsigned NOT NULL DEFAULT 0, 158 | `delivery_cost` int(10) unsigned NOT NULL DEFAULT 0, 159 | `value_added_tax` int(10) unsigned NOT NULL DEFAULT 0, 160 | `discount` int(10) unsigned NOT NULL DEFAULT 0, 161 | `total_price` int(10) unsigned NOT NULL DEFAULT 0, 162 | `pending` tinyint(1) NOT NULL DEFAULT 1, 163 | `cash_on_delivery` tinyint(1) NOT NULL DEFAULT 0, 164 | `created_at` timestamp NULL DEFAULT NULL, 165 | `updated_at` timestamp NULL DEFAULT NULL, 166 | PRIMARY KEY (`id`), 167 | UNIQUE KEY `orders_tracking_code_unique` (`tracking_code`), 168 | KEY `orders_user_id_foreign` (`user_id`), 169 | CONSTRAINT `orders_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 170 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 171 | 172 | 173 | DROP TABLE IF EXISTS `order_items`; 174 | CREATE TABLE `order_items` ( 175 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 176 | `order_id` bigint(20) unsigned NOT NULL, 177 | `product_id` bigint(20) unsigned NOT NULL, 178 | `count` int(10) unsigned NOT NULL DEFAULT 0, 179 | `price` int(10) unsigned NOT NULL DEFAULT 0, 180 | `total_price` int(10) unsigned NOT NULL DEFAULT 0, 181 | `created_at` timestamp NULL DEFAULT NULL, 182 | `updated_at` timestamp NULL DEFAULT NULL, 183 | PRIMARY KEY (`id`), 184 | KEY `order_items_order_id_foreign` (`order_id`), 185 | KEY `order_items_product_id_foreign` (`product_id`), 186 | CONSTRAINT `order_items_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`), 187 | CONSTRAINT `order_items_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) 188 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 189 | 190 | 191 | DROP TABLE IF EXISTS `order_status`; 192 | CREATE TABLE `order_status` ( 193 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 194 | `order_id` bigint(20) unsigned NOT NULL, 195 | `user_id` bigint(20) unsigned NOT NULL, 196 | `state` enum('waiting','paying','paid','sent','canceled') COLLATE utf8mb4_unicode_ci NOT NULL, 197 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 198 | `created_at` timestamp NOT NULL DEFAULT current_timestamp(), 199 | PRIMARY KEY (`id`), 200 | KEY `order_status_order_id_foreign` (`order_id`), 201 | KEY `order_status_user_id_foreign` (`user_id`), 202 | CONSTRAINT `order_status_order_id_foreign` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`), 203 | CONSTRAINT `order_status_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 204 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 205 | 206 | 207 | DROP TABLE IF EXISTS `password_resets`; 208 | CREATE TABLE `password_resets` ( 209 | `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 210 | `mobile` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 211 | `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 212 | `created_at` timestamp NULL DEFAULT NULL, 213 | KEY `password_resets_email_index` (`email`), 214 | KEY `password_resets_mobile_index` (`mobile`) 215 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 216 | 217 | 218 | DROP TABLE IF EXISTS `payment_transactiobs`; 219 | CREATE TABLE `payment_transactiobs` ( 220 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 221 | `user_id` bigint(20) unsigned DEFAULT NULL, 222 | `invoice_id` bigint(20) unsigned NOT NULL, 223 | `payment_method` enum('card','account','ach','ipg','ussd','credit','cash') COLLATE utf8mb4_unicode_ci NOT NULL, 224 | `bank_name` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 225 | `account` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 226 | `card_number` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 227 | `iban` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 228 | `amount` int(10) unsigned NOT NULL, 229 | `status` enum('pending','success','failed') COLLATE utf8mb4_unicode_ci NOT NULL, 230 | `reference_number` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 231 | `details` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 232 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 233 | `created_at` timestamp NOT NULL DEFAULT current_timestamp(), 234 | PRIMARY KEY (`id`), 235 | KEY `payment_transactiobs_user_id_foreign` (`user_id`), 236 | KEY `payment_transactiobs_invoice_id_foreign` (`invoice_id`), 237 | CONSTRAINT `payment_transactiobs_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`), 238 | CONSTRAINT `payment_transactiobs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 239 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 240 | 241 | 242 | DROP TABLE IF EXISTS `products`; 243 | CREATE TABLE `products` ( 244 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 245 | `category_id` bigint(20) unsigned DEFAULT NULL, 246 | `thumbnail_id` bigint(20) unsigned DEFAULT NULL, 247 | `name` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 248 | `slug` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 249 | `summary` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 250 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 251 | `price` int(10) unsigned NOT NULL, 252 | `quantity` int(10) unsigned NOT NULL DEFAULT 0, 253 | `priority` int(10) unsigned NOT NULL DEFAULT 0, 254 | `disabled` tinyint(1) NOT NULL DEFAULT 1, 255 | `created_at` timestamp NULL DEFAULT NULL, 256 | `updated_at` timestamp NULL DEFAULT NULL, 257 | `deleted_at` timestamp NULL DEFAULT NULL, 258 | PRIMARY KEY (`id`), 259 | UNIQUE KEY `products_slug_unique` (`slug`), 260 | KEY `products_category_id_foreign` (`category_id`), 261 | KEY `products_thumbnail_id_foreign` (`thumbnail_id`), 262 | CONSTRAINT `products_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`), 263 | CONSTRAINT `products_thumbnail_id_foreign` FOREIGN KEY (`thumbnail_id`) REFERENCES `files` (`id`) 264 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 265 | 266 | 267 | DROP TABLE IF EXISTS `refunds`; 268 | CREATE TABLE `refunds` ( 269 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 270 | `issuer_id` bigint(20) unsigned NOT NULL, 271 | `user_id` bigint(20) unsigned NOT NULL, 272 | `amount` int(10) unsigned NOT NULL, 273 | `tracking_code` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 274 | `slug` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 275 | `title` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL, 276 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 277 | `paid_at` timestamp NULL DEFAULT NULL, 278 | `created_at` timestamp NOT NULL DEFAULT current_timestamp(), 279 | PRIMARY KEY (`id`), 280 | UNIQUE KEY `refunds_tracking_code_unique` (`tracking_code`), 281 | UNIQUE KEY `refunds_slug_unique` (`slug`), 282 | KEY `refunds_issuer_id_foreign` (`issuer_id`), 283 | KEY `refunds_user_id_foreign` (`user_id`), 284 | CONSTRAINT `refunds_issuer_id_foreign` FOREIGN KEY (`issuer_id`) REFERENCES `users` (`id`), 285 | CONSTRAINT `refunds_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) 286 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 287 | 288 | 289 | DROP TABLE IF EXISTS `users`; 290 | CREATE TABLE `users` ( 291 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 292 | `avatar_id` bigint(20) unsigned DEFAULT NULL, 293 | `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, 294 | `username` varchar(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 295 | `email` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 296 | `email_verified_at` timestamp NULL DEFAULT NULL, 297 | `mobile` varchar(16) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 298 | `mobile_verified_at` timestamp NULL DEFAULT NULL, 299 | `balance` int(10) unsigned NOT NULL DEFAULT 0, 300 | `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 301 | `is_admin` tinyint(1) NOT NULL DEFAULT 0, 302 | `disabled` tinyint(1) NOT NULL DEFAULT 1, 303 | `description` text COLLATE utf8mb4_unicode_ci DEFAULT NULL, 304 | `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 305 | `created_at` timestamp NULL DEFAULT NULL, 306 | `updated_at` timestamp NULL DEFAULT NULL, 307 | `deleted_at` timestamp NULL DEFAULT NULL, 308 | PRIMARY KEY (`id`), 309 | UNIQUE KEY `users_username_unique` (`username`), 310 | UNIQUE KEY `users_email_unique` (`email`), 311 | UNIQUE KEY `users_mobile_unique` (`mobile`), 312 | KEY `users_avatar_id_foreign` (`avatar_id`), 313 | CONSTRAINT `users_avatar_id_foreign` FOREIGN KEY (`avatar_id`) REFERENCES `files` (`id`) 314 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 315 | 316 | 317 | -- 2020-09-05 04:59:03 318 | --------------------------------------------------------------------------------