🐛 Fixed migration for SQLite3 (#12371)

no-issue

The current version of SQLite3 bundled with Ghost supports a maximum of 999
variables, we use one variable for the SET value and so we're left with 998 for the
WHERE IN clause values.

refs: https://forum.ghost.org/t/unable-to-start-ghost-3-38-0-locally/18322
This commit is contained in:
Fabien 'egg' O'Carroll 2020-11-17 16:39:42 +00:00 committed by GitHub
parent 6b8bfb81fc
commit 8ad995203e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
const {chunk} = require('lodash');
const {createTransactionalMigration} = require('../../utils');
const logging = require('../../../../../shared/logging');
@ -17,13 +18,24 @@ module.exports = createTransactionalMigration(
.select('id')
.where('visibility', 'public')).map(row => row.id);
await connection('emails')
.update('recipient_filter', 'paid')
.whereIn('post_id', paidPostIds);
// Umm? Well... The current version of SQLite3 bundled with Ghost supports
// a maximum of 999 variables, we use one variable for the SET value
// and so we're left with 998 for our WHERE IN clause values
const chunkSize = 998;
const paidPostIdChunks = chunk(paidPostIds, chunkSize);
const membersAndPublicPostIdChunks = chunk(membersPostIds.concat(publicPostIds), chunkSize);
await connection('emails')
.update('recipient_filter', 'all')
.whereIn('post_id', membersPostIds.concat(publicPostIds));
for (const paidPostIdsChunk of paidPostIdChunks) {
await connection('emails')
.update('recipient_filter', 'paid')
.whereIn('post_id', paidPostIdsChunk);
}
for (const membersAndPublicPostIdsChunk of membersAndPublicPostIdChunks) {
await connection('emails')
.update('recipient_filter', 'all')
.whereIn('post_id', membersAndPublicPostIdsChunk);
}
},
async function down(connection) {