Skip to content

Commit

Permalink
detect database and change date comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
cathysarisky committed Feb 13, 2025
1 parent b66a8f8 commit d978952
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const ObjectId = require('bson-objectid').default;
const {chunk: chunkArray} = require('lodash');
const debug = require('@tryghost/debug')('jobs:clean-expired-comped');
const moment = require('moment');
const DatabaseInfo = require('@tryghost/database-info');


// recurring job to clean expired complimentary subscriptions

Expand Down Expand Up @@ -31,10 +33,16 @@ if (parentPort) {
const cleanupStartDate = new Date();
const db = require('../../../data/db');
debug(`Starting cleanup of expired comp subscriptions`);
const expiredCompedRows = await db.knex('members_products')
.where('expiry_at', '<', moment.utc().startOf('day').toISOString())
.select('*');

let expiredCompedRows = [];
if (DatabaseInfo.isMySQL(db.knex)) {
expiredCompedRows = await db.knex('members_products')
.where('expiry_at', '<', moment.utc().startOf('day').toISOString())
.select('*');
} else {
expiredCompedRows = await db.knex('members_products')
.where('expiry_at', '<', moment.utc().startOf('day').valueOf())
.select('*');
}
let deletedExpiredSubs = 0;
let updatedMembers = 0;

Expand Down

0 comments on commit d978952

Please sign in to comment.