chore: fix up the migrations a little bit so that it supports adding columns

Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
benjdlambert
2025-07-08 09:48:46 +02:00
parent b748b42f63
commit dc32e0c8a2
3 changed files with 50 additions and 4 deletions
@@ -40,7 +40,7 @@ export class UserInfoDatabase {
.insert({
user_entity_ref: userInfo.claims.sub as string,
user_info: JSON.stringify(userInfo),
updated_at: DateTime.now().toSQL({ includeOffset: false }),
updated_at: DateTime.utc().toSQL(),
})
.onConflict('user_entity_ref')
.merge();
+34 -1
View File
@@ -136,8 +136,41 @@ describe('migrations', () => {
const { created_at, updated_at } = await knex('user_info').first();
expect(updated_at).toBe(exp);
expect(created_at).toBeDefined();
await knex
.insert({
user_entity_ref: 'user:default/backstage-user',
user_info,
updated_at: knex.fn.now(),
})
.into('user_info')
.onConflict(['user_entity_ref'])
.merge();
await knex
.insert({
user_entity_ref: 'user:default/backstage-user-2',
user_info,
updated_at: knex.fn.now(),
})
.into('user_info');
await expect(
knex('user_info').select('created_at', 'updated_at'),
).resolves.toEqual([
{ created_at: expect.any(String), updated_at: expect.any(String) },
{ created_at: expect.any(String), updated_at: expect.any(String) },
]);
await migrateDownOnce(knex);
await expect(knex('user_info').select('exp')).resolves.toEqual([
{ exp: expect.any(String) },
{ exp: expect.any(String) },
]);
await knex.destroy();
},
);
});