From 53a0238a238fa904fee2f9f0c73055924f598ce7 Mon Sep 17 00:00:00 2001 From: Inamul-hasan-tec Date: Tue, 8 Sep 2026 16:26:41 +0530 Subject: [PATCH] fix(channels): align field mapping schema --- .../channels/mappings/channelMapping.model.js | 2 +- .../models/channelMapping.model.js | 2 +- .../integrations/models/integration.model.js | 4 +- ...07153000-create-channel-field-mappings.cjs | 76 +++++++++++++++++++ 4 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/migrations/20260907153000-create-channel-field-mappings.cjs diff --git a/src/features/channels/mappings/channelMapping.model.js b/src/features/channels/mappings/channelMapping.model.js index 05108c0..9fbd1cf 100644 --- a/src/features/channels/mappings/channelMapping.model.js +++ b/src/features/channels/mappings/channelMapping.model.js @@ -47,7 +47,7 @@ export default (sequelize) => { defaultValue: false, } }, { - tableName: 'channel_mappings', + tableName: 'channel_field_mappings', timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', diff --git a/src/features/integrations/models/channelMapping.model.js b/src/features/integrations/models/channelMapping.model.js index cb1abf5..bfc39c8 100644 --- a/src/features/integrations/models/channelMapping.model.js +++ b/src/features/integrations/models/channelMapping.model.js @@ -2,7 +2,7 @@ import { DataTypes } from 'sequelize'; export default function (sequelize) { const ChannelMapping = sequelize.define( - 'ChannelMapping', + 'IntegrationChannelMapping', { id: { type: DataTypes.UUID, diff --git a/src/features/integrations/models/integration.model.js b/src/features/integrations/models/integration.model.js index 5be74fd..5c35714 100644 --- a/src/features/integrations/models/integration.model.js +++ b/src/features/integrations/models/integration.model.js @@ -67,8 +67,8 @@ export default function (sequelize) { if (models.PublishingRule) { Integration.hasMany(models.PublishingRule, { foreignKey: 'integration_id', as: 'publishingRules' }); } - if (models.ChannelMapping) { - Integration.hasMany(models.ChannelMapping, { foreignKey: 'integration_id', as: 'channelMappings' }); + if (models.IntegrationChannelMapping) { + Integration.hasMany(models.IntegrationChannelMapping, { foreignKey: 'integration_id', as: 'channelMappings' }); } if (models.SyncJob) { Integration.hasMany(models.SyncJob, { foreignKey: 'integration_id', as: 'syncJobs' }); diff --git a/src/migrations/20260907153000-create-channel-field-mappings.cjs b/src/migrations/20260907153000-create-channel-field-mappings.cjs new file mode 100644 index 0000000..d8cb0f5 --- /dev/null +++ b/src/migrations/20260907153000-create-channel-field-mappings.cjs @@ -0,0 +1,76 @@ +'use strict'; + +module.exports = { + async up(queryInterface, Sequelize) { + const existing = await queryInterface.describeTable('channel_field_mappings').catch(() => null); + if (existing) return; + + await queryInterface.createTable('channel_field_mappings', { + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + primaryKey: true, + allowNull: false + }, + tenant_id: { + type: Sequelize.INTEGER, + allowNull: true, + references: { model: 'tenants', key: 'id' }, + onUpdate: 'CASCADE', + onDelete: 'CASCADE' + }, + channel_id: { + type: Sequelize.UUID, + allowNull: false, + references: { model: 'channels', key: 'id' }, + onUpdate: 'CASCADE', + onDelete: 'CASCADE' + }, + pim_attribute_code: { + type: Sequelize.STRING(100), + allowNull: false + }, + channel_field_code: { + type: Sequelize.STRING(100), + allowNull: false + }, + transformation_rule: { + type: Sequelize.STRING(50), + allowNull: false, + defaultValue: 'none' + }, + default_value: { + type: Sequelize.TEXT, + allowNull: true + }, + is_required: { + type: Sequelize.BOOLEAN, + allowNull: false, + defaultValue: false + }, + created_at: { + type: Sequelize.DATE, + allowNull: false, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') + }, + updated_at: { + type: Sequelize.DATE, + allowNull: false, + defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') + } + }); + + await queryInterface.addIndex('channel_field_mappings', ['tenant_id', 'channel_id'], { + name: 'channel_field_mappings_tenant_channel_idx' + }); + await queryInterface.addIndex( + 'channel_field_mappings', + ['tenant_id', 'channel_id', 'pim_attribute_code', 'channel_field_code'], + { name: 'channel_field_mappings_unique', unique: true } + ); + }, + + async down(queryInterface) { + await queryInterface.dropTable('channel_field_mappings'); + } +};