winsoroaks
winsoroaks8mo ago

run migration on prod before pushing new schema?

i've added a new column to my table, after running a migration on local,
// schema.ts
rank: v.optional(v.number()),

export const addRankToImages = migration({
table: "images",
migrateOne: async (ctx, image) => {
if (!image.rank) {
await ctx.db.patch(image._id, { rank: 0 })
}
},
})
// schema.ts
rank: v.optional(v.number()),

export const addRankToImages = migration({
table: "images",
migrateOne: async (ctx, image) => {
if (!image.rank) {
await ctx.db.patch(image._id, { rank: 0 })
}
},
})
can i run the migration on production before pushing the new schema? i also have rank an optional field now
1 Reply
Michal Srb
Michal Srb8mo ago
You must add the (optional) field before you can add it to your documents (right now tables either have a schema with all known fields or don't have a schema at all, no in-between).

Did you find this page helpful?