-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/schemas/alterations/next-1718527764-add-subject-tokens.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { sql } from '@silverhand/slonik'; | ||
|
||
import type { AlterationScript } from '../lib/types/alteration.js'; | ||
|
||
import { applyTableRls, dropTableRls } from './utils/1704934999-tables.js'; | ||
|
||
const alteration: AlterationScript = { | ||
up: async (pool) => { | ||
await pool.query(sql` | ||
create table subject_tokens ( | ||
tenant_id varchar(21) not null | ||
references tenants (id) on update cascade on delete cascade, | ||
id varchar(24) not null, | ||
context jsonb /* @use JsonObject */ not null default '{}'::jsonb, | ||
expires_at timestamptz not null, | ||
consumed_at timestamptz, | ||
user_id varchar(21) not null | ||
references users (id) on update cascade on delete cascade, | ||
created_at timestamptz not null default(now()), | ||
creator_id varchar(32) not null, /* It is intented to not reference to user or application table */ | ||
primary key (id) | ||
); | ||
create index subject_token__id on subject_tokens (tenant_id, id); | ||
`); | ||
await applyTableRls(pool, 'subject_tokens'); | ||
}, | ||
down: async (pool) => { | ||
await dropTableRls(pool, 'subject_tokens'); | ||
await pool.query(sql` | ||
drop table subject_tokens | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |