改进 项目模板结构

This commit is contained in:
iVampireSP.com 2023-10-24 14:40:31 +08:00
parent 98556ff09a
commit 748194e1b6
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 35 additions and 11 deletions

View File

@ -20,6 +20,8 @@
}, },
"scripts": { "scripts": {
"start": "ts-node main.ts", "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"
} }
} }

View File

@ -7,12 +7,9 @@ export class User {
id: number id: number
@Column() @Column()
firstName: string name: string
@Column() @Column()
lastName: string email: string
@Column()
age: number
} }

View File

@ -9,20 +9,45 @@ export class CreateUsersTable1698126666203 implements MigrationInterface {
columns: [ columns: [
{ {
name: "id", name: "id",
type: "unsignedint", type: "int",
isPrimary: true, 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({ // auto increment id
// columnNames: [""],
// name: "IDX_USER_FIRST_NAME"
// }) // add index to email
await queryRunner.createIndex(
"users",
new TableIndex({
name: "IDX_USERS_EMAIL",
columnNames: ["email"],
}
))
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable("users")
} }
} }