fix(channels): align field mapping schema
This commit is contained in:
@@ -47,7 +47,7 @@ export default (sequelize) => {
|
||||
defaultValue: false,
|
||||
}
|
||||
}, {
|
||||
tableName: 'channel_mappings',
|
||||
tableName: 'channel_field_mappings',
|
||||
timestamps: true,
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at',
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DataTypes } from 'sequelize';
|
||||
|
||||
export default function (sequelize) {
|
||||
const ChannelMapping = sequelize.define(
|
||||
'ChannelMapping',
|
||||
'IntegrationChannelMapping',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
|
||||
@@ -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' });
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user