smaccounS
Convex Community5mo ago
18 replies
smaccoun

convex schema + data migration

I think the issue if I understand it (i was having the same for a while) is that typically you have 3 or 4 environments (dev, canary, preview, prod,.....whatever) and you want them to be in sync. So typically at least what i'm used to with like postgres is you have CI automate the deploy between these envs so they are always in lock step. But convex doesnt have a standard database migration tool that effectively runs a set of migrations that you keep adding too that take you up from the default db state to the current state. I wrote my own my system that basically mimick dbmate (https://github.com/amacneil/dbmate) with my own migration tracking table that i am happy to share more about (it mostly works but because convex is so nicely typed does have some issues i'm working out)

I really think convex should standardize on this and have maybe even have a componetn for (i'm aware of the current migrations copnent but this is not that). This is a pretty critical feature that any relational db. Its very necessary for production workflows

migrationStatus: defineTable({
migrationId: v.string(),
status: v.union(
v.literal("pending"),
v.literal("running"),
v.literal("completed"),
v.literal("failed"),
v.literal("rolled_back") // Add rollback status
),
startedAt: v.optional(v.number()),
completedAt: v.optional(v.number()),
error: v.optional(v.string()),
// New optional fields for better tracking
name: v.optional(v.string()), // Migration name
description: v.optional(v.string()), // What it does
recordsProcessed: v.optional(v.number()),
recordsUpdated: v.optional(v.number()),
recordsErrored: v.optional(v.number()),
executionTimeMs: v.optional(v.number()),
environment: v.optional(v.string()), // Track which env ran it
}).index("migrationId", ["migrationId"]),
GitHub
🚀 A lightweight, framework-agnostic database migration tool. - amacneil/dbmate
GitHub - amacneil/dbmate: 🚀 A lightweight, framework-agnostic da...
Was this page helpful?