From 4e81d8ab94287c0d1eb870cd7b7c448b6705b34f Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:00:45 +0100 Subject: [PATCH 01/16] Define localized string data type --- src/db/models/attachmentPrototype.ts | 5 +---- src/db/models/planEntityVersion.ts | 8 ++------ src/db/models/workflowStatusOption.ts | 5 ++--- src/db/util/datatypes.ts | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/db/models/attachmentPrototype.ts b/src/db/models/attachmentPrototype.ts index f5b4a697..cf58fd22 100644 --- a/src/db/models/attachmentPrototype.ts +++ b/src/db/models/attachmentPrototype.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { LOCALIZED_STRING } from '../util/datatypes'; import { defineIDModel } from '../util/id-model'; import { PLAN_ID } from './plan'; @@ -26,10 +27,6 @@ export const ATTACHMENT_TYPE = t.keyof({ }); export type AttachmentType = t.TypeOf; -const LOCALIZED_STRING = t.type({ - en: t.string, -}); - const FIELDS = t.array( t.type({ name: LOCALIZED_STRING, diff --git a/src/db/models/planEntityVersion.ts b/src/db/models/planEntityVersion.ts index d2b9032b..3e1bb991 100644 --- a/src/db/models/planEntityVersion.ts +++ b/src/db/models/planEntityVersion.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { LOCALIZED_PLURAL_STRING } from '../util/datatypes'; import { defineLegacyVersionedModel } from '../util/legacy-versioned-model'; import { ENTITY_PROTOTYPE_ID } from './entityPrototype'; import { PLAN_ENTITY_ID } from './planEntity'; @@ -29,12 +30,7 @@ export const PLAN_ENTITY_VERSION_VALUE = t.type({ }), ]) ), - type: t.type({ - en: t.type({ - singular: t.string, - plural: t.string, - }), - }), + type: LOCALIZED_PLURAL_STRING, }); export type PlanEntityVersionValue = t.TypeOf; diff --git a/src/db/models/workflowStatusOption.ts b/src/db/models/workflowStatusOption.ts index b69edf99..5964a0e6 100644 --- a/src/db/models/workflowStatusOption.ts +++ b/src/db/models/workflowStatusOption.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { LOCALIZED_STRING } from '../util/datatypes'; import { defineIDModel } from '../util/id-model'; import { PLAN_ID } from './plan'; @@ -33,9 +34,7 @@ export const WORKFLOW_STATUS_OPTION_TYPE = t.keyof({ }); export const WORKFLOW_STATUS_OPTION_VALUE = t.type({ - label: t.type({ - en: t.string, - }), + label: LOCALIZED_STRING, }); export default defineIDModel({ diff --git a/src/db/util/datatypes.ts b/src/db/util/datatypes.ts index d9771d09..e850cd95 100644 --- a/src/db/util/datatypes.ts +++ b/src/db/util/datatypes.ts @@ -49,3 +49,17 @@ export const FILE_REFERENCE = t.type({ }); export type FileReference = t.TypeOf; + +const localized = >(type: T) => + t.type({ + en: type, + }); + +export const LOCALIZED_STRING = localized(t.string); + +export const LOCALIZED_PLURAL_STRING = localized( + t.type({ + singular: t.string, + plural: t.string, + }) +); From 59b954d1703433afc7b049c82988d3adb5df3ea9 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:02:01 +0100 Subject: [PATCH 02/16] Make `planId` in `attachmentPrototype` accidentally optional planId column is marked as NULL-able, but there are zero records in DB withouth this column set --- src/db/models/attachmentPrototype.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/db/models/attachmentPrototype.ts b/src/db/models/attachmentPrototype.ts index cf58fd22..ef24f049 100644 --- a/src/db/models/attachmentPrototype.ts +++ b/src/db/models/attachmentPrototype.ts @@ -56,10 +56,8 @@ export default defineIDModel({ generated: { id: { kind: 'branded-integer', brand: ATTACHMENT_PROTOTYPE_ID }, }, - optional: { - planId: { kind: 'branded-integer', brand: PLAN_ID }, - }, accidentallyOptional: { + planId: { kind: 'branded-integer', brand: PLAN_ID }, refCode: { kind: 'checked', type: t.string }, type: { kind: 'checked', type: ATTACHMENT_TYPE }, value: { kind: 'checked', type: ATTACHMENT_PROTOTYPE_VALUE }, From de88bcfe7a9ba74d6fdfa5e9c7759a1fd3b82761 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:03:56 +0100 Subject: [PATCH 03/16] Make `orderNumber` of `entityPrototype` optional This column is marked as NULL-able, and there are records already which have NULL set for this column. --- src/db/models/entityPrototype.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/entityPrototype.ts b/src/db/models/entityPrototype.ts index 2481d34d..5c9665f2 100644 --- a/src/db/models/entityPrototype.ts +++ b/src/db/models/entityPrototype.ts @@ -44,11 +44,11 @@ export default defineIDModel({ generated: { id: { kind: 'branded-integer', brand: ENTITY_PROTOTYPE_ID }, }, + optional: { orderNumber: { kind: 'checked', type: t.number } }, accidentallyOptional: { refCode: { kind: 'checked', type: ENTITY_PROTOTYPE_REF_CODE }, type: { kind: 'checked', type: ENTITY_PROTOTYPE_TYPE }, planId: { kind: 'checked', type: PLAN_ID }, - orderNumber: { kind: 'checked', type: t.number }, value: { kind: 'checked', type: t.unknown }, }, }, From 40c8728e52c47c66530fdffff1e8ccee62e34a75 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:09:54 +0100 Subject: [PATCH 04/16] Mark `tags` in `governingEntityVersion` optional This column is NULL-able with a DEFAULT value specified to be empty array. But, seems this DEFAULT value wasn't always set, since there are records with NULL value for this column. --- src/db/models/governingEntityVersion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/governingEntityVersion.ts b/src/db/models/governingEntityVersion.ts index 2dd93aa6..613051e6 100644 --- a/src/db/models/governingEntityVersion.ts +++ b/src/db/models/governingEntityVersion.ts @@ -25,6 +25,7 @@ export default defineLegacyVersionedModel({ brand: GOVERNING_ENTITY_VERSION_ID, }, }, + optional: { tags: { kind: 'checked', type: t.array(t.string) } }, accidentallyOptional: { governingEntityId: { kind: 'branded-integer', @@ -33,7 +34,6 @@ export default defineLegacyVersionedModel({ name: { kind: 'checked', type: t.string }, customReference: { kind: 'checked', type: t.string }, value: { kind: 'checked', type: t.unknown }, - tags: { kind: 'checked', type: t.array(t.string) }, }, required: { overriding: { From dee940012595ae4b707d38aad463d3b586872461 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:13:54 +0100 Subject: [PATCH 05/16] Mark `overriding` in `governingEntityVersion` as `nonNullWithDefault` This column is defined with `overriding boolean DEFAULT false NOT NULL` which clearly qualifies it to be marked as nonNullWithDefault --- src/db/models/governingEntityVersion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/models/governingEntityVersion.ts b/src/db/models/governingEntityVersion.ts index 613051e6..81cf32e0 100644 --- a/src/db/models/governingEntityVersion.ts +++ b/src/db/models/governingEntityVersion.ts @@ -35,7 +35,7 @@ export default defineLegacyVersionedModel({ customReference: { kind: 'checked', type: t.string }, value: { kind: 'checked', type: t.unknown }, }, - required: { + nonNullWithDefault: { overriding: { kind: 'checked', type: t.boolean, From 58d35623308f55d006a4b0368c04792c86e92814 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:15:42 +0100 Subject: [PATCH 06/16] Define `implementationStatus` from `project` table as enum column --- src/db/models/project.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/db/models/project.ts b/src/db/models/project.ts index 9f0db52d..05ecb22b 100644 --- a/src/db/models/project.ts +++ b/src/db/models/project.ts @@ -30,6 +30,14 @@ export const PROJECT_VERSION_ID = brandedType( t.number ); +const PROJECT_IMPLEMENTATION_STATUS = { + Planning: null, + Implementing: null, + 'Ended - Completed': null, + 'Ended - Terminated': null, + 'Ended - Not started and abandoned': null, +}; + const PROJECT_PDF_ENTRY = t.type({ /** * TODO: use something more stable, like UNIX OFFSET as a number @@ -60,7 +68,10 @@ export default defineIDModel({ }, optional: { code: { kind: 'checked', type: t.string }, - implementationStatus: { kind: 'checked', type: t.string }, + implementationStatus: { + kind: 'enum', + values: PROJECT_IMPLEMENTATION_STATUS, + }, currentPublishedVersionId: { kind: 'branded-integer', brand: PROJECT_VERSION_ID, From d5c250a5a3788f38567406acc5ab937ac67f30a1 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:18:18 +0100 Subject: [PATCH 07/16] Make `value` and `total` in `projectVersionAttachment` optional These two columns are defined as NULL-able and already have records with NULL values for these columns --- src/db/models/projectVersionAttachment.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/db/models/projectVersionAttachment.ts b/src/db/models/projectVersionAttachment.ts index 53191c97..d43dc761 100644 --- a/src/db/models/projectVersionAttachment.ts +++ b/src/db/models/projectVersionAttachment.ts @@ -13,6 +13,8 @@ export default defineSequelizeModel({ kind: 'branded-integer', brand: ATTACHMENT_VERSION_ID, }, + }, + optional: { value: { kind: 'checked', type: t.unknown }, total: { kind: 'checked', type: t.number }, }, From 3249ccc7eaba38f9c90464313a34bdc3288088d2 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 16:46:43 +0100 Subject: [PATCH 08/16] =?UTF-8?q?=F0=9F=8E=A8=20Sort=20model=20imports=20a?= =?UTF-8?q?lphabetically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/index.ts b/src/db/index.ts index 75b042bb..6f7ea374 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -17,10 +17,10 @@ import governingEntityVersion from './models/governingEntityVersion'; import operation from './models/operation'; import operationCluster from './models/operationCluster'; import participant from './models/participant'; -import project from './models/project'; import plan from './models/plan'; import planEntity from './models/planEntity'; import planEntityVersion from './models/planEntityVersion'; +import project from './models/project'; import projectVersion from './models/projectVersion'; import projectVersionAttachment from './models/projectVersionAttachment'; import projectVersionPlan from './models/projectVersionPlan'; From 759b3944d6b532266852c0ff51c4cb528dda0e4e Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:44:01 +0100 Subject: [PATCH 09/16] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20Typescript?= =?UTF-8?q?=20to=20`^4.4.4`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/util/async.ts | 4 +++- yarn.lock | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d90ef703..caf737f4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "husky": "^7.0.2", "lint-staged": "^11.2.4", "prettier": "2.4.1", - "typescript": "^4.3.5" + "typescript": "^4.4.4" }, "lint-staged": { "*.{ts,js}": [ diff --git a/src/util/async.ts b/src/util/async.ts index 8731ac7d..f4a2325b 100644 --- a/src/util/async.ts +++ b/src/util/async.ts @@ -44,7 +44,9 @@ export const createGroupableAsyncFunction = < } } catch (err) { for (const call of cs) { - call.reject(err); + if (err instanceof Error) { + call.reject(err); + } } } }; diff --git a/yarn.lock b/yarn.lock index 8187a3d5..7cd58c79 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2256,10 +2256,10 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -typescript@^4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@^4.4.4: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== unc-path-regex@^0.1.2: version "0.1.2" From 260eefbed8563fabc7c67120890ad3dbf05b9b16 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:45:23 +0100 Subject: [PATCH 10/16] =?UTF-8?q?=F0=9F=99=88=20Add=20`.vscode`=20to=20git?= =?UTF-8?q?ignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 44a9bf14..a7cda6e4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ /index.d.ts /yarn-error.log package-lock.json + +# IDE artifacts +.vscode From e2ff8fa605a3b43a71e3a785ac44e27630eaea58 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:46:44 +0100 Subject: [PATCH 11/16] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Define=20`locatio?= =?UTF-8?q?n`=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 ++ src/db/models/location.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/db/index.ts b/src/db/index.ts index 6f7ea374..b3b02525 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -14,6 +14,7 @@ import expiredData from './models/expiredData'; import form from './models/form'; import governingEntity from './models/governingEntity'; import governingEntityVersion from './models/governingEntityVersion'; +import location from './models/location'; import operation from './models/operation'; import operationCluster from './models/operationCluster'; import participant from './models/participant'; @@ -44,6 +45,7 @@ export default (conn: Knex) => ({ form: form(conn), governingEntity: governingEntity(conn), governingEntityVersion: governingEntityVersion(conn), + location: location(conn), operation: operation(conn), operationCluster: operationCluster(conn), participant: participant(conn), diff --git a/src/db/models/location.ts b/src/db/models/location.ts index 2922fb3d..2e0e47ab 100644 --- a/src/db/models/location.ts +++ b/src/db/models/location.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { defineIDModel } from '../util/id-model'; export type LocationId = Brand< number, @@ -10,3 +11,39 @@ export type LocationId = Brand< >; export const LOCATION_ID = brandedType(t.number); + +const LOCATION_STATUS = { + active: null, + expired: null, +}; + +export default defineIDModel({ + tableName: 'location', + fields: { + generated: { + id: { kind: 'branded-integer', brand: LOCATION_ID }, + }, + optional: { + externalId: { kind: 'checked', type: t.string }, + name: { kind: 'checked', type: t.string }, + latitude: { kind: 'checked', type: t.number }, + longitude: { kind: 'checked', type: t.number }, + iso3: { kind: 'checked', type: t.string }, + pcode: { kind: 'checked', type: t.string }, + // Even though this column is defined as int8, it is + // fetched as a string by knex, since it is bigint + validOn: { kind: 'checked', type: t.string }, + parentId: { kind: 'branded-integer', brand: LOCATION_ID }, + }, + accidentallyOptional: { + adminLevel: { kind: 'checked', type: t.number }, + status: { + kind: 'enum', + values: LOCATION_STATUS, + }, + itosSync: { kind: 'checked', type: t.boolean }, + }, + }, + idField: 'id', + softDeletionEnabled: false, +}); From f3fdb876bce22ca2785e96ebd3bb9dfa3f83f50a Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:48:18 +0100 Subject: [PATCH 12/16] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Define=20`planVer?= =?UTF-8?q?sion`=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 ++ src/db/models/planVersion.ts | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/db/index.ts b/src/db/index.ts index b3b02525..2f12acbb 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -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'; @@ -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), diff --git a/src/db/models/planVersion.ts b/src/db/models/planVersion.ts index 81fc5579..696e2ea6 100644 --- a/src/db/models/planVersion.ts +++ b/src/db/models/planVersion.ts @@ -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, @@ -10,3 +14,43 @@ export type PlanVersionId = Brand< >; export const PLAN_VERSION_ID = brandedType(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, + }, + }, + }, + idField: 'id', + softDeletionEnabled: false, +}); From 2c37036b0a7751368c302dece8ef5e6194812108 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:48:53 +0100 Subject: [PATCH 13/16] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Define=20`planYea?= =?UTF-8?q?r`=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 ++ src/db/models/planYear.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/db/index.ts b/src/db/index.ts index 2f12acbb..c41ba44e 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -22,6 +22,7 @@ import plan from './models/plan'; import planEntity from './models/planEntity'; import planEntityVersion from './models/planEntityVersion'; import planVersion from './models/planVersion'; +import planYear from './models/planYear'; import project from './models/project'; import projectVersion from './models/projectVersion'; import projectVersionAttachment from './models/projectVersionAttachment'; @@ -54,6 +55,7 @@ export default (conn: Knex) => ({ planEntity: planEntity(conn), planEntityVersion: planEntityVersion(conn), planVersion: planVersion(conn), + planYear: planYear(conn), project: project(conn), projectVersion: projectVersion(conn), projectVersionAttachment: projectVersionAttachment(conn), diff --git a/src/db/models/planYear.ts b/src/db/models/planYear.ts index dae22db9..b60c7095 100644 --- a/src/db/models/planYear.ts +++ b/src/db/models/planYear.ts @@ -2,6 +2,9 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { defineLegacyVersionedModel } from '../util/legacy-versioned-model'; +import { PLAN_ID } from './plan'; +import { USAGE_YEAR_ID } from './usageYear'; export type PlanYearId = Brand< number, @@ -10,3 +13,18 @@ export type PlanYearId = Brand< >; export const PLAN_YEAR_ID = brandedType(t.number); + +export default defineLegacyVersionedModel({ + tableName: 'planYear', + fields: { + generated: { + id: { kind: 'branded-integer', brand: PLAN_YEAR_ID }, + }, + required: { + planId: { kind: 'branded-integer', brand: PLAN_ID }, + usageYearId: { kind: 'branded-integer', brand: USAGE_YEAR_ID }, + }, + }, + idField: 'id', + softDeletionEnabled: true, +}); From 70b2c298b8b31a0620a8811b20ab8cd80b135e71 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:49:22 +0100 Subject: [PATCH 14/16] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Define=20`usageYe?= =?UTF-8?q?ar`=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 ++ src/db/models/usageYear.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/db/index.ts b/src/db/index.ts index c41ba44e..76df6ae2 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -29,6 +29,7 @@ import projectVersionAttachment from './models/projectVersionAttachment'; import projectVersionPlan from './models/projectVersionPlan'; import reportingWindow from './models/reportingWindow'; import reportingWindowAssignment from './models/reportingWindowAssignment'; +import usageYear from './models/usageYear'; import workflowStatusOption from './models/workflowStatusOption'; export default (conn: Knex) => ({ @@ -62,5 +63,6 @@ export default (conn: Knex) => ({ projectVersionPlan: projectVersionPlan(conn), reportingWindow: reportingWindow(conn), reportingWindowAssignment: reportingWindowAssignment(conn), + usageYear: usageYear(conn), workflowStatusOption: workflowStatusOption(conn), }); diff --git a/src/db/models/usageYear.ts b/src/db/models/usageYear.ts index 4defd8a8..b775ac0f 100644 --- a/src/db/models/usageYear.ts +++ b/src/db/models/usageYear.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { defineIDModel } from '../util/id-model'; export type UsageYearId = Brand< number, @@ -10,3 +11,17 @@ export type UsageYearId = Brand< >; export const USAGE_YEAR_ID = brandedType(t.number); + +export default defineIDModel({ + tableName: 'usageYear', + fields: { + generated: { + id: { kind: 'branded-integer', brand: USAGE_YEAR_ID }, + }, + required: { + year: { kind: 'checked', type: t.string }, + }, + }, + idField: 'id', + softDeletionEnabled: false, +}); From 948d97d44d2e4eb8659953e824579ea3d62becf0 Mon Sep 17 00:00:00 2001 From: Sam Lanning Date: Wed, 3 Nov 2021 10:35:24 +0000 Subject: [PATCH 15/16] Make enum properties checked keyof strings --- src/db/models/location.ts | 8 ++++---- src/db/models/planVersion.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/db/models/location.ts b/src/db/models/location.ts index 2e0e47ab..1aeab583 100644 --- a/src/db/models/location.ts +++ b/src/db/models/location.ts @@ -12,10 +12,10 @@ export type LocationId = Brand< export const LOCATION_ID = brandedType(t.number); -const LOCATION_STATUS = { +const LOCATION_STATUS = t.keyof({ active: null, expired: null, -}; +}); export default defineIDModel({ tableName: 'location', @@ -38,8 +38,8 @@ export default defineIDModel({ accidentallyOptional: { adminLevel: { kind: 'checked', type: t.number }, status: { - kind: 'enum', - values: LOCATION_STATUS, + kind: 'checked', + type: LOCATION_STATUS, }, itosSync: { kind: 'checked', type: t.boolean }, }, diff --git a/src/db/models/planVersion.ts b/src/db/models/planVersion.ts index 696e2ea6..e09551cc 100644 --- a/src/db/models/planVersion.ts +++ b/src/db/models/planVersion.ts @@ -15,10 +15,10 @@ export type PlanVersionId = Brand< export const PLAN_VERSION_ID = brandedType(t.number); -const PLAN_VERSION_CLUSTER_SELECTION_TYPE = { +const PLAN_VERSION_CLUSTER_SELECTION_TYPE = t.keyof({ single: null, multi: null, -}; +}); export default defineLegacyVersionedModel({ tableName: 'planVersion', @@ -46,8 +46,8 @@ export default defineLegacyVersionedModel({ 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, + kind: 'checked', + type: PLAN_VERSION_CLUSTER_SELECTION_TYPE, }, }, }, From ff4df88c79d45ea0b4723699552515a6a28f912f Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 18:22:19 +0100 Subject: [PATCH 16/16] =?UTF-8?q?=F0=9F=94=96=20Bump=20version=20to=20`0.2?= =?UTF-8?q?.0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index caf737f4..ba4226d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@unocha/hpc-api-core", - "version": "0.1.0", + "version": "0.2.0", "description": "Core libraries supporting HPC.Tools API Backend", "license": "Apache-2.0", "private": false,