From d66d8c22869a5bceaecf15fa6743c99d97fbbfd3 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Wed, 5 Jun 2024 22:33:41 +0800 Subject: [PATCH] feat(schemas): init organization email domains table --- ...75-add-organization-email-domains-table.ts | 31 +++++++++++++++++++ .../tables/organization_email_domains.sql | 13 ++++++++ 2 files changed, 44 insertions(+) create mode 100644 packages/schemas/alterations/next-1717597875-add-organization-email-domains-table.ts create mode 100644 packages/schemas/tables/organization_email_domains.sql diff --git a/packages/schemas/alterations/next-1717597875-add-organization-email-domains-table.ts b/packages/schemas/alterations/next-1717597875-add-organization-email-domains-table.ts new file mode 100644 index 000000000..4b487bb85 --- /dev/null +++ b/packages/schemas/alterations/next-1717597875-add-organization-email-domains-table.ts @@ -0,0 +1,31 @@ +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_email_domains ( + tenant_id varchar(21) not null + references tenants (id) on update cascade on delete cascade, + /** The ID of the organization. */ + organization_id varchar(21) not null + references organizations (id) on update cascade on delete cascade, + /** The email domain that will be automatically provisioned. */ + email_domain varchar(128) not null, + primary key (tenant_id, organization_id, email_domain) + ); + `); + await applyTableRls(pool, 'organization_email_domains'); + }, + down: async (pool) => { + await dropTableRls(pool, 'organization_email_domains'); + await pool.query(sql` + drop table organization_email_domains + `); + }, +}; + +export default alteration; diff --git a/packages/schemas/tables/organization_email_domains.sql b/packages/schemas/tables/organization_email_domains.sql new file mode 100644 index 000000000..63c37332f --- /dev/null +++ b/packages/schemas/tables/organization_email_domains.sql @@ -0,0 +1,13 @@ +/* init_order = 2 */ + +/** The email domains that will be automatically provisioned for an organization. */ +create table organization_email_domains ( + tenant_id varchar(21) not null + references tenants (id) on update cascade on delete cascade, + /** The ID of the organization. */ + organization_id varchar(21) not null + references organizations (id) on update cascade on delete cascade, + /** The email domain that will be automatically provisioned. */ + email_domain varchar(128) not null, + primary key (tenant_id, organization_id, email_domain) +);