Mehrere Stichtage pro Zeitraum verwalten
All checks were successful
CI / Build and Deploy (push) Successful in 2m43s
All checks were successful
CI / Build and Deploy (push) Successful in 2m43s
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
CREATE TABLE "period_cutoffs" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"date" TIMESTAMP(3),
|
||||
"period_id" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "period_cutoffs_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "period_cutoffs_period_id_idx" ON "period_cutoffs"("period_id");
|
||||
|
||||
ALTER TABLE "period_cutoffs"
|
||||
ADD CONSTRAINT "period_cutoffs_period_id_fkey"
|
||||
FOREIGN KEY ("period_id") REFERENCES "accounting_periods"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "expenses" ADD COLUMN "cutoff_id" TEXT;
|
||||
|
||||
INSERT INTO "period_cutoffs" ("id", "name", "date", "period_id", "created_at", "updated_at")
|
||||
SELECT
|
||||
'cutoff_' || md5("id"),
|
||||
COALESCE(NULLIF("cutoff_name", ''), 'Open Air'),
|
||||
"cutoff_date",
|
||||
"id",
|
||||
CURRENT_TIMESTAMP,
|
||||
CURRENT_TIMESTAMP
|
||||
FROM "accounting_periods";
|
||||
|
||||
UPDATE "expenses"
|
||||
SET "cutoff_id" = 'cutoff_' || md5("period_id");
|
||||
|
||||
ALTER TABLE "expenses"
|
||||
ADD CONSTRAINT "expenses_cutoff_id_fkey"
|
||||
FOREIGN KEY ("cutoff_id") REFERENCES "period_cutoffs"("id")
|
||||
ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
Reference in New Issue
Block a user