Added built in collection fixtures

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

- The instance should have two built-in collections "latest" (prviously known as "index") and "featured". These have been filled through in-memory tricks before, now they should come pre-populated through fixtures mechanism.
This commit is contained in:
Naz 2023-07-07 22:32:14 +08:00 committed by naz
parent 32f602d899
commit acbe3a250e
5 changed files with 99 additions and 23 deletions

View File

@ -0,0 +1,60 @@
const logging = require('@tryghost/logging');
const {default: ObjectID} = require('bson-objectid');
const {createTransactionalMigration} = require('../../utils');
module.exports = createTransactionalMigration(
async function up(knex) {
logging.info('Creating built in collections');
const existingIndexCollection = await knex('collections')
.where({
slug: 'index'
})
.first();
if (existingIndexCollection) {
logging.warn('Index collection already exists, skipping');
} else {
await knex('collections').insert({
id: (new ObjectID()).toHexString(),
name: 'Index',
slug: 'index',
description: 'Collection with all posts',
type: 'automatic',
filter: '',
created_at: knex.raw('current_timestamp')
});
}
const existingFeaturedCollection = await knex('collections')
.where({
slug: 'featured'
})
.first();
if (existingFeaturedCollection) {
logging.warn('Index collection already exists, skipping');
} else {
await knex('collections').insert({
id: (new ObjectID()).toHexString(),
name: 'Featured',
slug: 'featured',
description: 'Collection of featured posts',
type: 'automatic',
filter: 'featured:true',
created_at: knex.raw('current_timestamp')
});
}
},
async function down(knex) {
logging.info('Deleting built in collections');
await knex('collections').where({
slug: 'index'
}).del();
await knex('collections').where({
slug: 'featured'
}).del();
}
);

View File

@ -1,5 +1,24 @@
{
"models": [
{
"name": "Collection",
"entries": [
{
"title": "Index",
"slug": "index",
"description": "Collection with all posts",
"type": "automatic",
"filter": ""
},
{
"title": "Featured",
"slug": "featured",
"description": "Collection of featured posts",
"type": "automatic",
"filter": "featured:true"
}
]
},
{
"name": "Product",
"entries": [

View File

@ -33,28 +33,6 @@ class CollectionsServiceWrapper {
return;
}
const existingBuiltins = await this.api.getAll({filter: 'slug:featured'});
if (!existingBuiltins.data.length) {
await this.api.createCollection({
title: 'Index',
slug: 'index',
description: 'Collection with all posts',
type: 'automatic',
deletable: false,
filter: 'status:published'
});
await this.api.createCollection({
title: 'Featured Posts',
slug: 'featured',
description: 'Collection of featured posts',
type: 'automatic',
deletable: false,
filter: 'featured:true'
});
}
this.api.subscribeToEvents();
require('./intercept-events')();
}

View File

@ -36,7 +36,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '8e299caf33efbcf8a12c9cefaf8f6500';
const currentFixturesHash = '93c3b3cb8bca34a733634e74ee514172';
const currentFixturesHash = '03f3d9ddc0a1190e909a85808a591a04';
const currentSettingsHash = '4f23a583335dcb4cb3fae553122ea200';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';

View File

@ -1,5 +1,24 @@
{
"models": [
{
"name": "Collection",
"entries": [
{
"title": "Latest",
"slug": "latest",
"description": "Collection with all posts",
"type": "automatic",
"filter": ""
},
{
"title": "Featured Posts",
"slug": "featured",
"description": "Collection of featured posts",
"type": "automatic",
"filter": "featured:true"
}
]
},
{
"name": "Product",
"entries": [