Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define models needed for HPC-7904 #30

Merged
merged 16 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import participant from './models/participant';
import plan from './models/plan';
import planEntity from './models/planEntity';
import planEntityVersion from './models/planEntityVersion';
import planVersion from './models/planVersion';
import project from './models/project';
import projectVersion from './models/projectVersion';
import projectVersionAttachment from './models/projectVersionAttachment';
Expand Down Expand Up @@ -52,6 +53,7 @@ export default (conn: Knex) => ({
plan: plan(conn),
planEntity: planEntity(conn),
planEntityVersion: planEntityVersion(conn),
planVersion: planVersion(conn),
project: project(conn),
projectVersion: projectVersion(conn),
projectVersionAttachment: projectVersionAttachment(conn),
Expand Down
44 changes: 44 additions & 0 deletions src/db/models/planVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as t from 'io-ts';

import { brandedType } from '../../util/io-ts';
import type { Brand } from '../../util/types';
import { DATE } from '../util/datatypes';
import { defineLegacyVersionedModel } from '../util/legacy-versioned-model';
import { PLAN_ID } from './plan';
import { PLAN_REPORTING_PERIOD_ID } from './planReportingPeriod';

export type PlanVersionId = Brand<
number,
Expand All @@ -10,3 +14,43 @@ export type PlanVersionId = Brand<
>;

export const PLAN_VERSION_ID = brandedType<number, PlanVersionId>(t.number);

const PLAN_VERSION_CLUSTER_SELECTION_TYPE = {
single: null,
multi: null,
};

export default defineLegacyVersionedModel({
tableName: 'planVersion',
fields: {
generated: {
id: { kind: 'branded-integer', brand: PLAN_VERSION_ID },
},
nonNullWithDefault: {
isForHPCProjects: { kind: 'checked', type: t.boolean },
},
accidentallyOptional: {
planId: { kind: 'branded-integer', brand: PLAN_ID },
name: { kind: 'checked', type: t.string },
startDate: { kind: 'checked', type: DATE },
endDate: { kind: 'checked', type: DATE },
},
optional: {
comments: { kind: 'checked', type: t.string },
code: { kind: 'checked', type: t.string },
customLocationCode: { kind: 'checked', type: t.string },
currentReportingPeriodId: {
kind: 'branded-integer',
brand: PLAN_REPORTING_PERIOD_ID,
},
lastPublishedReportingPeriodId: { kind: 'checked', type: t.number },
// Even though this column isn't defined using DB enum only two values are used
clusterSelectionType: {
kind: 'enum',
values: PLAN_VERSION_CLUSTER_SELECTION_TYPE,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use a checked t.keyof type instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have removed this comment above too. Since it "justifies" why 'enum' was used

},
},
idField: 'id',
softDeletionEnabled: false,
});