Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change user login to unique #130

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 69 additions & 58 deletions src/database/migration/1637774086085-create_user.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,76 @@
import {MigrationInterface, QueryRunner, Table, TableForeignKey} from "typeorm";
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
} from 'typeorm';

export class createUser1637774086085 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'user',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
},
{
name: 'name',
type: 'varchar',
},
{
name: 'login',
type: 'varchar',
isUnique: true,
danilolutz marked this conversation as resolved.
Show resolved Hide resolved
},
{
name: 'password',
type: 'varchar',
isNullable: true,
},
{
name: 'language',
type: 'varchar',
},
{
name: 'notes',
type: 'varchar',
isNullable: true,
},
{
name: 'document',
type: 'varchar',
},
{
name: 'userTypeId',
type: 'int',
},
],
}),
true
);

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(new Table({
name: "user",
columns: [
{
name: "id",
type: "int",
isPrimary: true
},
{
name: "name",
type: "varchar",
},
{
name: "login",
type: "varchar",
isNullable: true,
},
{
name: "password",
type: "varchar",
isNullable: true,
},
{
name: "language",
type: "varchar",
},
{
name: "notes",
type: "varchar",
isNullable: true,
},
{
name: "document",
type: "varchar",
},
{
name: "userTypeId",
type: "int",
},
]
}), true)
await queryRunner.createForeignKey(
'user',
new TableForeignKey({
columnNames: ['userTypeId'],
referencedColumnNames: ['id'],
referencedTableName: 'user_type',
onDelete: 'CASCADE',
})
);
}

await queryRunner.createForeignKey("user", new TableForeignKey({
columnNames: ["userTypeId"],
referencedColumnNames: ["id"],
referencedTableName: "user_type",
onDelete: "CASCADE"
}));
}
public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable('user');

public async down(queryRunner: QueryRunner): Promise<void> {
const table = await queryRunner.getTable("user");

const userTypeId = table.foreignKeys.find(fk => fk.columnNames.indexOf("userTypeId") !== -1);
await queryRunner.dropForeignKey("user", userTypeId);

await queryRunner.dropTable("user");
}
const userTypeId = table.foreignKeys.find(
(fk) => fk.columnNames.indexOf('userTypeId') !== -1
);
await queryRunner.dropForeignKey('user', userTypeId);

await queryRunner.dropTable('user');
}
}
2 changes: 1 addition & 1 deletion src/electron/database/models/User.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class User {
@Column()
name: string;

@Column({nullable: true})
@Column({unique: true})
login: string;

@Column({nullable: true})
Expand Down