Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw on migration error #10439

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions scripts/toolboxSrc/preDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'
import getKysely from 'parabol-server/postgres/getKysely'
import {Logger} from 'parabol-server/utils/Logger'
import path from 'path'
import queryMap from '../../queryMap.json'
import getProjectRoot from '../webpack/utils/getProjectRoot'
Expand All @@ -12,7 +13,7 @@ import standaloneMigrations from './standaloneMigrations'
const PROJECT_ROOT = getProjectRoot()

const storePersistedQueries = async () => {
console.log('🔗 QueryMap Persistence Started')
Logger.log('🔗 QueryMap Persistence Started')
const hashes = Object.keys(queryMap)
const now = new Date()
const records = hashes.map((hash) => ({
Expand All @@ -22,23 +23,28 @@ const storePersistedQueries = async () => {
}))

const pg = getKysely()
const res = await pg.insertInto('QueryMap').values(records).onConflict((oc) => oc.doNothing()).returning('id').execute()
console.log(`🔗 QueryMap Persistence Complete: ${res.length} records added`)
const res = await pg
.insertInto('QueryMap')
.values(records)
.onConflict((oc) => oc.doNothing())
.returning('id')
.execute()
Logger.log(`🔗 QueryMap Persistence Complete: ${res.length} records added`)
}

const preDeploy = async () => {
// .env is typically only used in testing prod deploys
const envPath = path.join(PROJECT_ROOT, '.env')
const myEnv = dotenv.config({path: envPath})
dotenvExpand(myEnv)
console.log(`🚀 Predeploy Started v${__APP_VERSION__} sha:${__COMMIT_HASH__}`)
Logger.log(`🚀 Predeploy Started v${__APP_VERSION__} sha:${__COMMIT_HASH__}`)
// first we migrate DBs & add env vars to client assets
await Promise.all([standaloneMigrations(), applyEnvVarsToClientAssets()])

// The we can prime the DB & CDN
await Promise.all([storePersistedQueries(), primeIntegrations(), pushToCDN()])
await getKysely().destroy()
console.log(`🚀 Predeploy Complete`)
Logger.log(`🚀 Predeploy Complete`)
process.exit()
}

Expand Down
13 changes: 7 additions & 6 deletions scripts/toolboxSrc/standaloneMigrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// This file is bundled by webpack into a small migrate.js file which includes all migration files & their deps
// It is used by PPMIs who are only provided with the bundles
import {Migrator} from 'kysely'
import {Logger} from 'parabol-server/utils/Logger'
import path from 'path'
import {migrations} from '../../.config/kyselyMigrations'
import getKysely from '../../packages/server/postgres/getKysely'
import '../webpack/utils/dotenv'
import pgEnsureExtensions from './pgEnsureExtensions'

const migratePG = async () => {
console.log('🐘 Postgres Migration Started')
Logger.log('🐘 Postgres Migration Started')
await pgEnsureExtensions()
// pgm uses a dynamic require statement, which doesn't work with webpack
// if we ignore that dynamic require, we'd still have to include the migrations directory AND any dependencies it might have
Expand Down Expand Up @@ -38,17 +39,17 @@ const migratePG = async () => {

results?.forEach((it) => {
if (it.status === 'Success') {
console.log(` ✅ Migration: ${it.migrationName}`)
Logger.log(` ✅ Migration: ${it.migrationName}`)
} else if (it.status === 'Error') {
console.error(` ⛔️ Migration: ${it.migrationName}`)
Logger.error(` ⛔️ Migration: ${it.migrationName}`)
}
})

if (error) {
console.log('🐘 Postgres Migration Failed')
console.error(error)
Logger.log('🐘 Postgres Migration Failed')
throw error
} else {
console.log('🐘 Postgres Migration Complete')
Logger.log('🐘 Postgres Migration Complete')
}
}

Expand Down
Loading