@dvsa/cvs-db-schemas 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,24 @@
1
+ import type { MySqlColumn } from 'drizzle-orm/mysql-core';
2
+ import type { SQL } from 'drizzle-orm/sql/sql';
1
3
  /**
2
4
  * Format schema name to append a branch identifier if on a CB2 branch
3
5
  * @param {string} baseSchemaName
4
6
  * @return {string} Formatted schema name
5
7
  *
6
8
  * @examples
7
- * process.env.BRANCH = 'prod'
9
+ * process.env.BRANCH = 'prod';
8
10
  * const schema = formatSchemaName('test_facility');
9
- * // test_facility
11
+ * console.log(schema); // test_facility
10
12
  *
11
- * process.env.BRANCH = 'cb2-1234'
13
+ * process.env.BRANCH = 'cb2-1234';
12
14
  * const schema = formatSchemaName('test_facility');
13
- * // test_facility_CB21234
15
+ * console.log(schema); // test_facility_CB21234
14
16
  */
15
17
  export declare const formatSchemaName: (baseSchemaName: string) => string;
18
+ /**
19
+ * Convert a MySQL column that uses 1/0 for boolean values into an actual boolean type in the query result
20
+ * @param {MySqlColumn} column
21
+ * @param {string} alias - Optional Alias, defaults back to `column.name` otherwise
22
+ * @return {boolean}
23
+ */
24
+ export declare const toBoolean: (column: MySqlColumn, alias?: string | undefined) => SQL.Aliased<boolean>;
@@ -1,23 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatSchemaName = void 0;
3
+ exports.toBoolean = exports.formatSchemaName = void 0;
4
+ const drizzle_orm_1 = require("drizzle-orm");
4
5
  /**
5
6
  * Format schema name to append a branch identifier if on a CB2 branch
6
7
  * @param {string} baseSchemaName
7
8
  * @return {string} Formatted schema name
8
9
  *
9
10
  * @examples
10
- * process.env.BRANCH = 'prod'
11
+ * process.env.BRANCH = 'prod';
11
12
  * const schema = formatSchemaName('test_facility');
12
- * // test_facility
13
+ * console.log(schema); // test_facility
13
14
  *
14
- * process.env.BRANCH = 'cb2-1234'
15
+ * process.env.BRANCH = 'cb2-1234';
15
16
  * const schema = formatSchemaName('test_facility');
16
- * // test_facility_CB21234
17
+ * console.log(schema); // test_facility_CB21234
17
18
  */
18
19
  const formatSchemaName = (baseSchemaName) => {
19
- return process.env.BRANCH?.includes('cb2')
20
- ? `${baseSchemaName}_${process.env.BRANCH.toUpperCase().replace('-', '')}`
21
- : baseSchemaName;
20
+ const branch = process.env.BRANCH?.toUpperCase();
21
+ return branch?.includes('CB2') ? `${baseSchemaName}_${branch.replace('-', '')}` : baseSchemaName;
22
22
  };
23
23
  exports.formatSchemaName = formatSchemaName;
