Skip to content

Commit

Permalink
set version on create and also update bots when migrating
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Jul 18, 2019
1 parent 6ea7575 commit cf51049
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/bp/core/services/bot-service.ts
Expand Up @@ -430,7 +430,8 @@ export class BotService {
const mergedConfigs = {
...DEFAULT_BOT_CONFIGS,
...templateConfig,
...botConfig
...botConfig,
version: process.BOTPRESS_VERSION
}

if (!mergedConfigs.imports.contentTypes) {
Expand Down
15 changes: 13 additions & 2 deletions src/bp/core/services/migration/index.ts
Expand Up @@ -14,6 +14,7 @@ import path from 'path'
import semver from 'semver'

import { container } from '../../app.inversify'
import { GhostService } from '../ghost/service'

const debug = DEBUG('migration')

Expand All @@ -35,7 +36,8 @@ export class MigrationService {
@inject(TYPES.Logger)
private logger: sdk.Logger,
@inject(TYPES.Database) private database: Database,
@inject(TYPES.ConfigProvider) private configProvider: ConfigProvider
@inject(TYPES.ConfigProvider) private configProvider: ConfigProvider,
@inject(TYPES.GhostService) private ghostService: GhostService
) {
this.currentVersion = process.env.MIGRATION_TEST_VERSION || process.BOTPRESS_VERSION
this.completedMigrationsDir = path.resolve(process.PROJECT_LOCATION, `data/migrations`)
Expand Down Expand Up @@ -133,10 +135,19 @@ export class MigrationService {
process.exit(1)
}

await this.configProvider.mergeBotpressConfig({ version: this.currentVersion })
await this.updateAllVersions()
this.logger.info(`Migrations completed successfully! `)
}

private async updateAllVersions() {
await this.configProvider.mergeBotpressConfig({ version: this.currentVersion })

const botIds = (await this.ghostService.bots().directoryListing('/', 'bot.config.json')).map(path.dirname)
for (const botId of botIds) {
await this.configProvider.mergeBotConfig(botId, { version: this.currentVersion })
}
}

private displayMigrationStatus(configVersion: string, missingMigrations: MigrationFile[], logger: sdk.Logger) {
const migrations = missingMigrations.map(x => this.loadedMigrations[x.filename].info)

Expand Down

0 comments on commit cf51049

Please sign in to comment.