-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add db migration for Upload, ExpenditureCategory, and UploadVal…
…idation
- Loading branch information
Showing
2 changed files
with
621 additions
and
502 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...grations/20231208211141_add_upload_expenditurecategory_and_uploadvalidation/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
-- CreateTable | ||
CREATE TABLE "ExpenditureCategory" ( | ||
"id" SERIAL NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"code" TEXT NOT NULL, | ||
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMPTZ(6) NOT NULL, | ||
|
||
CONSTRAINT "ExpenditureCategory_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Upload" ( | ||
"id" SERIAL NOT NULL, | ||
"filename" TEXT NOT NULL, | ||
"uploadedById" INTEGER NOT NULL, | ||
"agencyId" INTEGER NOT NULL, | ||
"organizationId" INTEGER NOT NULL, | ||
"reportingPeriodId" INTEGER NOT NULL, | ||
"expenditureCategoryId" INTEGER NOT NULL, | ||
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMPTZ(6) NOT NULL, | ||
|
||
CONSTRAINT "Upload_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "UploadValidation" ( | ||
"id" SERIAL NOT NULL, | ||
"uploadId" INTEGER NOT NULL, | ||
"agencyId" INTEGER NOT NULL, | ||
"organizationId" INTEGER NOT NULL, | ||
"inputTemplateId" INTEGER NOT NULL, | ||
"validationResults" JSONB, | ||
"validatedAt" TIMESTAMPTZ(6), | ||
"validatedById" INTEGER, | ||
"invalidationResults" JSONB, | ||
"invalidatedAt" TIMESTAMPTZ(6), | ||
"invalidatedById" INTEGER, | ||
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMPTZ(6) NOT NULL, | ||
|
||
CONSTRAINT "UploadValidation_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_agencyId_fkey" FOREIGN KEY ("agencyId") REFERENCES "Agency"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_reportingPeriodId_fkey" FOREIGN KEY ("reportingPeriodId") REFERENCES "ReportingPeriod"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Upload" ADD CONSTRAINT "Upload_expenditureCategoryId_fkey" FOREIGN KEY ("expenditureCategoryId") REFERENCES "ExpenditureCategory"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_uploadId_fkey" FOREIGN KEY ("uploadId") REFERENCES "Upload"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_agencyId_fkey" FOREIGN KEY ("agencyId") REFERENCES "Agency"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_inputTemplateId_fkey" FOREIGN KEY ("inputTemplateId") REFERENCES "InputTemplate"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_validatedById_fkey" FOREIGN KEY ("validatedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "UploadValidation" ADD CONSTRAINT "UploadValidation_invalidatedById_fkey" FOREIGN KEY ("invalidatedById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
Oops, something went wrong.