Skip to content

Commit d15aee2

Browse files
committed
🗃️ Define planVersion model
1 parent a86e5d5 commit d15aee2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/db/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import project from './models/project';
2222
import plan from './models/plan';
2323
import planEntity from './models/planEntity';
2424
import planEntityVersion from './models/planEntityVersion';
25+
import planVersion from './models/planVersion';
2526
import projectVersion from './models/projectVersion';
2627
import projectVersionAttachment from './models/projectVersionAttachment';
2728
import projectVersionPlan from './models/projectVersionPlan';
@@ -52,6 +53,7 @@ export default (conn: Knex) => ({
5253
plan: plan(conn),
5354
planEntity: planEntity(conn),
5455
planEntityVersion: planEntityVersion(conn),
56+
planVersion: planVersion(conn),
5557
project: project(conn),
5658
projectVersion: projectVersion(conn),
5759
projectVersionAttachment: projectVersionAttachment(conn),

src/db/models/planVersion.ts

+44
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as t from 'io-ts';
22

33
import { brandedType } from '../../util/io-ts';
44
import type { Brand } from '../../util/types';
5+
import { DATE } from '../util/datatypes';
6+
import { defineLegacyVersionedModel } from '../util/legacy-versioned-model';
7+
import { PLAN_ID } from './plan';
8+
import { PLAN_REPORTING_PERIOD_ID } from './planReportingPeriod';
59

610
export type PlanVersionId = Brand<
711
number,
@@ -10,3 +14,43 @@ export type PlanVersionId = Brand<
1014
>;
1115

1216
export const PLAN_VERSION_ID = brandedType<number, PlanVersionId>(t.number);
17+
18+
const PLAN_VERSION_CLUSTER_SELECTION_TYPE = {
19+
single: null,
20+
multi: null,
21+
};
22+
23+
export default defineLegacyVersionedModel({
24+
tableName: 'planVersion',
25+
fields: {
26+
generated: {
27+
id: { kind: 'branded-integer', brand: PLAN_VERSION_ID },
28+
},
29+
nonNullWithDefault: {
30+
isForHPCProjects: { kind: 'checked', type: t.boolean },
31+
},
32+
accidentallyOptional: {
33+
planId: { kind: 'branded-integer', brand: PLAN_ID },
34+
name: { kind: 'checked', type: t.string },
35+
startDate: { kind: 'checked', type: DATE },
36+
endDate: { kind: 'checked', type: DATE },
37+
},
38+
optional: {
39+
comments: { kind: 'checked', type: t.string },
40+
code: { kind: 'checked', type: t.string },
41+
customLocationCode: { kind: 'checked', type: t.string },
42+
currentReportingPeriodId: {
43+
kind: 'branded-integer',
44+
brand: PLAN_REPORTING_PERIOD_ID,
45+
},
46+
lastPublishedReportingPeriodId: { kind: 'checked', type: t.number },
47+
// Even though this column isn't defined using DB enum only two values are used
48+
clusterSelectionType: {
49+
kind: 'enum',
50+
values: PLAN_VERSION_CLUSTER_SELECTION_TYPE,
51+
},
52+
},
53+
},
54+
idField: 'id',
55+
softDeletionEnabled: false,
56+
});

0 commit comments

Comments
 (0)