sent messages
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
Table,
|
||||
TableForeignKey,
|
||||
TableIndex,
|
||||
} from 'typeorm';
|
||||
|
||||
export class AddSentMessages1720200000000 implements MigrationInterface {
|
||||
name = 'AddSentMessages1720200000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE TYPE "sent_messages_status_enum" AS ENUM(
|
||||
'pending',
|
||||
'sent',
|
||||
'failed'
|
||||
)
|
||||
`);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'sent_messages',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
type: 'uuid',
|
||||
isPrimary: true,
|
||||
generationStrategy: 'uuid',
|
||||
default: 'gen_random_uuid()',
|
||||
},
|
||||
{ name: 'salonId', type: 'uuid' },
|
||||
{ name: 'customerId', type: 'uuid', isNullable: true },
|
||||
{ name: 'reserveId', type: 'uuid', isNullable: true },
|
||||
{ name: 'mobile', type: 'varchar', length: '11' },
|
||||
{ name: 'body', type: 'text' },
|
||||
{
|
||||
name: 'status',
|
||||
type: 'sent_messages_status_enum',
|
||||
default: `'pending'`,
|
||||
},
|
||||
{ name: 'createdAt', type: 'timestamp', default: 'now()' },
|
||||
{ name: 'updatedAt', type: 'timestamp', default: 'now()' },
|
||||
],
|
||||
}),
|
||||
true,
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'sent_messages',
|
||||
new TableForeignKey({
|
||||
columnNames: ['salonId'],
|
||||
referencedTableName: 'salons',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'sent_messages',
|
||||
new TableForeignKey({
|
||||
columnNames: ['customerId'],
|
||||
referencedTableName: 'customers',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'SET NULL',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'sent_messages',
|
||||
new TableForeignKey({
|
||||
columnNames: ['reserveId'],
|
||||
referencedTableName: 'reserves',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'SET NULL',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'sent_messages',
|
||||
new TableIndex({
|
||||
name: 'IDX_sent_messages_salonId_createdAt',
|
||||
columnNames: ['salonId', 'createdAt'],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'sent_messages',
|
||||
new TableIndex({
|
||||
name: 'IDX_sent_messages_customerId',
|
||||
columnNames: ['customerId'],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'sent_messages',
|
||||
new TableIndex({
|
||||
name: 'IDX_sent_messages_reserveId',
|
||||
columnNames: ['reserveId'],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'sent_messages',
|
||||
new TableIndex({
|
||||
name: 'IDX_sent_messages_status',
|
||||
columnNames: ['status'],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('sent_messages', true);
|
||||
await queryRunner.query(`DROP TYPE "sent_messages_status_enum"`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user