改进 项目模板结构
This commit is contained in:
parent
98556ff09a
commit
748194e1b6
@ -20,6 +20,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "ts-node main.ts",
|
||||
"typeorm": "typeorm-ts-node-commonjs"
|
||||
"typeorm": "typeorm-ts-node-commonjs",
|
||||
"migrate": "typeorm-ts-node-commonjs migration:run -d src/config/database.ts",
|
||||
"migrate:rollback": "typeorm-ts-node-commonjs migration:revert -d src/config/database.ts"
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,9 @@ export class User {
|
||||
id: number
|
||||
|
||||
@Column()
|
||||
firstName: string
|
||||
name: string
|
||||
|
||||
@Column()
|
||||
lastName: string
|
||||
|
||||
@Column()
|
||||
age: number
|
||||
email: string
|
||||
|
||||
}
|
||||
|
@ -9,20 +9,45 @@ export class CreateUsersTable1698126666203 implements MigrationInterface {
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
type: "unsignedint",
|
||||
type: "int",
|
||||
isPrimary: true,
|
||||
unsigned: true,
|
||||
|
||||
// auto increment
|
||||
isGenerated: true,
|
||||
generationStrategy: "increment",
|
||||
},
|
||||
{
|
||||
name: "name",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "email",
|
||||
type: "varchar",
|
||||
length: "255",
|
||||
isNullable: false,
|
||||
}
|
||||
]
|
||||
})
|
||||
)
|
||||
|
||||
// await queryRunner.createIndex("users", new TableIndex({
|
||||
// columnNames: [""],
|
||||
// name: "IDX_USER_FIRST_NAME"
|
||||
// })
|
||||
// auto increment id
|
||||
|
||||
|
||||
// add index to email
|
||||
await queryRunner.createIndex(
|
||||
"users",
|
||||
new TableIndex({
|
||||
name: "IDX_USERS_EMAIL",
|
||||
columnNames: ["email"],
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable("users")
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user