Nooped v5.64 migrations

refs https://github.com/TryGhost/Arch/issues/95

- The migrations in v5.65 are clearing the collections data again and only populate the "featured" collection.
This commit is contained in:
Naz 2023-09-22 21:38:18 +08:00 committed by naz
parent 8d02752802
commit 8655f960c8
2 changed files with 12 additions and 73 deletions

View File

@ -1,12 +1,10 @@
const logging = require('@tryghost/logging');
const {createNonTransactionalMigration} = require('../../utils');
module.exports = createNonTransactionalMigration(
async function up(knex) {
logging.info('Clearing collections_posts table');
await knex('collections_posts').truncate();
module.exports = {
async up() {
logging.warn('Skipping migration - noop');
},
async function down() {
logging.info('Not doing anything - collections_posts table has been truncated');
async down() {
logging.warn('Skipping migration - noop');
}
);
};

View File

@ -1,69 +1,10 @@
const logging = require('@tryghost/logging');
const {default: ObjectID} = require('bson-objectid');
const {createTransactionalMigration} = require('../../utils');
const insertPostCollections = async (knex, collectionId, postIds) => {
logging.warn(`Batch inserting ${postIds.length} collection posts for collection ${collectionId}`);
const collectionPosts = postIds.map((postId) => {
return {
id: (new ObjectID()).toHexString(),
collection_id: collectionId,
post_id: postId,
sort_order: 0
};
});
await knex.batchInsert('collections_posts', collectionPosts, 1000);
};
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Populating built-in collections');
const existingLatestCollection = await knex('collections')
.where({
slug: 'latest'
})
.first();
if (!existingLatestCollection) {
logging.warn('Latest collection does not exists, skipping');
} else {
const latestPostsRows = await knex('posts')
.select('id')
.where({
type: 'post'
});
const latestPostsIds = latestPostsRows.map(row => row.id);
await insertPostCollections(knex, existingLatestCollection.id, latestPostsIds);
}
const existingFeaturedCollection = await knex('collections')
.where({
slug: 'featured'
})
.first();
if (!existingFeaturedCollection) {
logging.warn('Featured collection does not exist, skipping');
} else {
const featuredPostsRows = await knex('posts')
.select('id')
.where({
featured: true,
type: 'post'
});
const featuredPostsIds = featuredPostsRows.map(row => row.id);
await insertPostCollections(knex, existingFeaturedCollection.id, featuredPostsIds);
}
module.exports = {
async up() {
logging.warn('Skipping migration - noop');
},
async function down(knex) {
logging.info('Clearing collections_posts table');
await knex('collections_posts').truncate();
async down() {
logging.warn('Skipping migration - noop');
}
);
};