Skip to content
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
1 change: 1 addition & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions packages/fastify-app/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Disable the automated database migrations on app startup
# Default: false
DISABLE_MIGRATIONS=false
1 change: 1 addition & 0 deletions packages/fastify-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` | Disable the automated database migrations on app startup | No |

## Endpoints

Expand Down
12 changes: 7 additions & 5 deletions packages/fastify-app/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/fastify-app/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type StripeSyncServerConfig = {
revalidateObjectsViaStripeApi: Array<RevalidateEntity>

port: number

disableMigrations: boolean
}

export function getConfig(): StripeSyncServerConfig {
Expand All @@ -65,5 +67,6 @@ export function getConfig(): StripeSyncServerConfig {
.split(',')
.map((it) => it.trim())
.filter((it) => it.length > 0) as Array<RevalidateEntity>,
disableMigrations: getConfigFromEnv('DISABLE_MIGRATIONS', 'false') === 'true',
}
}