30 lines
1.7 KiB
PL/PgSQL
30 lines
1.7 KiB
PL/PgSQL
BEGIN;
|
|
CREATE TABLE "team_function_configs" (
|
|
"id" TEXT NOT NULL,
|
|
"organization_unit_id" TEXT NOT NULL,
|
|
"lead_employee_profile_id" TEXT,
|
|
"description" TEXT NOT NULL DEFAULT '',
|
|
"branches" JSONB NOT NULL DEFAULT '[]',
|
|
"revision" INTEGER NOT NULL DEFAULT 1,
|
|
"updated_by_user_id" TEXT NOT NULL,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
CONSTRAINT "team_function_configs_pkey" PRIMARY KEY ("id"),
|
|
CONSTRAINT "team_function_configs_revision_check" CHECK ("revision" > 0)
|
|
);
|
|
CREATE UNIQUE INDEX "team_function_configs_organization_unit_id_key" ON "team_function_configs"("organization_unit_id");
|
|
ALTER TABLE "team_function_configs" ADD CONSTRAINT "team_function_configs_organization_unit_id_fkey" FOREIGN KEY ("organization_unit_id") REFERENCES "organization_units"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
ALTER TABLE "team_function_configs" ADD CONSTRAINT "team_function_configs_lead_employee_profile_id_fkey" FOREIGN KEY ("lead_employee_profile_id") REFERENCES "performance_survey_employee_profiles"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
CREATE TABLE "team_function_config_audits" (
|
|
"id" TEXT NOT NULL,
|
|
"config_id" TEXT NOT NULL,
|
|
"actor_user_id" TEXT NOT NULL,
|
|
"before" JSONB,
|
|
"after" JSONB NOT NULL,
|
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
CONSTRAINT "team_function_config_audits_pkey" PRIMARY KEY ("id")
|
|
);
|
|
CREATE INDEX "team_function_config_audits_config_id_created_at_idx" ON "team_function_config_audits"("config_id", "created_at");
|
|
ALTER TABLE "team_function_config_audits" ADD CONSTRAINT "team_function_config_audits_config_id_fkey" FOREIGN KEY ("config_id") REFERENCES "team_function_configs"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
COMMIT;
|