改进 项目模板结构
This commit is contained in:
parent
98556ff09a
commit
748194e1b6
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user