Skip to content

Commit e043ecd

Browse files
committed
fix: add tracked migration for billing email schema on existing databases
The fee_rate, fee_discount_until, fee_rate_applied columns and email_events table were added inside the already-applied schema_inline_v2026_04_07 migration, so they never ran on the production database. This adds a separate tracked migration.
1 parent 2024d58 commit e043ecd

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/db.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,34 @@ pub async fn create_pool(database_url: &str) -> anyhow::Result<SqlitePool> {
14571457
})
14581458
.await?;
14591459

1460+
// Billing email infrastructure: per-merchant fee rate, discount expiry, email idempotency
1461+
run_tracked_migration(&pool, "billing_emails_v2026_04_10", || async {
1462+
for sql in &[
1463+
"ALTER TABLE merchants ADD COLUMN fee_rate REAL",
1464+
"ALTER TABLE merchants ADD COLUMN fee_discount_until TEXT",
1465+
"ALTER TABLE fee_ledger ADD COLUMN fee_rate_applied REAL",
1466+
] {
1467+
sqlx::query(sql).execute(&pool).await.ok();
1468+
}
1469+
1470+
sqlx::query(
1471+
"CREATE TABLE IF NOT EXISTS email_events (
1472+
id TEXT PRIMARY KEY,
1473+
merchant_id TEXT NOT NULL,
1474+
template TEXT NOT NULL,
1475+
entity_id TEXT NOT NULL,
1476+
sent_at TEXT NOT NULL,
1477+
UNIQUE(merchant_id, template, entity_id)
1478+
)",
1479+
)
1480+
.execute(&pool)
1481+
.await
1482+
.ok();
1483+
1484+
Ok(())
1485+
})
1486+
.await?;
1487+
14601488
Ok(pool)
14611489
}
14621490

0 commit comments

Comments
 (0)