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

39 lines
990 B
TypeScript
Raw Permalink Normal View History

2024-03-19 09:51:26 -05:00
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();
`);
2024-03-19 09:51:26 -05:00
},
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();
`);
2024-03-19 09:51:26 -05:00
},
};
export default alteration;