Skip to content

Commit e207cb1

Browse files
committed
fix: update minor
1 parent ce250fd commit e207cb1

17 files changed

+260
-271
lines changed

src/app/database/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { env } from '~/config/env'
22

3-
module.exports = {
3+
export default {
44
username: env.SEQUELIZE_USERNAME,
55
password: env.SEQUELIZE_PASSWORD,
66
database: env.SEQUELIZE_DATABASE,

src/app/database/connection.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ import 'reflect-metadata'
33
import { Sequelize, type SequelizeOptions } from 'sequelize-typescript'
44
import { env } from '~/config/env'
55
import { logger } from '~/config/logger'
6+
import { __dirname } from '~/lib/string'
67

7-
const connectionType: 'postgres' | 'mysql' = 'postgres'
8+
type ConnectionType = 'postgres' | 'mysql'
89

910
const sequelizeOptions: SequelizeOptions = {
10-
dialect: env.SEQUELIZE_CONNECTION as typeof connectionType,
11+
dialect: env.SEQUELIZE_CONNECTION as ConnectionType,
1112
host: env.SEQUELIZE_HOST,
1213
port: env.SEQUELIZE_PORT,
1314
username: env.SEQUELIZE_USERNAME,
1415
password: env.SEQUELIZE_PASSWORD,
1516
database: env.SEQUELIZE_DATABASE,
1617
logQueryParameters: env.SEQUELIZE_LOGGING,
1718
timezone: env.SEQUELIZE_TIMEZONE,
18-
models: [`${__dirname}/entity`],
19+
models: [`${__dirname}/dist/app/database/entity`],
1920
}
2021

2122
const sequelize = new Sequelize({ ...sequelizeOptions })
@@ -28,7 +29,7 @@ export const initDatabase = async () => {
2829

2930
// not recommended when running in production mode
3031
if (env.SEQUELIZE_SYNC) {
31-
await sequelize.sync({ logging: true, force: true })
32+
await sequelize.sync({ force: true })
3233
logger.info(`Sync database successfully`)
3334
}
3435
} catch (error: any) {

src/app/database/entity/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface IBaseEntity {
1616
}
1717

1818
@Table({ tableName: 'base' })
19-
export abstract class Base extends Model {
19+
export class BaseSchema extends Model {
2020
@IsUUID(4)
2121
@PrimaryKey
2222
@Column({ type: DataType.UUID, defaultValue: DataType.UUIDV4 })

src/app/database/entity/role.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Column, DeletedAt, Table } from 'sequelize-typescript'
2-
import { Base } from './base'
2+
import { BaseSchema } from './base'
33

44
@Table({ tableName: 'role', paranoid: true })
5-
export class Role extends Base {
5+
export class Role extends BaseSchema {
66
@DeletedAt
77
@Column
88
deleted_at?: Date

src/app/database/entity/session.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { BelongsTo, Column, DataType, ForeignKey, IsUUID, Table } from 'sequelize-typescript'
22
import { User } from './user'
3-
import { Base } from './base'
3+
import { BaseSchema } from './base'
44

55
@Table({ tableName: 'session' })
6-
export class Session extends Base {
6+
export class Session extends BaseSchema {
77
@IsUUID(4)
88
@ForeignKey(() => User)
99
@Column({

src/app/database/entity/upload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Column, DataType, DeletedAt, Table } from 'sequelize-typescript'
2-
import { Base } from './base'
2+
import { BaseSchema } from './base'
33

44
@Table({ tableName: 'upload', paranoid: true })
5-
export class Upload extends Base {
5+
export class Upload extends BaseSchema {
66
@DeletedAt
77
@Column
88
deleted_at?: Date

src/app/database/entity/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'sequelize-typescript'
1616
import Hashing from '~/config/hashing'
1717
import { createPasswordSchema } from '../schema/user'
18-
import { Base } from './base'
18+
import { BaseSchema } from './base'
1919
import { Role } from './role'
2020
import { Session } from './session'
2121
import { Upload } from './upload'
@@ -31,7 +31,7 @@ const hashing = new Hashing()
3131
withPassword: {},
3232
}))
3333
@Table({ tableName: 'user', paranoid: true })
34-
export class User extends Base {
34+
export class User extends BaseSchema {
3535
@DeletedAt
3636
@Column
3737
deleted_at?: Date

src/app/database/migration/20250405075558-table-role.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,32 @@
33
import { DataTypes, QueryInterface } from 'sequelize'
44

55
/** @type {import('sequelize-cli').Migration} */
6-
module.exports = {
7-
async up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
8-
await queryInterface.createTable('role', {
9-
id: {
10-
allowNull: false,
11-
primaryKey: true,
12-
type: Sequelize.UUID,
13-
defaultValue: Sequelize.UUIDV4,
14-
},
15-
created_at: {
16-
allowNull: false,
17-
type: Sequelize.DATE,
18-
},
19-
updated_at: {
20-
allowNull: false,
21-
type: Sequelize.DATE,
22-
},
23-
deleted_at: {
24-
type: Sequelize.DATE,
25-
},
26-
name: {
27-
allowNull: false,
28-
type: Sequelize.STRING,
29-
},
30-
})
31-
},
6+
export async function up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
7+
await queryInterface.createTable('role', {
8+
id: {
9+
allowNull: false,
10+
primaryKey: true,
11+
type: Sequelize.UUID,
12+
defaultValue: Sequelize.UUIDV4,
13+
},
14+
created_at: {
15+
allowNull: false,
16+
type: Sequelize.DATE,
17+
},
18+
updated_at: {
19+
allowNull: false,
20+
type: Sequelize.DATE,
21+
},
22+
deleted_at: {
23+
type: Sequelize.DATE,
24+
},
25+
name: {
26+
allowNull: false,
27+
type: Sequelize.STRING,
28+
},
29+
})
30+
}
3231

33-
async down(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
34-
await queryInterface.dropTable('role')
35-
},
32+
export async function down(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
33+
await queryInterface.dropTable('role')
3634
}

src/app/database/migration/20250405075716-table-user.ts

Lines changed: 75 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,83 @@
33
import { DataTypes, QueryInterface } from 'sequelize'
44

55
/** @type {import('sequelize-cli').Migration} */
6-
module.exports = {
7-
async up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
8-
await queryInterface.createTable('user', {
9-
id: {
10-
allowNull: false,
11-
primaryKey: true,
12-
type: Sequelize.UUID,
13-
defaultValue: Sequelize.UUIDV4,
6+
export async function up(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
7+
await queryInterface.createTable('user', {
8+
id: {
9+
allowNull: false,
10+
primaryKey: true,
11+
type: Sequelize.UUID,
12+
defaultValue: Sequelize.UUIDV4,
13+
},
14+
created_at: {
15+
allowNull: false,
16+
type: Sequelize.DATE,
17+
},
18+
updated_at: {
19+
allowNull: false,
20+
type: Sequelize.DATE,
21+
},
22+
deleted_at: {
23+
type: Sequelize.DATE,
24+
},
25+
fullname: {
26+
allowNull: false,
27+
type: Sequelize.STRING,
28+
},
29+
email: {
30+
allowNull: false,
31+
type: Sequelize.STRING,
32+
},
33+
password: {
34+
allowNull: false,
35+
type: Sequelize.STRING,
36+
},
37+
phone: {
38+
type: Sequelize.STRING('20'),
39+
},
40+
token_verify: {
41+
type: Sequelize.TEXT,
42+
},
43+
address: {
44+
type: Sequelize.TEXT,
45+
},
46+
is_active: {
47+
allowNull: false,
48+
defaultValue: false,
49+
type: Sequelize.BOOLEAN,
50+
},
51+
is_blocked: {
52+
allowNull: false,
53+
defaultValue: false,
54+
type: Sequelize.BOOLEAN,
55+
},
56+
role_id: {
57+
allowNull: false,
58+
type: Sequelize.UUID,
59+
defaultValue: Sequelize.UUIDV4,
60+
references: {
61+
model: 'role',
62+
key: 'id',
1463
},
15-
created_at: {
16-
allowNull: false,
17-
type: Sequelize.DATE,
64+
},
65+
upload_id: {
66+
allowNull: true,
67+
type: Sequelize.UUID,
68+
defaultValue: Sequelize.UUIDV4,
69+
references: {
70+
model: 'upload',
71+
key: 'id',
1872
},
19-
updated_at: {
20-
allowNull: false,
21-
type: Sequelize.DATE,
22-
},
23-
deleted_at: {
24-
type: Sequelize.DATE,
25-
},
26-
fullname: {
27-
allowNull: false,
28-
type: Sequelize.STRING,
29-
},
30-
email: {
31-
allowNull: false,
32-
type: Sequelize.STRING,
33-
},
34-
password: {
35-
allowNull: false,
36-
type: Sequelize.STRING,
37-
},
38-
phone: {
39-
type: Sequelize.STRING('20'),
40-
},
41-
token_verify: {
42-
type: Sequelize.TEXT,
43-
},
44-
address: {
45-
type: Sequelize.TEXT,
46-
},
47-
is_active: {
48-
allowNull: false,
49-
defaultValue: false,
50-
type: Sequelize.BOOLEAN,
51-
},
52-
is_blocked: {
53-
allowNull: false,
54-
defaultValue: false,
55-
type: Sequelize.BOOLEAN,
56-
},
57-
role_id: {
58-
allowNull: false,
59-
type: Sequelize.UUID,
60-
defaultValue: Sequelize.UUIDV4,
61-
references: {
62-
model: 'role',
63-
key: 'id',
64-
},
65-
},
66-
upload_id: {
67-
allowNull: true,
68-
type: Sequelize.UUID,
69-
defaultValue: Sequelize.UUIDV4,
70-
references: {
71-
model: 'upload',
72-
key: 'id',
73-
},
74-
},
75-
})
73+
},
74+
})
7675

77-
await queryInterface.addConstraint('user', {
78-
type: 'unique',
79-
fields: ['email'],
80-
name: 'UNIQUE_USERS_EMAIL',
81-
})
82-
},
76+
await queryInterface.addConstraint('user', {
77+
type: 'unique',
78+
fields: ['email'],
79+
name: 'UNIQUE_USERS_EMAIL',
80+
})
81+
}
8382

84-
async down(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
85-
await queryInterface.dropTable('user')
86-
},
83+
export async function down(queryInterface: QueryInterface, Sequelize: typeof DataTypes) {
84+
await queryInterface.dropTable('user')
8785
}

0 commit comments

Comments
 (0)