customers

This commit is contained in:
2026-07-07 20:35:14 +03:30
parent 94367752a2
commit 9fdc81bff1
11 changed files with 720 additions and 3 deletions
@@ -0,0 +1,89 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
TableUnique,
} from 'typeorm';
export class AddSalonCustomers1721100000000 implements MigrationInterface {
name = 'AddSalonCustomers1721100000000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'salon_customers',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'gen_random_uuid()',
},
{ name: 'salonId', type: 'uuid' },
{ name: 'customerId', type: 'uuid' },
{ name: 'createdAt', type: 'timestamp', default: 'now()' },
{ name: 'updatedAt', type: 'timestamp', default: 'now()' },
],
}),
true,
);
await queryRunner.createForeignKey(
'salon_customers',
new TableForeignKey({
columnNames: ['salonId'],
referencedTableName: 'salons',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createForeignKey(
'salon_customers',
new TableForeignKey({
columnNames: ['customerId'],
referencedTableName: 'customers',
referencedColumnNames: ['id'],
onDelete: 'CASCADE',
}),
);
await queryRunner.createIndex(
'salon_customers',
new TableIndex({
name: 'IDX_salon_customers_salonId',
columnNames: ['salonId'],
}),
);
await queryRunner.createIndex(
'salon_customers',
new TableIndex({
name: 'IDX_salon_customers_customerId',
columnNames: ['customerId'],
}),
);
await queryRunner.createUniqueConstraint(
'salon_customers',
new TableUnique({
name: 'UQ_salon_customers_salonId_customerId',
columnNames: ['salonId', 'customerId'],
}),
);
await queryRunner.query(`
INSERT INTO salon_customers ("salonId", "customerId", "createdAt", "updatedAt")
SELECT DISTINCT "salonId", "customerId", NOW(), NOW()
FROM reserves
ON CONFLICT ("salonId", "customerId") DO NOTHING
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('salon_customers');
}
}