-
-
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.
feat(schemas): init personal access tokens table
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/schemas/alterations/next-1722506508-personal-access-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,33 @@ | ||
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 personal_access_tokens ( | ||
tenant_id varchar(21) not null | ||
references tenants (id) on update cascade on delete cascade, | ||
user_id varchar(21) not null | ||
references users (id) on update cascade on delete cascade, | ||
/** The name of the secret. Should be unique within the user. */ | ||
name varchar(256) not null, | ||
value varchar(64) not null, | ||
created_at timestamptz not null default now(), | ||
expires_at timestamptz, | ||
primary key (tenant_id, user_id, name) | ||
); | ||
`); | ||
await applyTableRls(pool, 'personal_access_tokens'); | ||
}, | ||
down: async (pool) => { | ||
await dropTableRls(pool, 'personal_access_tokens'); | ||
await pool.query(sql` | ||
drop table personal_access_tokens; | ||
`); | ||
}, | ||
}; | ||
|
||
export default alteration; |
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,14 @@ | ||
/* init_order = 2 */ | ||
|
||
create table personal_access_tokens ( | ||
tenant_id varchar(21) not null | ||
references tenants (id) on update cascade on delete cascade, | ||
user_id varchar(21) not null | ||
references users (id) on update cascade on delete cascade, | ||
/** The name of the secret. Should be unique within the user. */ | ||
name varchar(256) not null, | ||
value varchar(64) not null, | ||
created_at timestamptz not null default now(), | ||
expires_at timestamptz, | ||
primary key (tenant_id, user_id, name) | ||
); |