0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/schemas/alterations/1.19.0-1722926389-argon2d-argon2id.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

import { sql } from '@silverhand/slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {
await pool.query(sql`
alter type users_password_encryption_method add value 'Argon2id';
alter type users_password_encryption_method add value 'Argon2d';
`);
},
down: async (pool) => {
const { rows } = await pool.query(sql`
select id from users
where password_encryption_method = ${'Argon2id'}
or password_encryption_method = ${'Argon2d'}
`);
if (rows.length > 0) {
throw new Error('There are users with password encryption methods Argon2id or Argon2d.');
}
await pool.query(sql`
create type users_password_encryption_method_revised as enum ('Argon2i', 'SHA1', 'SHA256', 'MD5', 'Bcrypt');
alter table users
alter column password_encryption_method type users_password_encryption_method_revised
using password_encryption_method::text::users_password_encryption_method_revised;
drop type users_password_encryption_method;
alter type users_password_encryption_method_revised rename to users_password_encryption_method;
`);
},
};
export default alteration;