From a30953fcb5c277ddf9a82ef5e4fdbfeac9363ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Tue, 16 Sep 2025 20:50:28 +0800 Subject: [PATCH 1/2] feat: disable migrations Ability to skip migrations in fastify app to manage the migrations yourself --- packages/fastify-app/.env.sample | 5 +++++ packages/fastify-app/README.md | 1 + packages/fastify-app/src/server.ts | 12 +++++++----- packages/fastify-app/src/utils/config.ts | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/fastify-app/.env.sample b/packages/fastify-app/.env.sample index 0a37f6e3..055b4084 100644 --- a/packages/fastify-app/.env.sample +++ b/packages/fastify-app/.env.sample @@ -36,3 +36,8 @@ MAX_POSTGRES_CONNECTIONS=20 # If true, the webhook data is not used and instead the webhook is just a trigger to fetch the entity from Stripe again. This ensures that a race condition with failed webhooks can never accidentally overwrite the data with an older state. # Default: REVALIDATE_OBJECTS_VIA_STRIPE_API=payment_intent,invoice,customer,subscription + +# optional +# If you do not want the app to run the migrations and manage them outside of the app, set this to true +# Default: false +DISABLE_MIGRATIONS=false \ No newline at end of file diff --git a/packages/fastify-app/README.md b/packages/fastify-app/README.md index c805cfa6..ee3d19f3 100644 --- a/packages/fastify-app/README.md +++ b/packages/fastify-app/README.md @@ -51,6 +51,7 @@ Set your webhook endpoint in the Stripe dashboard to point to your server’s `/ | `BACKFILL_RELATED_ENTITIES` | Backfill related entities for foreign key integrity (default: true) | No | | `MAX_POSTGRES_CONNECTIONS` | Max Postgres connection pool size (default: 10) | No | | `REVALIDATE_OBJECTS_VIA_STRIPE_API` | Always fetch latest entity from Stripe instead of trusting webhook payload, possible values: charge, credit_note, customer, dispute, invoice, payment_intent, payment_method, plan, price, product, refund, review, radar.early_fraud_warning, setup_intent, subscription, subscription_schedule, tax_id | No | +| `DISABLE_MIGRATIONS` | If you do not want the app to run the migrations and manage them outside of the app, set this to true | No | ## Endpoints diff --git a/packages/fastify-app/src/server.ts b/packages/fastify-app/src/server.ts index 7627e2f0..9b1dbdbb 100644 --- a/packages/fastify-app/src/server.ts +++ b/packages/fastify-app/src/server.ts @@ -15,11 +15,13 @@ const main = async () => { const config = getConfig() - await runMigrations({ - databaseUrl: config.databaseUrl, - schema: config.schema, - logger: logger, - }) + if (!config.disableMigrations) { + await runMigrations({ + databaseUrl: config.databaseUrl, + schema: config.schema, + logger: logger, + }) + } // Start the server app.listen({ port: Number(config.port), host: '0.0.0.0' }, (err, address) => { diff --git a/packages/fastify-app/src/utils/config.ts b/packages/fastify-app/src/utils/config.ts index 9938d28b..6e495ded 100644 --- a/packages/fastify-app/src/utils/config.ts +++ b/packages/fastify-app/src/utils/config.ts @@ -45,6 +45,8 @@ export type StripeSyncServerConfig = { revalidateObjectsViaStripeApi: Array port: number + + disableMigrations: boolean } export function getConfig(): StripeSyncServerConfig { @@ -65,5 +67,6 @@ export function getConfig(): StripeSyncServerConfig { .split(',') .map((it) => it.trim()) .filter((it) => it.length > 0) as Array, + disableMigrations: getConfigFromEnv('DISABLE_MIGRATIONS', 'false') === 'true', } } From 77c5a3a925a96d45bda64b075b087ffca8565fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Tue, 16 Sep 2025 20:54:59 +0800 Subject: [PATCH 2/2] docs --- docs/docker.md | 1 + packages/fastify-app/.env.sample | 4 ++-- packages/fastify-app/README.md | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/docker.md b/docs/docker.md index 0f3b8213..b47f2450 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -51,6 +51,7 @@ Set your webhook endpoint in the Stripe dashboard to point to your server’s `/ | `BACKFILL_RELATED_ENTITIES` | Backfill related entities for foreign key integrity (default: true) | No | | `MAX_POSTGRES_CONNECTIONS` | Max Postgres connection pool size (default: 10) | No | | `REVALIDATE_OBJECTS_VIA_STRIPE_API` | Always fetch latest entity from Stripe (default: false) | No | +| `DISABLE_MIGRATIONS` | Disable the automated database migrations on app startup (default: false) | No | ## Endpoints diff --git a/packages/fastify-app/.env.sample b/packages/fastify-app/.env.sample index 055b4084..f4f7b64d 100644 --- a/packages/fastify-app/.env.sample +++ b/packages/fastify-app/.env.sample @@ -38,6 +38,6 @@ MAX_POSTGRES_CONNECTIONS=20 REVALIDATE_OBJECTS_VIA_STRIPE_API=payment_intent,invoice,customer,subscription # optional -# If you do not want the app to run the migrations and manage them outside of the app, set this to true +# Disable the automated database migrations on app startup # Default: false -DISABLE_MIGRATIONS=false \ No newline at end of file +DISABLE_MIGRATIONS=false diff --git a/packages/fastify-app/README.md b/packages/fastify-app/README.md index ee3d19f3..dd33be73 100644 --- a/packages/fastify-app/README.md +++ b/packages/fastify-app/README.md @@ -51,7 +51,7 @@ Set your webhook endpoint in the Stripe dashboard to point to your server’s `/ | `BACKFILL_RELATED_ENTITIES` | Backfill related entities for foreign key integrity (default: true) | No | | `MAX_POSTGRES_CONNECTIONS` | Max Postgres connection pool size (default: 10) | No | | `REVALIDATE_OBJECTS_VIA_STRIPE_API` | Always fetch latest entity from Stripe instead of trusting webhook payload, possible values: charge, credit_note, customer, dispute, invoice, payment_intent, payment_method, plan, price, product, refund, review, radar.early_fraud_warning, setup_intent, subscription, subscription_schedule, tax_id | No | -| `DISABLE_MIGRATIONS` | If you do not want the app to run the migrations and manage them outside of the app, set this to true | No | +| `DISABLE_MIGRATIONS` | Disable the automated database migrations on app startup | No | ## Endpoints