Skip to content

Commit

Permalink
refactor: adjust user field
Browse files Browse the repository at this point in the history
  • Loading branch information
a20688392 committed Apr 16, 2023
1 parent c19d7d3 commit 0f4a61d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/database/migrations/1681641687260-AdjustUserFieldMigration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AdjustUserFieldMigration1681641687260
implements MigrationInterface
{
name = "AdjustUserFieldMigration1681641687260";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX \`IDX_51b8b26ac168fbe7d6f5653e6c\` ON \`users\``,
);
await queryRunner.query(
`ALTER TABLE \`users\` MODIFY \`password\` varchar(60) NOT NULL`,
);
await queryRunner.query(`ALTER TABLE \`users\` DROP COLUMN \`updateAt\``);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`users\` ADD \`updateAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)`,
);
await queryRunner.query(
`ALTER TABLE \`users\` MODIFY \`password\` varchar(255) NOT NULL`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX \`IDX_51b8b26ac168fbe7d6f5653e6c\` ON \`users\` (\`name\`)`,
);
}
}
10 changes: 4 additions & 6 deletions src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";

@Entity({ name: "users" })
Expand All @@ -15,18 +14,17 @@ export class UserEntity extends BaseEntity {
@Column({ unique: true })
email: string;

@Column({ unique: true })
@Column()
name: string;

@Column({ unique: true })
account: string;

@Column()
@Column({
length: 60,
})
password: string;

@CreateDateColumn()
createAt: Date;

@UpdateDateColumn()
updateAt: Date;
}

0 comments on commit 0f4a61d

Please sign in to comment.