From 6d21cc1b01b00bb44b0f8e756529fa6dfb73d869 Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Fri, 1 Dec 2023 17:29:26 -0600 Subject: [PATCH] Add flag for running db migrations on appview (#1913) * add flag for running db migrations on appview * lint * another fix --- services/bsky/api.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/services/bsky/api.js b/services/bsky/api.js index cf63c951043..2e78d3bafec 100644 --- a/services/bsky/api.js +++ b/services/bsky/api.js @@ -32,6 +32,18 @@ const { const main = async () => { const env = getEnv() assert(env.dbPrimaryPostgresUrl, 'missing configuration for db') + + if (env.enableMigrations) { + // separate db needed for more permissions + const migrateDb = new PrimaryDatabase({ + url: env.dbMigratePostgresUrl, + schema: env.dbPostgresSchema, + poolSize: 2, + }) + await migrateDb.migrateToLatestOrThrow() + await migrateDb.close() + } + const db = new DatabaseCoordinator({ schema: env.dbPostgresSchema, primary: { @@ -102,12 +114,12 @@ const main = async () => { algos, }) // separate db needed for more permissions - const migrateDb = new PrimaryDatabase({ + const viewMaintainerDb = new PrimaryDatabase({ url: env.dbMigratePostgresUrl, schema: env.dbPostgresSchema, poolSize: 2, }) - const viewMaintainer = new ViewMaintainer(migrateDb, 1800) + const viewMaintainer = new ViewMaintainer(viewMaintainerDb, 1800) const viewMaintainerRunning = viewMaintainer.run() const periodicModerationEventReversal = new PeriodicModerationEventReversal( @@ -125,11 +137,12 @@ const main = async () => { await bsky.destroy() viewMaintainer.destroy() await viewMaintainerRunning - await migrateDb.close() + await viewMaintainerDb.close() }) } const getEnv = () => ({ + enableMigrations: process.env.ENABLE_MIGRATIONS === 'true', port: parseInt(process.env.PORT), version: process.env.BSKY_VERSION, dbMigratePostgresUrl: