Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion ghost/admin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ghost-admin",
"version": "6.36.1-rc.0",
"version": "6.37.0-rc.0",
"description": "Ember.js admin client for Ghost",
"author": "Ghost Foundation",
"homepage": "http://ghost.org",
Expand Down
12 changes: 6 additions & 6 deletions ghost/core/core/server/api/endpoints/automated-emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const messages = {
};

// NOTE: This file is in a transitionary state. The `automated_emails` database table was split into
// `welcome_email_automations` (automation metadata: status, name, slug) and
// `automations` (automation metadata: status, name, slug) and
// `welcome_email_automated_emails` (email content: subject, lexical, sender fields). This controller
// acts as a facade that joins/splits data between those two models while preserving the original
// `automated_emails` API shape externally.
Expand Down Expand Up @@ -51,7 +51,7 @@ const controller = {
],
permissions: true,
async query(frame) {
const result = await models.WelcomeEmailAutomation.findPage({
const result = await models.Automation.findPage({
...frame.options,
withRelated: ['welcomeEmailAutomatedEmail']
});
Expand All @@ -75,7 +75,7 @@ const controller = {
],
permissions: true,
async query(frame) {
const model = await models.WelcomeEmailAutomation.findOne(frame.data, {
const model = await models.Automation.findOne(frame.data, {
...frame.options,
withRelated: ['welcomeEmailAutomatedEmail']
});
Expand All @@ -102,7 +102,7 @@ const controller = {
const automationData = _.pick(data, AUTOMATION_FIELDS);

return models.Base.transaction(async (transacting) => {
const automation = await models.WelcomeEmailAutomation.add(automationData, {...frame.options, transacting});
const automation = await models.Automation.add(automationData, {...frame.options, transacting});
const email = await models.WelcomeEmailAutomatedEmail.add(
{
...emailData,
Expand Down Expand Up @@ -139,7 +139,7 @@ const controller = {
const automationData = _.pick(data, AUTOMATION_FIELDS);

return models.Base.transaction(async (transacting) => {
let automation = await models.WelcomeEmailAutomation.findOne({id: frame.options.id}, {
let automation = await models.Automation.findOne({id: frame.options.id}, {
transacting,
withRelated: ['welcomeEmailAutomatedEmail']
});
Expand All @@ -159,7 +159,7 @@ const controller = {
}

if (Object.keys(automationData).length > 0) {
automation = await models.WelcomeEmailAutomation.edit(automationData, {
automation = await models.Automation.edit(automationData, {
...frame.options,
transacting
});
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/core/server/api/endpoints/automations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const controller = {
},
permissions: true,
async query() {
const automations = await models.WelcomeEmailAutomation.findAll();
const automations = await models.Automation.findAll();
return {
data: automations.map(automation => ({
id: automation.get('id'),
Expand Down
2 changes: 1 addition & 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,7 @@ const BACKUP_TABLES = [
'recommendation_subscribe_events',
'outbox',
'gifts',
'welcome_email_automations',
'automations',
'welcome_email_automation_runs',
'welcome_email_automated_emails'
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const logging = require('@tryghost/logging');
const {createNonTransactionalMigration} = require('../../utils');

const FROM_TABLE = 'welcome_email_automations';
const TO_TABLE = 'automations';

module.exports = createNonTransactionalMigration(
async function up(connection) {
const fromExists = await connection.schema.hasTable(FROM_TABLE);
const toExists = await connection.schema.hasTable(TO_TABLE);

if (toExists) {
logging.warn(`Skipping renaming table: ${TO_TABLE} already exists`);
return;
}

if (!fromExists) {
logging.warn(`Skipping renaming table: ${FROM_TABLE} does not exist`);
return;
}

logging.info(`Renaming table: ${FROM_TABLE} -> ${TO_TABLE}`);
await connection.schema.renameTable(FROM_TABLE, TO_TABLE);
},
async function down(connection) {
const fromExists = await connection.schema.hasTable(FROM_TABLE);
const toExists = await connection.schema.hasTable(TO_TABLE);

if (fromExists) {
logging.warn(`Skipping renaming table: ${FROM_TABLE} already exists`);
return;
}

if (!toExists) {
logging.warn(`Skipping renaming table: ${TO_TABLE} does not exist`);
return;
}

logging.info(`Renaming table: ${TO_TABLE} -> ${FROM_TABLE}`);
await connection.schema.renameTable(TO_TABLE, FROM_TABLE);
}
);
6 changes: 3 additions & 3 deletions ghost/core/core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ module.exports = {
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
welcome_email_automations: {
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},
Expand All @@ -1180,7 +1180,7 @@ module.exports = {
},
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},
welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: '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, unsigned: true},
subject: {type: 'string', maxlength: 300, nullable: false},
Expand All @@ -1194,7 +1194,7 @@ module.exports = {
},
welcome_email_automation_runs: {
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: 'wear_automation_id_foreign', cascadeDelete: true},
welcome_email_automation_id: {type: 'string', maxlength: 24, nullable: false, references: 'automations.id', constraintName: 'wear_automation_id_foreign', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', constraintName: 'wear_member_id_foreign', cascadeDelete: true},
next_welcome_email_automated_email_id: {type: 'string', maxlength: 24, nullable: true, references: 'welcome_email_automated_emails.id', constraintName: 'wear_next_email_id_foreign', cascadeDelete: false},
ready_at: {type: 'dateTime', nullable: true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const {MEMBER_WELCOME_EMAIL_SLUGS} = require('../services/member-welcome-emails/

const MEMBER_WELCOME_EMAIL_SLUG_SET = new Set(Object.values(MEMBER_WELCOME_EMAIL_SLUGS));

const WelcomeEmailAutomation = ghostBookshelf.Model.extend({
tableName: 'welcome_email_automations',
const Automation = ghostBookshelf.Model.extend({
tableName: 'automations',

defaults() {
return {
Expand Down Expand Up @@ -57,5 +57,5 @@ const WelcomeEmailAutomation = ghostBookshelf.Model.extend({
});

module.exports = {
WelcomeEmailAutomation: ghostBookshelf.model('WelcomeEmailAutomation', WelcomeEmailAutomation)
Automation: ghostBookshelf.model('Automation', Automation)
};
4 changes: 2 additions & 2 deletions ghost/core/core/server/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {Action} = require('./action');
const {ApiKey, ApiKeys} = require('./api-key');
const {Author, Authors} = require('./author');
const {AutomatedEmailRecipient, AutomatedEmailRecipients} = require('./automated-email-recipient');
const {Automation} = require('./automation');
const {Benefit, Benefits} = require('./benefit');
const {CollectionPost} = require('./collection-post');
const {Collection} = require('./collection');
Expand Down Expand Up @@ -75,7 +76,6 @@ const {User, Users} = require('./user');
const {Webhook, Webhooks} = require('./webhook');
const {WelcomeEmailAutomatedEmail} = require('./welcome-email-automated-email');
const {WelcomeEmailAutomationRun} = require('./welcome-email-automation-run');
const {WelcomeEmailAutomation} = require('./welcome-email-automation');

// enable event listeners
require('./base/listeners');
Expand All @@ -91,6 +91,7 @@ exports.Author = Author;
exports.Authors = Authors;
exports.AutomatedEmailRecipient = AutomatedEmailRecipient;
exports.AutomatedEmailRecipients = AutomatedEmailRecipients;
exports.Automation = Automation;
exports.Benefit = Benefit;
exports.Benefits = Benefits;
exports.CollectionPost = CollectionPost;
Expand Down Expand Up @@ -188,7 +189,6 @@ exports.Webhook = Webhook;
exports.Webhooks = Webhooks;
exports.WelcomeEmailAutomatedEmail = WelcomeEmailAutomatedEmail;
exports.WelcomeEmailAutomationRun = WelcomeEmailAutomationRun;
exports.WelcomeEmailAutomation = WelcomeEmailAutomation;

function init() {
// `init` used to be a necessary call, but now it's unnecessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const WelcomeEmailAutomatedEmail = ghostBookshelf.Model.extend({
return this.belongsTo('EmailDesignSetting', 'email_design_setting_id', 'id');
},

welcomeEmailAutomation() {
return this.belongsTo('WelcomeEmailAutomation', 'welcome_email_automation_id', 'id');
automation() {
return this.belongsTo('Automation', 'welcome_email_automation_id', 'id');
},

nextWelcomeEmailAutomatedEmail() {
Expand Down
4 changes: 2 additions & 2 deletions ghost/core/core/server/models/welcome-email-automation-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const WelcomeEmailAutomationRun = ghostBookshelf.Model.extend({
};
},

welcomeEmailAutomation() {
return this.belongsTo('WelcomeEmailAutomation', 'welcome_email_automation_id', 'id');
automation() {
return this.belongsTo('Automation', 'welcome_email_automation_id', 'id');
},

member() {
Expand Down
10 changes: 5 additions & 5 deletions ghost/core/core/server/services/member-welcome-emails/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const settingsHelpers = require('../settings-helpers');
const EmailAddressParser = require('../email-address/email-address-parser');
const mail = require('../mail');
// @ts-expect-error type checker has trouble with the dynamic exporting in models
const {WelcomeEmailAutomation, WelcomeEmailAutomatedEmail, Newsletter} = require('../../models');
const {Automation, WelcomeEmailAutomatedEmail, Newsletter} = require('../../models');
const MemberWelcomeEmailRenderer = require('./member-welcome-email-renderer');
const {MEMBER_WELCOME_EMAIL_LOG_KEY, MEMBER_WELCOME_EMAIL_TAG, MEMBER_WELCOME_EMAIL_SLUGS, MESSAGES} = require('./constants');

Expand Down Expand Up @@ -179,7 +179,7 @@ class MemberWelcomeEmailService {
}

async #loadWelcomeEmailsCollection() {
return WelcomeEmailAutomation.findAll({
return Automation.findAll({
filter: WELCOME_EMAIL_FILTER,
withRelated: ['welcomeEmailAutomatedEmail']
});
Expand Down Expand Up @@ -337,7 +337,7 @@ class MemberWelcomeEmailService {
this.#defaultNewsletterSenderOptions = await this.#getDefaultNewsletterSenderOptions();

for (const [memberStatus, slug] of Object.entries(MEMBER_WELCOME_EMAIL_SLUGS)) {
const row = await WelcomeEmailAutomation.findOne({slug}, {
const row = await Automation.findOne({slug}, {
withRelated: ['welcomeEmailAutomatedEmail', 'welcomeEmailAutomatedEmail.emailDesignSetting']
});

Expand Down Expand Up @@ -428,7 +428,7 @@ class MemberWelcomeEmailService {
return false;
}

const row = await WelcomeEmailAutomation.findOne({slug}, {withRelated: ['welcomeEmailAutomatedEmail']});
const row = await Automation.findOne({slug}, {withRelated: ['welcomeEmailAutomatedEmail']});
if (!row) {
return false;
}
Expand All @@ -438,7 +438,7 @@ class MemberWelcomeEmailService {

async #renderWelcomeEmailPreview({automatedEmailId, subject, lexical, memberEmail = 'jamie@example.com'}) {
// Still validate the automated email exists (for permission purposes)
const automation = await WelcomeEmailAutomation.findOne({id: automatedEmailId}, {
const automation = await Automation.findOne({id: automatedEmailId}, {
withRelated: ['welcomeEmailAutomatedEmail', 'welcomeEmailAutomatedEmail.emailDesignSetting']
});
const automatedEmail = automation?.related('welcomeEmailAutomatedEmail');
Expand Down
2 changes: 1 addition & 1 deletion ghost/core/core/server/services/members/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function createApiInstance(config) {
MemberFeedback: models.MemberFeedback,
EmailSpamComplaintEvent: models.EmailSpamComplaintEvent,
Outbox: models.Outbox,
WelcomeEmailAutomation: models.WelcomeEmailAutomation,
Automation: models.Automation,
WelcomeEmailAutomationRun: models.WelcomeEmailAutomationRun,
AutomatedEmailRecipient: models.AutomatedEmailRecipient,
Gift: models.Gift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = function MembersAPI({
Comment,
MemberFeedback,
Outbox,
WelcomeEmailAutomation,
Automation,
WelcomeEmailAutomationRun,
AutomatedEmailRecipient,
Gift
Expand Down Expand Up @@ -104,7 +104,7 @@ module.exports = function MembersAPI({
tokenService,
newslettersService,
productRepository,
WelcomeEmailAutomation,
Automation,
WelcomeEmailAutomationRun,
Member,
MemberNewsletter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ module.exports = class EventRepository {
async getAutomatedEmailSentEvents(options = {}, filter) {
options = {
...options,
withRelated: ['member', 'automatedEmail.welcomeEmailAutomation'],
withRelated: ['member', 'automatedEmail.automation'],
filter: 'custom:true',
useBasicCount: true,
mongoTransformer: chainTransformers(
Expand All @@ -1035,10 +1035,10 @@ module.exports = class EventRepository {

const data = models.map((model) => {
const automatedEmail = model.related('automatedEmail');
const automation = automatedEmail.related('welcomeEmailAutomation');
const automation = automatedEmail.related('automation');
if (!automation || !automation.id) {
throw new errors.InternalServerError({
message: `Automated email recipient ${model.id} has no associated welcome email automation`
message: `Automated email recipient ${model.id} has no associated automation`
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class MemberRepository {
* @param {any} deps.offersAPI
* @param {ITokenService} deps.tokenService
* @param {any} deps.newslettersService
* @param {any} deps.WelcomeEmailAutomation
* @param {any} deps.Automation
* @param {any} deps.WelcomeEmailAutomationRun
*/
constructor({
Expand All @@ -87,7 +87,7 @@ module.exports = class MemberRepository {
offersAPI,
tokenService,
newslettersService,
WelcomeEmailAutomation,
Automation,
WelcomeEmailAutomationRun
}) {
this._Member = Member;
Expand All @@ -107,7 +107,7 @@ module.exports = class MemberRepository {
this._offersAPI = offersAPI;
this.tokenService = tokenService;
this._newslettersService = newslettersService;
this._WelcomeEmailAutomation = WelcomeEmailAutomation;
this._Automation = Automation;
this._WelcomeEmailAutomationRun = WelcomeEmailAutomationRun;

DomainEvents.subscribe(OfferRedemptionEvent, async function (event) {
Expand Down Expand Up @@ -385,9 +385,9 @@ module.exports = class MemberRepository {
const isGiftSignup = !stripeCustomer && memberData.status === 'gift';
let welcomeEmailToEnqueue = null;

if (this._WelcomeEmailAutomation && WELCOME_EMAIL_SOURCES.includes(source)) {
if (this._Automation && WELCOME_EMAIL_SOURCES.includes(source)) {
const getActiveWelcomeEmailToEnqueue = async (slug) => {
const automation = await this._WelcomeEmailAutomation.findOne(
const automation = await this._Automation.findOne(
{slug},
{...options, withRelated: ['welcomeEmailAutomatedEmail']}
);
Expand Down Expand Up @@ -1520,8 +1520,8 @@ module.exports = class MemberRepository {
let isPaidWelcomeEmailActive = false;
let paidWelcomeAutomation = null;
let paidWelcomeEmail = null;
if (shouldSendPaidWelcomeEmail && this._WelcomeEmailAutomation) {
paidWelcomeAutomation = await this._WelcomeEmailAutomation.findOne(
if (shouldSendPaidWelcomeEmail && this._Automation) {
paidWelcomeAutomation = await this._Automation.findOne(
{slug: MEMBER_WELCOME_EMAIL_SLUGS.paid},
{...options, withRelated: ['welcomeEmailAutomatedEmail']}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {OUTBOX_LOG_KEY} = require('../jobs/lib/constants');
const memberWelcomeEmailService = require('../../member-welcome-emails/service');
const logging = require('@tryghost/logging');
const {WelcomeEmailAutomation, AutomatedEmailRecipient} = require('../../../models');
const {Automation, AutomatedEmailRecipient} = require('../../../models');
const {MEMBER_WELCOME_EMAIL_SLUGS} = require('../../member-welcome-emails/constants');

const LOG_KEY = `${OUTBOX_LOG_KEY}[MEMBER-WELCOME-EMAIL]`;
Expand All @@ -21,7 +21,7 @@ async function handle({payload}) {
return;
}

const automation = await WelcomeEmailAutomation.findOne({slug}, {withRelated: ['welcomeEmailAutomatedEmail']});
const automation = await Automation.findOne({slug}, {withRelated: ['welcomeEmailAutomatedEmail']});
if (!automation) {
logging.warn({
system: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function fetchAndLockRuns() {
return await db.knex.transaction(async (trx) => {
/** @type {Run[]} */
const runs = await trx('welcome_email_automation_runs as r')
.join('welcome_email_automations as a', 'r.welcome_email_automation_id', 'a.id')
.join('automations as a', 'r.welcome_email_automation_id', 'a.id')
.join('welcome_email_automated_emails as e', 'r.next_welcome_email_automated_email_id', 'e.id')
.whereNotNull('r.next_welcome_email_automated_email_id')
.where('r.ready_at', '<=', now)
Expand Down
Loading
Loading