File tree Expand file tree Collapse file tree 10 files changed +296
-15
lines changed Expand file tree Collapse file tree 10 files changed +296
-15
lines changed Original file line number Diff line number Diff line change 1
- 'use strict'
1
+ 'use strict' ;
2
2
3
3
/** @type {import('@adonisjs/lucid/src/Schema') } */
4
- const Schema = use ( 'Schema' )
4
+ const Schema = use ( 'Schema' ) ;
5
5
6
6
class UserSchema extends Schema {
7
- up ( ) {
8
- this . create ( 'users' , ( table ) => {
9
- table . increments ( )
10
- table . string ( 'username' , 80 ) . notNullable ( ) . unique ( )
11
- table . string ( 'email' , 254 ) . notNullable ( ) . unique ( )
12
- table . string ( 'password' , 60 ) . notNullable ( )
13
- table . timestamps ( )
14
- } )
15
- }
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE users(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ username VARCHAR(80) NOT NULL UNIQUE,
12
+ email VARCHAR(254) NOT NULL UNIQUE,
13
+ password VARCHAR(60) NOT NULL,
14
+ f_name VARCHAR(60) NOT NULL,
15
+ l_name VARCHAR(60) NOT NULL,
16
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
17
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
18
+ )
19
+ `
20
+ ) ;
21
+ }
16
22
17
- down ( ) {
18
- this . drop ( ' users')
19
- }
23
+ down ( ) {
24
+ this . raw ( 'DROP TABLE users') ;
25
+ }
20
26
}
21
27
22
- module . exports = UserSchema
28
+ module . exports = UserSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateProductsSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE products(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ sku VARCHAR(100) NOT NULL,
12
+ title VARCHAR(100) NOT NULL,
13
+ description TEXT,
14
+ image_url TEXT,
15
+ color VARCHAR(20) NOT NULL,
16
+ price FLOAT UNSIGNED NOT NULL,
17
+ qty INT UNSIGNED NOT NULL,
18
+ material VARCHAR(100) NOT NULL,
19
+ brand_id INT UNSIGNED NOT NULL,
20
+ type_id INT UNSIGNED NOT NULL,
21
+ user_id INT UNSIGNED NOT NULL,
22
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
23
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
24
+ )
25
+ `
26
+ ) ;
27
+ }
28
+
29
+ down ( ) {
30
+ this . raw ( 'DROP TABLE products' ) ;
31
+ }
32
+ }
33
+
34
+ module . exports = CreateProductsSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateBrandsSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE types(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ title VARCHAR(200) NOT NULL,
12
+ description TEXT,
13
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
14
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
15
+ )
16
+ `
17
+ ) ;
18
+ }
19
+
20
+ down ( ) {
21
+ this . raw ( 'DROP TABLE types' ) ;
22
+ }
23
+ }
24
+
25
+ module . exports = CreateBrandsSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateTagsSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE tags(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ title VARCHAR(200) NOT NULL,
12
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
13
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
14
+ )
15
+ `
16
+ ) ;
17
+ }
18
+
19
+ down ( ) {
20
+ this . raw ( 'DROP TABLE tags' ) ;
21
+ }
22
+ }
23
+
24
+ module . exports = CreateTagsSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateProductTagSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE product_tag(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ product_id INT UNSIGNED NOT NULL,
12
+ tag_id INT UNSIGNED NOT NULL,
13
+ FOREIGN KEY(product_id) REFERENCES products(id),
14
+ FOREIGN KEY(tag_id) REFERENCES tags(id),
15
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
16
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
17
+ )
18
+ `
19
+ ) ;
20
+ }
21
+
22
+ down ( ) {
23
+ this . raw ( 'DROP TABLE product_tag' ) ;
24
+ }
25
+ }
26
+
27
+ module . exports = CreateProductTagSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateAddressesSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE addresses(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ address VARCHAR(100) NOT NULL,
12
+ address_2 VARCHAR(100),
13
+ city VARCHAR(60) NOT NULL,
14
+ country VARCHAR(3) NOT NULL,
15
+ zipcode VARCHAR(5) NOT NULL,
16
+ user_id INT UNSIGNED NOT NULL,
17
+ FOREIGN KEY(user_id) REFERENCES users(id),
18
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
19
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
20
+ )
21
+ `
22
+ ) ;
23
+ }
24
+
25
+ down ( ) {
26
+ this . raw ( 'DROP TABLE addresses' ) ;
27
+ }
28
+ }
29
+
30
+ module . exports = CreateAddressesSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateOrdersSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE orders(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ payment VARCHAR(100),
12
+ total_amount FLOAT UNSIGNED,
13
+ user_id INT UNSIGNED NOT NULL,
14
+ address_id INT UNSIGNED NOT NULL,
15
+ FOREIGN KEY(user_id) REFERENCES users(id),
16
+ FOREIGN KEY(address_id) REFERENCES addresses(id),
17
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
18
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
19
+ )
20
+ `
21
+ ) ;
22
+ }
23
+
24
+ down ( ) {
25
+ this . raw ( 'DROP TABLE orders' ) ;
26
+ }
27
+ }
28
+
29
+ module . exports = CreateOrdersSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateCartSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE carts(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ user_id INT UNSIGNED,
12
+ session_id VARCHAR(100),
13
+ FOREIGN KEY(user_id) REFERENCES users(id),
14
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
15
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
16
+ )
17
+ `
18
+ ) ;
19
+ }
20
+
21
+ down ( ) {
22
+ this . raw ( 'DROP TABLE carts' ) ;
23
+ }
24
+ }
25
+
26
+ module . exports = CreateCartSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class CreateItemsSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `CREATE TABLE items(
10
+ id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
11
+ sku VARCHAR(100) NOT NULL,
12
+ title VARCHAR(100) NOT NULL,
13
+ image_url TEXT,
14
+ price FLOAT UNSIGNED NOT NULL,
15
+ qty INT UNSIGNED NOT NULL,
16
+ brand_id INT UNSIGNED NOT NULL,
17
+ type_id INT UNSIGNED NOT NULL,
18
+ user_id INT UNSIGNED NOT NULL,
19
+ FOREIGN KEY(brand_id) REFERENCES brands(id),
20
+ FOREIGN KEY(type_id) REFERENCES types(id),
21
+ FOREIGN KEY(user_id) REFERENCES users(id),
22
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
23
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
24
+ )
25
+ `
26
+ ) ;
27
+ }
28
+
29
+ down ( ) {
30
+ this . raw ( 'DROP TABLE items' ) ;
31
+ }
32
+ }
33
+
34
+ module . exports = CreateItemsSchema ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /** @type {import('@adonisjs/lucid/src/Schema') } */
4
+ const Schema = use ( 'Schema' ) ;
5
+
6
+ class AddForeignKeyToProductsSchema extends Schema {
7
+ up ( ) {
8
+ this . raw (
9
+ `ALTER TABLE products
10
+ ADD CONSTRAINT fk_brand_id_products
11
+ FOREIGN KEY (brand_id) REFERENCES brands(id)
12
+ `
13
+ ) ;
14
+
15
+ this . raw (
16
+ `ALTER TABLE products
17
+ ADD CONSTRAINT fk_user_id_products
18
+ FOREIGN KEY (user_id) REFERENCES users(id)
19
+ `
20
+ ) ;
21
+ this . raw (
22
+ `ALTER TABLE products
23
+ ADD CONSTRAINT fk_type_id_products
24
+ FOREIGN KEY (type_id) REFERENCES types(id)
25
+ `
26
+ ) ;
27
+ }
28
+
29
+ down ( ) {
30
+ this . raw ( `
31
+ ALTER TABLE products
32
+ DROP FOREIGN KEY fk_brand_id_products
33
+ ` ) ;
34
+
35
+ this . raw ( `
36
+ ALTER TABLE products
37
+ DROP FOREIGN KEY fk_user_id_products
38
+ ` ) ;
39
+ this . raw ( `
40
+ ALTER TABLE products
41
+ DROP FOREIGN KEY fk_type_id_products
42
+ ` ) ;
43
+ }
44
+ }
45
+
46
+ module . exports = AddForeignKeyToProductsSchema ;
You can’t perform that action at this time.
0 commit comments