24
+ /**
25
+ * Convert a MySQL column that uses 1/0 for boolean values into an actual boolean type in the query result
26
+ * @param {MySqlColumn} column
27
+ * @param {string} alias - Optional Alias, defaults back to `column.name` otherwise
28
+ * @return {boolean}
29
+ */
30
+ const toBoolean = (column, alias = undefined) => (0, drizzle_orm_1.sql) `IF(${column} = 1, CAST(TRUE AS JSON), CAST(FALSE AS JSON))`.as(alias ?? column.name);
31
+ exports.toBoolean = toBoolean;
@@ -1,3 +1,20 @@
1
+ /**
2
+ * @generated-schema-doc
3
+ * Schema: `outbox` | Table: `outbox`
4
+ *
5
+ * | Column | Type | Nullable | Constraints |
6
+ * | ------------- | ------------------------------------------------------ | -------- | -------------------------- |
7
+ * | id | serial | No | PK, NOT NULL |
8
+ * | eventType | enum(created, updated, deleted) | No | NOT NULL |
9
+ * | aggregateType | enum(activity, tech-record, test-result, test-station) | No | NOT NULL |
10
+ * | payload | json | No | NOT NULL |
11
+ * | status | enum(pending, completed, failed) | No | NOT NULL, default: pending |
12
+ * | attemptCount | int | No | NOT NULL, default: 0 |
13
+ * | createdAt | datetime(3) | Yes | default: sql`(now(3 |
14
+ * | updatedAt | datetime(3) | Yes | default: sql`(now(3 |
15
+ * | errorMessage | text | Yes | |
16
+ * | completedAt | datetime | Yes | |
17
+ */
1
18
  export declare const outbox: import("drizzle-orm/mysql-core").MySqlTableWithColumns<{
2
19
  name: "outbox";
3
20
  schema: string;
@@ -158,9 +175,9 @@ export declare const outbox: import("drizzle-orm/mysql-core").MySqlTableWithColu
158
175
  completedAt: import("drizzle-orm/mysql-core").MySqlColumn<{
159
176
  name: "completed_at";
160
177
  tableName: "outbox";
161
- dataType: "date";
162
- columnType: "MySqlDateTime";
163
- data: Date;
178
+ dataType: "string";
179
+ columnType: "MySqlDateTimeString";
180
+ data: string;
164
181
  driverParam: string | number;
165
182
  notNull: false;
166
183
  hasDefault: false;
package/outbox/outbox.js CHANGED
@@ -4,6 +4,23 @@ exports.outbox = void 0;
4
4
  const drizzle_orm_1 = require("drizzle-orm");
5
5
  const mysql_core_1 = require("drizzle-orm/mysql-core");
6
6
  const format_schema_name_1 = require("../helper/format-schema-name");
7
+ /**
8
+ * @generated-schema-doc
9
+ * Schema: `outbox` | Table: `outbox`
10
+ *
11
+ * | Column | Type | Nullable | Constraints |
12
+ * | ------------- | ------------------------------------------------------ | -------- | -------------------------- |
13
+ * | id | serial | No | PK, NOT NULL |
14
+ * | eventType | enum(created, updated, deleted) | No | NOT NULL |
15
+ * | aggregateType | enum(activity, tech-record, test-result, test-station) | No | NOT NULL |
16
+ * | payload | json | No | NOT NULL |
17
+ * | status | enum(pending, completed, failed) | No | NOT NULL, default: pending |
18
+ * | attemptCount | int | No | NOT NULL, default: 0 |
19
+ * | createdAt | datetime(3) | Yes | default: sql`(now(3 |
20
+ * | updatedAt | datetime(3) | Yes | default: sql`(now(3 |
21
+ * | errorMessage | text | Yes | |
22
+ * | completedAt | datetime | Yes | |
23
+ */
7
24
  exports.outbox = (0, mysql_core_1.mysqlSchema)((0, format_schema_name_1.formatSchemaName)('outbox')).table('outbox', {
8
25
  id: (0, mysql_core_1.serial)().notNull().primaryKey(),
9
26
  eventType: (0, mysql_core_1.mysqlEnum)('event_type', ['created', 'updated', 'deleted']).notNull(),
@@ -14,7 +31,7 @@ exports.outbox = (0, mysql_core_1.mysqlSchema)((0, format_schema_name_1.formatSc
14
31
  createdAt: (0, mysql_core_1.datetime)('created_at', { mode: 'string', fsp: 3 }).default((0, drizzle_orm_1.sql) `(now(3))`),
15
32
  updatedAt: (0, mysql_core_1.datetime)('updated_at', { mode: 'string', fsp: 3 }).default((0, drizzle_orm_1.sql) `(now(3))`),
16
33
  errorMessage: (0, mysql_core_1.text)('error_message'),
17
- completedAt: (0, mysql_core_1.datetime)('completed_at'),
34
+ completedAt: (0, mysql_core_1.datetime)('completed_at', { mode: 'string' }),
18
35
  }, (table) => [
19
36
  (0, mysql_core_1.unique)('uq_outbox_aggregate_uuid_event').on(table.aggregateType, table.id, table.eventType),
20
37
  (0, mysql_core_1.index)('idx_outbox_status_created_at').on(table.status, table.createdAt),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dvsa/cvs-db-schemas",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CVS Drizzle Schema Common Package",
5
5
  "author": "DVSA",
6
6
  "license": "ISC",
@@ -22,7 +22,8 @@
22
22
  "clean:temp": "rimraf auth api",
23
23
  "lint": "biome check src",
24
24
  "lint:fix": "npm run lint -- --write",
25
- "build": "npm run clean && tsc",
25
+ "generate:schema-docs": "node scripts/generate-schema-docs.mjs",
26
+ "build": "npm run clean && npm run generate:schema-docs && tsc",
26
27
  "build:package": "npm run build",
27
28
  "test": "jest --passWithNoTests",
28
29
  "test:coverage": "npm run test -- --coverage",
@@ -1,3 +1,29 @@
1
+ /**
2
+ * @generated-schema-doc
3
+ * Schema: `test_facility` | Table: `activity`
4
+ *
5
+ * | Column | Type | Nullable | Constraints |
6
+ * | ------------------- | --------------- | -------- | -------------------------- |
7
+ * | id | bigint unsigned | No | PK, AUTO INC |
8
+ * | activityUuid | varchar(36) | Yes | |
9
+ * | testerStaffId | varchar(40) | Yes | |
10
+ * | testerStaffName | varchar(100) | Yes | |
11
+ * | testerStaffEmail | varchar(200) | Yes | |
12
+ * | testStationId | bigint unsigned | No | NOT NULL |
13
+ * | parentActivityId | bigint unsigned | Yes | |
14
+ * | activityType | varchar(50) | Yes | |
15
+ * | startDatetime | datetime(3) | Yes | |
16
+ * | endDatetime | datetime(3) | Yes | |
17
+ * | waitReason | varchar(150) | Yes | |
18
+ * | notes | varchar(500) | Yes | |
19
+ * | closureReason | varchar(20) | Yes | |
20
+ * | createdById | varchar(40) | Yes | |
21
+ * | createdByName | varchar(200) | Yes | |
22
+ * | insertedDatetime | datetime(3) | Yes | default: CURRENT_TIMESTAMP |
23
+ * | lastUpdatedById | varchar(40) | Yes | |
24
+ * | lastUpdatedByName | varchar(200) | Yes | |
25
+ * | lastUpdatedDatetime | datetime(3) | Yes | default: CURRENT_TIMESTAMP |
26
+ */
1
27
  export declare const activity: import("drizzle-orm/mysql-core").MySqlTableWithColumns<{
2
28
  name: "activity";
3
29
  schema: string;
@@ -4,6 +4,32 @@ exports.activity = void 0;
4
4
  const drizzle_orm_1 = require("drizzle-orm");
5
5
  const mysql_core_1 = require("drizzle-orm/mysql-core");
6
6
  const format_schema_name_1 = require("../helper/format-schema-name");
7
+ /**
8
+ * @generated-schema-doc
9
+ * Schema: `test_facility` | Table: `activity`
10
+ *
11
+ * | Column | Type | Nullable | Constraints |
12
+ * | ------------------- | --------------- | -------- | -------------------------- |
13
+ * | id | bigint unsigned | No | PK, AUTO INC |
14
+ * | activityUuid | varchar(36) | Yes | |
15
+ * | testerStaffId | varchar(40) | Yes | |
16
+ * | testerStaffName | varchar(100) | Yes | |
17
+ * | testerStaffEmail | varchar(200) | Yes | |
18
+ * | testStationId | bigint unsigned | No | NOT NULL |
19
+ * | parentActivityId | bigint unsigned | Yes | |
20
+ * | activityType | varchar(50) | Yes | |
21
+ * | startDatetime | datetime(3) | Yes | |
22
+ * | endDatetime | datetime(3) | Yes | |
23
+ * | waitReason | varchar(150) | Yes | |
24
+ * | notes | varchar(500) | Yes | |
25
+ * | closureReason | varchar(20) | Yes | |
26
+ * | createdById | varchar(40) | Yes | |
27
+ * | createdByName | varchar(200) | Yes | |
28
+ * | insertedDatetime | datetime(3) | Yes | default: CURRENT_TIMESTAMP |
29
+ * | lastUpdatedById | varchar(40) | Yes | |
30
+ * | lastUpdatedByName | varchar(200) | Yes | |
31
+ * | lastUpdatedDatetime | datetime(3) | Yes | default: CURRENT_TIMESTAMP |
32
+ */
7
33
  exports.activity = (0, mysql_core_1.mysqlSchema)((0, format_schema_name_1.formatSchemaName)('test_facility')).table('activity', {
8
34
  id: (0, mysql_core_1.bigint)({ mode: 'number', unsigned: true }).autoincrement().primaryKey(),
9
35
  activityUuid: (0, mysql_core_1.varchar)('activity_uuid', { length: 36 }),
@@ -1,3 +1,26 @@
1
+ /**
2
+ * @generated-schema-doc
3
+ * Schema: `test_facility` | Table: `test_station`
4
+ *
5
+ * | Column | Type | Nullable | Constraints |
6
+ * | --------------------- | --------------- | -------- | ------------ |
7
+ * | id | bigint unsigned | No | PK, AUTO INC |
8
+ * | dynamicsTestStationId | varchar(36) | Yes | |
9
+ * | accessNotes | text | Yes | |
10
+ * | address | varchar(100) | Yes | |
11
+ * | contactNumber | varchar(30) | Yes | |
12
+ * | country | varchar(30) | Yes | |
13
+ * | emailAddressesJson | varchar(2000) | Yes | |
14
+ * | generalNotes | text | Yes | |
15
+ * | latitude | decimal(9,6) | Yes | |
16
+ * | longitude | decimal(9,6) | Yes | |
17
+ * | name | varchar(160) | Yes | |
18
+ * | pNumber | varchar(256) | Yes | |
19
+ * | postcode | varchar(20) | Yes | |
20
+ * | status | varchar(21) | Yes | |
21
+ * | town | varchar(30) | Yes | |
22
+ * | type | varchar(4) | Yes | |
23
+ */
1
24
  export declare const testStation: import("drizzle-orm/mysql-core").MySqlTableWithColumns<{
2
25
  name: "test_station";
3
26
  schema: string;
@@ -3,6 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.testStation = void 0;
4
4
  const mysql_core_1 = require("drizzle-orm/mysql-core");
5
5
  const format_schema_name_1 = require("../helper/format-schema-name");
6
+ /**
7
+ * @generated-schema-doc
8
+ * Schema: `test_facility` | Table: `test_station`
9
+ *
10
+ * | Column | Type | Nullable | Constraints |
11
+ * | --------------------- | --------------- | -------- | ------------ |
12
+ * | id | bigint unsigned | No | PK, AUTO INC |
13
+ * | dynamicsTestStationId | varchar(36) | Yes | |
14
+ * | accessNotes | text | Yes | |
15
+ * | address | varchar(100) | Yes | |
16
+ * | contactNumber | varchar(30) | Yes | |
17
+ * | country | varchar(30) | Yes | |
18
+ * | emailAddressesJson | varchar(2000) | Yes | |
19
+ * | generalNotes | text | Yes | |
20
+ * | latitude | decimal(9,6) | Yes | |
21
+ * | longitude | decimal(9,6) | Yes | |
22
+ * | name | varchar(160) | Yes | |
23
+ * | pNumber | varchar(256) | Yes | |
24
+ * | postcode | varchar(20) | Yes | |
25
+ * | status | varchar(21) | Yes | |
26
+ * | town | varchar(30) | Yes | |
27
+ * | type | varchar(4) | Yes | |
28
+ */
6
29
  exports.testStation = (0, mysql_core_1.mysqlSchema)((0, format_schema_name_1.formatSchemaName)('test_facility')).table('test_station', {
7
30
  id: (0, mysql_core_1.bigint)({ mode: 'number', unsigned: true }).autoincrement().primaryKey(),
8
31
  dynamicsTestStationId: (0, mysql_core_1.varchar)('dynamics_test_station_id', { length: 36 }),