Added subscription changed trigger

Is very useful if some subscription data is updated by API and you want to trigger after that because segments (filters) have changed.
This commit is contained in:
Gernot Pansy 2019-10-10 12:35:57 +02:00
parent ed2655b78e
commit e2a69ef76d
8 changed files with 21 additions and 3 deletions

View file

@ -195,6 +195,7 @@ async function create(context, entity) {
' `latest_open` timestamp NULL DEFAULT NULL,\n' +
' `latest_click` timestamp NULL DEFAULT NULL,\n' +
' `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
' `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
' PRIMARY KEY (`id`),\n' +
' UNIQUE KEY `hash_email` (`hash_email`),\n' +
' UNIQUE KEY `cid` (`cid`),\n' +
@ -204,7 +205,8 @@ async function create(context, entity) {
' KEY `is_test` (`is_test`),\n' +
' KEY `latest_open` (`latest_open`),\n' +
' KEY `latest_click` (`latest_click`),\n' +
' KEY `created` (`created`)\n' +
' KEY `created` (`created`),\n' +
' KEY `updated` (`updated`)\n' +
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n');
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'list', entityId: id });

View file

@ -616,6 +616,7 @@ async function _update(tx, listId, groupedFieldsMap, existing, filteredEntity) {
}
if (filteredEntity) {
filteredEntity.updated = new Date();
await tx(getSubscriptionTableName(listId)).where('id', existing.id).update(filteredEntity);
if ('status' in filteredEntity) {

View file

@ -0,0 +1,10 @@
exports.up = (knex, Promise) => (async() => {
const lists = await knex('lists');
for (const list of lists) {
await knex.schema.raw('ALTER TABLE `subscription__' + list.id + '` ADD COLUMN `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `created`');
await knex.schema.raw('CREATE INDEX updated ON `subscription__' + list.id + '` (`updated`)');
}
})();
exports.down = (knex, Promise) => (async() => {
})();