2024-11-17 22:50:21 -05:00
|
|
|
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,
|
2024-11-20 02:42:29 -05:00
|
|
|
private_key text not null,
|
|
|
|
certificate text not null,
|
2024-11-17 22:50:21 -05:00
|
|
|
created_at timestamptz not null default now(),
|
|
|
|
expires_at timestamptz not null,
|
|
|
|
active boolean not null,
|
2024-11-19 01:06:28 -05:00
|
|
|
primary key (tenant_id, application_id, id),
|
2024-11-17 22:50:21 -05:00
|
|
|
constraint application_type
|
|
|
|
check (check_application_type(application_id, 'SAML'))
|
|
|
|
);
|
|
|
|
|
|
|
|
create unique index saml_application_secrets__unique_active_secret
|
2024-11-19 01:06:28 -05:00
|
|
|
on saml_application_secrets (tenant_id, application_id, active)
|
2024-11-17 22:50:21 -05:00
|
|
|
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;
|