mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 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:
parent
6b8bfb81fc
commit
8ad995203e
1 changed files with 18 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
const {chunk} = require('lodash');
|
||||||
const {createTransactionalMigration} = require('../../utils');
|
const {createTransactionalMigration} = require('../../utils');
|
||||||
const logging = require('../../../../../shared/logging');
|
const logging = require('../../../../../shared/logging');
|
||||||
|
|
||||||
|
@ -17,13 +18,24 @@ module.exports = createTransactionalMigration(
|
||||||
.select('id')
|
.select('id')
|
||||||
.where('visibility', 'public')).map(row => row.id);
|
.where('visibility', 'public')).map(row => row.id);
|
||||||
|
|
||||||
await connection('emails')
|
// Umm? Well... The current version of SQLite3 bundled with Ghost supports
|
||||||
.update('recipient_filter', 'paid')
|
// a maximum of 999 variables, we use one variable for the SET value
|
||||||
.whereIn('post_id', paidPostIds);
|
// 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')
|
for (const paidPostIdsChunk of paidPostIdChunks) {
|
||||||
.update('recipient_filter', 'all')
|
await connection('emails')
|
||||||
.whereIn('post_id', membersPostIds.concat(publicPostIds));
|
.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) {
|
async function down(connection) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue