From f14113b71fec1de54b3da6d628981538dfa00c86 Mon Sep 17 00:00:00 2001 From: Tyagi-Sunny Date: Fri, 27 Sep 2024 17:57:31 +0530 Subject: [PATCH] feat(tenant-management): shgds sdhgs BREAKING CHANGE: yes 43 --- ...0925102459-add-table-tenant-configs-up.sql | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/services/tenant-management-service/migrations/pg/migrations/sqls/20240925102459-add-table-tenant-configs-up.sql b/services/tenant-management-service/migrations/pg/migrations/sqls/20240925102459-add-table-tenant-configs-up.sql index fa27218..9681a4c 100644 --- a/services/tenant-management-service/migrations/pg/migrations/sqls/20240925102459-add-table-tenant-configs-up.sql +++ b/services/tenant-management-service/migrations/pg/migrations/sqls/20240925102459-add-table-tenant-configs-up.sql @@ -3,8 +3,8 @@ CREATE TABLE IF NOT EXISTS main.tenant_configs id uuid NOT NULL DEFAULT (md5(((random())::text || (clock_timestamp())::text)))::uuid, config_key varchar(100) NOT NULL, config_value jsonb NOT NULL, - created_on timestamptz DEFAULT CURRENT_TIMESTAMP, - modified_on timestamptz, + created_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, + modified_on timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL, created_by uuid, modified_by uuid, deleted boolean DEFAULT FALSE NOT NULL, @@ -14,4 +14,20 @@ CREATE TABLE IF NOT EXISTS main.tenant_configs CONSTRAINT pk_tenant_configs_id PRIMARY KEY (id), CONSTRAINT fk_tenant_configs_tenants FOREIGN KEY (tenant_id) REFERENCES main.tenants(id) -) \ No newline at end of file +); + + +CREATE OR REPLACE FUNCTION main.moddatetime() + RETURNS TRIGGER + LANGUAGE plpgsql + AS $function$ +BEGIN + NEW.modified_on = now(); + RETURN NEW; +END; +$function$; + +CREATE TRIGGER mdt_tenant_configs + BEFORE UPDATE ON main.tenant_configs + FOR EACH ROW + EXECUTE FUNCTION main.moddatetime('modified_on');