Work in progress on subscriptions
This commit is contained in:
parent
d9211377dd
commit
e73c0a8b28
42 changed files with 1558 additions and 678 deletions
|
@ -34,37 +34,89 @@ exports.up = (knex, Promise) => (async() => {
|
|||
});
|
||||
*/
|
||||
|
||||
// We should check here if the tables already exist and upgrade them to db_schema_version 28, which is the baseline.
|
||||
// For now, we just check whether our DB is up-to-date based on the existing SQL migration infrastructure in Mailtrain.
|
||||
// Original Mailtrain migration is executed before this one. So here we check that the original migration
|
||||
// ended where it should have and we take it from here.
|
||||
const row = await knex('settings').where({key: 'db_schema_version'}).first('value');
|
||||
if (!row || Number(row.value) !== 29) {
|
||||
throw new Error('Unsupported DB schema version: ' + row.value);
|
||||
}
|
||||
|
||||
// We have to update data types of primary keys and related foreign keys. Mailtrain uses unsigned int(11), while
|
||||
// Knex uses unsigned int (which is unsigned int(10) ).
|
||||
// We have to update data types of primary keys and related foreign keys. Mailtrain uses unsigned int(11), while
|
||||
// Knex uses unsigned int (which is unsigned int(10) ).
|
||||
await knex.schema
|
||||
.raw('ALTER TABLE `users` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `attachments` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `attachments` MODIFY `campaign` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `campaign` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `campaign` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `campaign` MODIFY `segment` int unsigned not null')
|
||||
.raw('ALTER TABLE `campaign` MODIFY `subscription` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `campaign_tracker` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `campaign_tracker` MODIFY `subscriber` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `campaigns` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `campaigns` MODIFY `parent` int unsigned default null')
|
||||
.raw('ALTER TABLE `campaigns` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `campaigns` MODIFY `segment` int unsigned default null')
|
||||
.raw('ALTER TABLE `campaigns` MODIFY `template` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `confirmations` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `confirmations` MODIFY `list` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `custom_fields` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `custom_fields` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `custom_fields` MODIFY `group` int unsigned default null')
|
||||
|
||||
.raw('ALTER TABLE `custom_forms` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `custom_forms` MODIFY `list` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `custom_forms_data` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `custom_forms_data` MODIFY `form` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `import_failed` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `import_failed` MODIFY `import` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `importer` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `importer` MODIFY `list` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `links` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `links` MODIFY `campaign` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `lists` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `confirmations` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `custom_fields` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `importer` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `segments` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `triggers` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `custom_forms` MODIFY `list` int unsigned not null');
|
||||
|
||||
/*
|
||||
Remaining foreign keys:
|
||||
-----------------------
|
||||
.raw('ALTER TABLE `queued` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `queued` MODIFY `campaign` int unsigned not null')
|
||||
.raw('ALTER TABLE `queued` MODIFY `subscriber` int unsigned not null')
|
||||
|
||||
links campaign campaigns id
|
||||
segment_rules segment segments id
|
||||
import_failed import importer id
|
||||
rss parent campaigns id
|
||||
attachments campaign campaigns id
|
||||
custom_forms_data form custom_forms id
|
||||
report_template report_template report_templates id
|
||||
*/
|
||||
.raw('ALTER TABLE `reports` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `reports` MODIFY `report_template` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `report_templates` MODIFY `id` int unsigned not null auto_increment')
|
||||
|
||||
.raw('ALTER TABLE `rss` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `rss` MODIFY `parent` int unsigned not null')
|
||||
.raw('ALTER TABLE `rss` MODIFY `campaign` int unsigned default null')
|
||||
|
||||
.raw('ALTER TABLE `segment_rules` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `segment_rules` MODIFY `segment` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `segments` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `segments` MODIFY `list` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `subscription` MODIFY `id` int unsigned not null auto_increment')
|
||||
|
||||
.raw('ALTER TABLE `templates` MODIFY `id` int unsigned not null auto_increment')
|
||||
|
||||
.raw('ALTER TABLE `trigger` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `trigger` MODIFY `subscription` int unsigned not null')
|
||||
|
||||
.raw('ALTER TABLE `triggers` MODIFY `id` int unsigned not null auto_increment')
|
||||
.raw('ALTER TABLE `triggers` MODIFY `list` int unsigned not null')
|
||||
.raw('ALTER TABLE `triggers` MODIFY `source_campaign` int unsigned default null')
|
||||
.raw('ALTER TABLE `triggers` MODIFY `dest_campaign` int unsigned default null')
|
||||
|
||||
.raw('ALTER TABLE `users` MODIFY `id` int unsigned not null auto_increment');
|
||||
})();
|
||||
|
||||
exports.down = (knex, Promise) => (async() => {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
exports.up = (knex, Promise) => (async() => {
|
||||
const entityTypesAddNamespace = ['list', 'custom_form', 'report', 'report_template', 'user'];
|
||||
const entityTypesAddNamespace = ['list', 'custom_form', 'template', 'campaign', 'report', 'report_template', 'user'];
|
||||
await knex.schema.createTable('namespaces', table => {
|
||||
table.increments('id').primary();
|
||||
table.string('name');
|
||||
table.text('description');
|
||||
table.integer('namespace').unsigned().references('namespaces.id').onDelete('CASCADE');
|
||||
table.integer('namespace').unsigned().references('namespaces.id');
|
||||
});
|
||||
|
||||
await knex('namespaces').insert({
|
||||
|
@ -23,7 +23,7 @@ exports.up = (knex, Promise) => (async() => {
|
|||
});
|
||||
|
||||
await knex.schema.table(`${entityType}s`, table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
table.foreign('namespace').references('namespaces.id');
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const shareableEntityTypes = ['list', 'custom_form', 'report', 'report_template', 'namespace'];
|
||||
const shareableEntityTypes = ['list', 'custom_form', 'template', 'campaign', 'report', 'report_template', 'namespace'];
|
||||
|
||||
exports.up = (knex, Promise) => (async() => {
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
exports.up = (knex, Promise) => (async() => {
|
||||
await knex.schema.table('custom_fields', table => {
|
||||
table.foreign('group').references('custom_fields.id').onDelete('CASCADE');
|
||||
});
|
||||
})();
|
||||
|
||||
exports.down = (knex, Promise) => (async() => {
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue