diff --git a/libs/db/migrations/README.md b/libs/db/migrations/README.md index 8b08b20f..96b6838c 100644 --- a/libs/db/migrations/README.md +++ b/libs/db/migrations/README.md @@ -16,7 +16,7 @@ erDiagram User_Account ||--|{ Login_Method : "can have" Local_Login |o--|| Login_Method : "is a" User_Account ||--|{ User_Permission : "should have" - Verification_Tokens ||--|| User_Account : "relates to" + Verification_Token ||--|| User_Account : "relates to" Role ||--|{ User_Permission : "relates_to" DeityCategory { string name @@ -94,7 +94,6 @@ erDiagram ulid id string token ulid user_id - timestamp expires_at string type } diff --git a/libs/db/migrations/diagram.mmd b/libs/db/migrations/diagram.mmd index 99853b60..548eab99 100644 --- a/libs/db/migrations/diagram.mmd +++ b/libs/db/migrations/diagram.mmd @@ -7,7 +7,7 @@ erDiagram User_Account ||--|{ Login_Method : "can have" Local_Login |o--|| Login_Method : "is a" User_Account ||--|{ User_Permission : "should have" - Verification_Tokens ||--|| User_Account : "relates to" + Verification_Token ||--|| User_Account : "relates to" Role ||--|{ User_Permission : "relates_to" DeityCategory { string name @@ -85,6 +85,5 @@ erDiagram ulid id string token ulid user_id - timestamp expires_at string type } diff --git a/libs/db/migrations/src/01H5TV87JJ3CE73WBGZZWQYBP4-convert-to-new-ulid-type.ts b/libs/db/migrations/src/01H5TV87JJ3CE73WBGZZWQYBP4-convert-to-new-ulid-type.ts index 2ec1df44..05ddf52f 100644 --- a/libs/db/migrations/src/01H5TV87JJ3CE73WBGZZWQYBP4-convert-to-new-ulid-type.ts +++ b/libs/db/migrations/src/01H5TV87JJ3CE73WBGZZWQYBP4-convert-to-new-ulid-type.ts @@ -105,12 +105,29 @@ export const up = async (db: Kysely): Promise => { .alterTable('local_login') .dropConstraint('local_login_login_method_id_fkey') .execute(); + await db.schema + .alterTable('verification_token') + .dropConstraint('verification_token_user_id_fkey') + .execute(); + await migrateTableColumnToUlid(db, 'verification_token', 'id', true); + await migrateTableColumnToUlid(db, 'verification_token', 'user_id'); await migrateTableColumnToUlid(db, 'role', 'id', true); await migrateTableColumnToUlid(db, 'local_login', 'id', true); await migrateTableColumnToUlid(db, 'local_login', 'login_method_id'); await migrateTableColumnToUlid(db, 'login_method', 'id', true); await migrateTableColumnToUlid(db, 'login_method', 'user_id'); await migrateTableColumnToUlid(db, 'user_account', 'id', true); + await recreateForeignKey( + db, + 'verification_token', + 'user_id', + 'user_account', + 'id' + ); + await db.schema + .alterTable('verification_token') + .dropColumn('expires_at') + .execute(); await migrateTableColumnToUlid(db, 'user_permission', 'id', true); await migrateTableColumnToUlid(db, 'user_permission', 'user_id'); await migrateTableColumnToUlid(db, 'user_permission', 'role_id');