Skip to content

Commit

Permalink
Fix down migrations (#1002)
Browse files Browse the repository at this point in the history
Down migrations weren't working due to a non-nullable field being
renamed by recreating it.
  • Loading branch information
jotjern authored Sep 17, 2024
1 parent 8562f32 commit 17c4fc4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/db/src/migrations/0029_add_user_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
export async function up(db) {
await db.schema
.alterTable("ow_user")
.dropColumn("auth0_sub") // rename to auth0_id
.addColumn("auth0_id", "varchar(128)", (col) => col.unique().notNull()) //https://community.auth0.com/t/is-256-a-safe-max-length-for-a-user-id/34040/9
.addColumn("family_name", "varchar(255)", (col) => col.notNull())
.addColumn("middle_name", "varchar(255)", (col) => col.notNull())
.addColumn("given_name", "varchar(255)", (col) => col.notNull())
Expand All @@ -12,9 +10,22 @@ export async function up(db) {
.addColumn("phone", "varchar(255)")
.addColumn("gender", "varchar(255)")
.execute()

await db.schema.alterTable("ow_user").renameColumn("auth0_sub", "auth0_id").execute()
}

/** @param db {import('kysely').Kysely} */
export async function down(db) {
await db.schema.dropTable("ow_user").execute()
await db.schema
.alterTable("ow_user")
.dropColumn("family_name")
.dropColumn("middle_name")
.dropColumn("given_name")
.dropColumn("picture")
.dropColumn("allergies")
.dropColumn("phone")
.dropColumn("gender")
.execute()

await db.schema.alterTable("ow_user").renameColumn("auth0_id", "auth0_sub").execute()
}

0 comments on commit 17c4fc4

Please sign in to comment.