From 877e647f49c3a3f9d3195fe32f755f16619b6b28 Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Tue, 21 Jan 2025 13:39:58 +1100 Subject: [PATCH] feat(tenant): delegate tenant configuration so we can have meetings shared between domains --- ...202501211046000_alter_tenant_add_parent.sql | 18 ++++++++++++++++++ src/placeos-models/tenant.cr | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 migration/db/migrations/202501211046000_alter_tenant_add_parent.sql diff --git a/migration/db/migrations/202501211046000_alter_tenant_add_parent.sql b/migration/db/migrations/202501211046000_alter_tenant_add_parent.sql new file mode 100644 index 00000000..94cefdbb --- /dev/null +++ b/migration/db/migrations/202501211046000_alter_tenant_add_parent.sql @@ -0,0 +1,18 @@ +-- +micrate Up +-- SQL in section 'Up' is executed when this migration is applied + +ALTER TABLE tenants ADD COLUMN parent_id BIGINT DEFAULT NULL; + +ALTER TABLE tenants ADD CONSTRAINT fk_tenants_parent_id + FOREIGN KEY (parent_id) + REFERENCES tenants(id) + ON DELETE CASCADE; + +CREATE INDEX IF NOT EXISTS index_tenants_parent_id_idx ON "tenants" USING HASH (parent_id); + +-- +micrate Down +-- SQL section 'Down' is executed when this migration is rolled back + +ALTER TABLE tenants DROP CONSTRAINT fk_tenants_parent_id; +DROP INDEX IF EXISTS index_tenants_parent_id_idx; +ALTER TABLE tenants DROP COLUMN parent_id; diff --git a/src/placeos-models/tenant.cr b/src/placeos-models/tenant.cr index 63336124..a63d0ece 100644 --- a/src/placeos-models/tenant.cr +++ b/src/placeos-models/tenant.cr @@ -9,6 +9,8 @@ module PlaceOS::Model class Tenant < ModelWithAutoKey table :tenants + belongs_to Tenant, foreign_key: "parent_id", association_name: "parent" + attribute name : String? attribute domain : String attribute email_domain : String? = nil