Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schemas): add saml_application_secres table #6816

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 saml_application_secrets (
id varchar(21) not null,
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
application_id varchar(21) not null
references applications (id) on update cascade on delete cascade,
private_key text not null,
certificate text not null,
created_at timestamptz not null default now(),
expires_at timestamptz not null,
active boolean not null,
primary key (tenant_id, application_id, id),
constraint application_type
check (check_application_type(application_id, 'SAML'))
);

create unique index saml_application_secrets__unique_active_secret
on saml_application_secrets (tenant_id, application_id, active)
where active;
`);
await applyTableRls(pool, 'saml_application_secrets');
},
down: async (pool) => {
await dropTableRls(pool, 'saml_application_secrets');
await pool.query(sql`
drop table saml_application_secrets;
`);
},
};

export default alteration;
22 changes: 22 additions & 0 deletions packages/schemas/tables/saml_application_secrets.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* init_order = 2 */

create table saml_application_secrets (
id varchar(21) not null,
tenant_id varchar(21) not null
references tenants (id) on update cascade on delete cascade,
application_id varchar(21) not null
references applications (id) on update cascade on delete cascade,
private_key text not null,
darcyYe marked this conversation as resolved.
Show resolved Hide resolved
certificate text not null,
created_at timestamptz not null default now(),
expires_at timestamptz not null,
active boolean not null,
primary key (tenant_id, application_id, id),
constraint application_type
check (check_application_type(application_id, 'SAML'))
);

-- Only one active secret per application
create unique index saml_application_secrets__unique_active_secret
on saml_application_secrets (tenant_id, application_id, active)
where active;
Loading