0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(schemas): add organization role resource scope relation

This commit is contained in:
wangsijie 2024-04-01 15:13:44 +08:00
parent 9bf9f07f17
commit 12f464c09b
No known key found for this signature in database
GPG key ID: C72642FE24F7D42B
2 changed files with 42 additions and 0 deletions

View file

@ -0,0 +1,30 @@
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 organization_role_resource_scope_relations (
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
organization_role_id varchar(21) not null
references organization_roles (id) on update cascade on delete cascade,
resource_scope_id varchar(21) not null
references scopes (id) on update cascade on delete cascade,
primary key (tenant_id, organization_role_id, resource_scope_id)
);
`);
await applyTableRls(pool, 'organization_role_resource_scope_relations');
},
down: async (pool) => {
await dropTableRls(pool, 'organization_role_resource_scope_relations');
await pool.query(sql`
drop table organization_role_resource_scope_relations
`);
},
};
export default alteration;

View file

@ -0,0 +1,12 @@
/* init_order = 3 */
/** The relations between organization roles and resource scopes (normal scopes). It indicates which resource scopes are available to which organization roles. */
create table organization_role_resource_scope_relations (
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
organization_role_id varchar(21) not null
references organization_roles (id) on update cascade on delete cascade,
resource_scope_id varchar(21) not null
references scopes (id) on update cascade on delete cascade,
primary key (tenant_id, organization_role_id, resource_scope_id)
);