update suggestion
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
TableColumn,
|
||||
TableForeignKey,
|
||||
TableIndex,
|
||||
TableUnique,
|
||||
} from 'typeorm';
|
||||
|
||||
export class MoveSuggestionsToServiceSkill1720900000000
|
||||
implements MigrationInterface
|
||||
{
|
||||
name = 'MoveSuggestionsToServiceSkill1720900000000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const table = await queryRunner.getTable('service_suggestions');
|
||||
|
||||
const serviceFk = table?.foreignKeys.find((fk) =>
|
||||
fk.columnNames.includes('serviceId'),
|
||||
);
|
||||
if (serviceFk) {
|
||||
await queryRunner.dropForeignKey('service_suggestions', serviceFk);
|
||||
}
|
||||
|
||||
const suggestedServiceFk = table?.foreignKeys.find((fk) =>
|
||||
fk.columnNames.includes('suggestedServiceId'),
|
||||
);
|
||||
if (suggestedServiceFk) {
|
||||
await queryRunner.dropForeignKey('service_suggestions', suggestedServiceFk);
|
||||
}
|
||||
|
||||
const uniqueConstraints = table?.uniques ?? [];
|
||||
for (const unique of uniqueConstraints) {
|
||||
await queryRunner.dropUniqueConstraint('service_suggestions', unique);
|
||||
}
|
||||
|
||||
const indexes = table?.indices ?? [];
|
||||
for (const index of indexes) {
|
||||
if (index.columnNames.includes('serviceId') || index.columnNames.includes('serviceSkillId')) {
|
||||
await queryRunner.dropIndex('service_suggestions', index);
|
||||
}
|
||||
}
|
||||
|
||||
if (table?.findColumnByName('serviceId')) {
|
||||
await queryRunner.dropColumn('service_suggestions', 'serviceId');
|
||||
}
|
||||
if (table?.findColumnByName('suggestedServiceId')) {
|
||||
await queryRunner.dropColumn('service_suggestions', 'suggestedServiceId');
|
||||
}
|
||||
|
||||
const refreshedTable = await queryRunner.getTable('service_suggestions');
|
||||
|
||||
if (!refreshedTable?.findColumnByName('serviceSkillId')) {
|
||||
await queryRunner.addColumn(
|
||||
'service_suggestions',
|
||||
new TableColumn({
|
||||
name: 'serviceSkillId',
|
||||
type: 'uuid',
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (!refreshedTable?.findColumnByName('suggestedServiceSkillId')) {
|
||||
await queryRunner.addColumn(
|
||||
'service_suggestions',
|
||||
new TableColumn({
|
||||
name: 'suggestedServiceSkillId',
|
||||
type: 'uuid',
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'service_suggestions',
|
||||
new TableForeignKey({
|
||||
columnNames: ['serviceSkillId'],
|
||||
referencedTableName: 'service_skills',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'service_suggestions',
|
||||
new TableForeignKey({
|
||||
columnNames: ['suggestedServiceSkillId'],
|
||||
referencedTableName: 'service_skills',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createUniqueConstraint(
|
||||
'service_suggestions',
|
||||
new TableUnique({
|
||||
name: 'UQ_service_suggestions_serviceSkillId_suggestedServiceSkillId',
|
||||
columnNames: ['serviceSkillId', 'suggestedServiceSkillId'],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'service_suggestions',
|
||||
new TableIndex({
|
||||
name: 'IDX_service_suggestions_serviceSkillId_isActive_displayPriority',
|
||||
columnNames: ['serviceSkillId', 'isActive', 'displayPriority'],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const table = await queryRunner.getTable('service_suggestions');
|
||||
|
||||
for (const fk of table?.foreignKeys ?? []) {
|
||||
if (
|
||||
fk.columnNames.includes('serviceSkillId') ||
|
||||
fk.columnNames.includes('suggestedServiceSkillId')
|
||||
) {
|
||||
await queryRunner.dropForeignKey('service_suggestions', fk);
|
||||
}
|
||||
}
|
||||
|
||||
await queryRunner.dropUniqueConstraint(
|
||||
'service_suggestions',
|
||||
'UQ_service_suggestions_serviceSkillId_suggestedServiceSkillId',
|
||||
);
|
||||
await queryRunner.dropIndex(
|
||||
'service_suggestions',
|
||||
'IDX_service_suggestions_serviceSkillId_isActive_displayPriority',
|
||||
);
|
||||
await queryRunner.dropColumn('service_suggestions', 'serviceSkillId');
|
||||
await queryRunner.dropColumn('service_suggestions', 'suggestedServiceSkillId');
|
||||
|
||||
await queryRunner.addColumn(
|
||||
'service_suggestions',
|
||||
new TableColumn({ name: 'serviceId', type: 'uuid' }),
|
||||
);
|
||||
await queryRunner.addColumn(
|
||||
'service_suggestions',
|
||||
new TableColumn({ name: 'suggestedServiceId', type: 'uuid' }),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'service_suggestions',
|
||||
new TableForeignKey({
|
||||
columnNames: ['serviceId'],
|
||||
referencedTableName: 'services',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createForeignKey(
|
||||
'service_suggestions',
|
||||
new TableForeignKey({
|
||||
columnNames: ['suggestedServiceId'],
|
||||
referencedTableName: 'services',
|
||||
referencedColumnNames: ['id'],
|
||||
onDelete: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createUniqueConstraint(
|
||||
'service_suggestions',
|
||||
new TableUnique({
|
||||
name: 'UQ_service_suggestions_serviceId_suggestedServiceId',
|
||||
columnNames: ['serviceId', 'suggestedServiceId'],
|
||||
}),
|
||||
);
|
||||
|
||||
await queryRunner.createIndex(
|
||||
'service_suggestions',
|
||||
new TableIndex({
|
||||
name: 'IDX_service_suggestions_serviceId_isActive_displayPriority',
|
||||
columnNames: ['serviceId', 'isActive', 'displayPriority'],
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user