Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ghost/core/core/server/data/exporter/table-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const BACKUP_TABLES = [
'recommendation_click_events',
'recommendation_subscribe_events',
'outbox',
'gifts'
'gifts',
'welcome_email_automations',
'welcome_email_automated_emails'
];

// NOTE: exposing only tables which are going to be included in a "default" export file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const logging = require('@tryghost/logging');
const {commands} = require('../../../schema');
const {createNonTransactionalMigration} = require('../../utils');

// The default names are too long.
const WELCOME_EMAIL_AUTOMATED_EMAILS_AUTOMATION_FK = 'weae_automation_id_foreign';
const WELCOME_EMAIL_AUTOMATED_EMAILS_NEXT_EMAIL_FK = 'weae_next_email_id_foreign';

const welcomeEmailAutomationsSpec = {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'inactive', validations: {isIn: [['active', 'inactive']]}},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
};

const welcomeEmailAutomatedEmailsSpec = {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'welcome_email_automations.id', constraintName: WELCOME_EMAIL_AUTOMATED_EMAILS_AUTOMATION_FK, cascadeDelete: true},
next_welcome_email_automated_email_id: {type: 'string', maxlength: 24, nullable: true, references: 'welcome_email_automated_emails.id', constraintName: WELCOME_EMAIL_AUTOMATED_EMAILS_NEXT_EMAIL_FK, cascadeDelete: false},
delay_days: {type: 'integer', nullable: false},
subject: {type: 'string', maxlength: 300, nullable: false},
lexical: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
sender_name: {type: 'string', maxlength: 191, nullable: true},
sender_email: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}},
sender_reply_to: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}},
email_design_setting_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_design_settings.id'},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
};

module.exports = createNonTransactionalMigration(
async function up(knex) {
const automationsExists = await knex.schema.hasTable('welcome_email_automations');
if (automationsExists) {
logging.warn('Skipping creating table welcome_email_automations - already exists');
} else {
logging.info('Creating table: welcome_email_automations');
await commands.createTable('welcome_email_automations', knex, welcomeEmailAutomationsSpec);
}

const automatedEmailsExists = await knex.schema.hasTable('welcome_email_automated_emails');
if (automatedEmailsExists) {
logging.warn('Skipping creating table welcome_email_automated_emails - already exists');
} else {
logging.info('Creating table: welcome_email_automated_emails');
await commands.createTable('welcome_email_automated_emails', knex, welcomeEmailAutomatedEmailsSpec);
}
},

async function down(knex) {
logging.info('Dropping table: welcome_email_automated_emails');
await commands.deleteTable('welcome_email_automated_emails', knex);

logging.info('Dropping table: welcome_email_automations');
await commands.deleteTable('welcome_email_automations', knex);
}
);
22 changes: 22 additions & 0 deletions ghost/core/core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,28 @@ module.exports = {
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
welcome_email_automations: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'inactive', validations: {isIn: [['active', 'inactive']]}},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
welcome_email_automated_emails: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'welcome_email_automations.id', constraintName: 'weae_automation_id_foreign', cascadeDelete: true},
next_welcome_email_automated_email_id: {type: 'string', maxlength: 24, nullable: true, references: 'welcome_email_automated_emails.id', constraintName: 'weae_next_email_id_foreign', cascadeDelete: false},
delay_days: {type: 'integer', nullable: false},
subject: {type: 'string', maxlength: 300, nullable: false},
lexical: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
sender_name: {type: 'string', maxlength: 191, nullable: true},
sender_email: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}},
sender_reply_to: {type: 'string', maxlength: 191, nullable: true, validations: {isEmail: true}},
email_design_setting_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_design_settings.id'},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
automated_emails: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'inactive', validations: {isIn: [['active', 'inactive']]}},
Expand Down
4 changes: 3 additions & 1 deletion ghost/core/test/integration/exporter/exporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ describe('Exporter', function () {
'tags',
'tokens',
'users',
'webhooks'
'webhooks',
'welcome_email_automated_emails',
'welcome_email_automations'
];

assertExists(exportData);
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/test/unit/server/data/schema/integrity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '6c63467aae47d05d9a67e695905f08d4';
const currentSchemaHash = '62c59d1ad8e4b75e2e69e89ce6c3222c';
const currentFixturesHash = '2f86ab1e3820e86465f9ad738dd0ee93';
const currentSettingsHash = 'a102b80d2ab0cd92325ed007c94d7da6';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
Expand Down
Loading