improve login and add migration script

This commit is contained in:
Anika Raemer 2025-09-21 20:01:33 +02:00
parent 1fce467571
commit 099ffb74a1
5 changed files with 106 additions and 9 deletions

View file

@ -0,0 +1,77 @@
import { MigrationInterface, QueryRunner, Table, TableUnique } from "typeorm";
export class CreateUserTable1661234567890 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "user",
columns: [
{
name: "id",
type: "uuid",
isPrimary: true,
isGenerated: true,
generationStrategy: "uuid",
},
{
name: "userName",
type: "varchar",
isNullable: false,
},
{
name: "email",
type: "varchar",
isNullable: false,
},
{
name: "password",
type: "varchar",
isNullable: false,
},
{
name: "firstName",
type: "varchar",
isNullable: true,
},
{
name: "lastName",
type: "varchar",
isNullable: true,
},
{
name: "role",
type: "varchar",
default: "'user'",
},
{
name: "createdAt",
type: "timestamp",
default: "now()",
},
{
name: "updatedAt",
type: "timestamp",
default: "now()",
},
],
}),
true
);
// Add a unique constraint on userName
await queryRunner.createUniqueConstraint(
"user",
new TableUnique({
columnNames: ["userName"],
name: "UQ_user_userName",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
// Drop the unique constraint first
await queryRunner.dropUniqueConstraint("user", "UQ_user_userName");
// Drop the table
await queryRunner.dropTable("user");
}
}