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.15.0-1710859622-add-oidc-standard-claim-properties.ts
2024-04-10 21:27:24 +08:00

38 lines
990 B
TypeScript

import { sql } from '@silverhand/slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {
await pool.query(sql`
alter table users
add column profile jsonb not null default '{}'::jsonb,
add column updated_at timestamptz not null default (now());
`);
await pool.query(sql`
create function set_updated_at() returns trigger as
$$ begin
new.updated_at = now();
return new;
end; $$ language plpgsql;
create trigger set_updated_at
before update on users
for each row
execute procedure set_updated_at();
`);
},
down: async (pool) => {
await pool.query(sql`
alter table users
drop column profile,
drop column updated_at;
`);
await pool.query(sql`
drop trigger set_updated_at on users;
drop function set_updated_at();
`);
},
};
export default alteration;