2025-02-25 06:52:50 +00:00
|
|
|
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from 'typeorm';
|
2021-07-09 09:05:56 +00:00
|
|
|
|
|
|
|
|
export class CreateUsers1625814801417 implements MigrationInterface {
|
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
2025-02-25 06:52:50 +00:00
|
|
|
await queryRunner.createTable(
|
|
|
|
|
new Table({
|
|
|
|
|
name: 'users',
|
|
|
|
|
columns: [
|
|
|
|
|
{
|
|
|
|
|
name: 'id',
|
|
|
|
|
type: 'uuid',
|
|
|
|
|
isGenerated: true,
|
|
|
|
|
default: 'gen_random_uuid()',
|
|
|
|
|
isPrimary: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'first_name',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'last_name',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'email',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isUnique: true,
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'password_digest',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'invitation_token',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'forgot_password_token',
|
|
|
|
|
type: 'varchar',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'organization_id',
|
|
|
|
|
type: 'uuid',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'created_at',
|
|
|
|
|
type: 'timestamp',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
default: 'now()',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'updated_at',
|
|
|
|
|
type: 'timestamp',
|
|
|
|
|
isNullable: true,
|
|
|
|
|
default: 'now()',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
true
|
|
|
|
|
);
|
2021-07-09 09:05:56 +00:00
|
|
|
|
2025-02-25 06:52:50 +00:00
|
|
|
await queryRunner.createForeignKey(
|
|
|
|
|
'users',
|
|
|
|
|
new TableForeignKey({
|
|
|
|
|
columnNames: ['organization_id'],
|
|
|
|
|
referencedColumnNames: ['id'],
|
|
|
|
|
referencedTableName: 'organizations',
|
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
|
})
|
|
|
|
|
);
|
2021-07-09 09:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-25 06:52:50 +00:00
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
2021-07-09 09:05:56 +00:00
|
|
|
}
|