-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE][LUCY-1169] - Add BlowBy table to capture BlowBy data coming…
… from INSPECT (#1170) * wip - preliminary work to add blow by table, remove previous columns * wip - update blow by model and route * fix to blowBy validation check and yaml * change blow_by_time type, clean up redundancies * revert removal of watercraft complexity from shift, no real change * revert removal of watercraft complexity, no real change * Update api/api_sources/sources/database/models/blowBy.ts Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com> --------- Co-authored-by: Matthew Logan <62873746+LocalNewsTV@users.noreply.github.com>
- Loading branch information
1 parent
9709916
commit f2d0ac5
Showing
12 changed files
with
385 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
version: '1.0' | ||
description: Schema file for table blow_by | ||
externalTables: [] | ||
includes: | ||
- observerWorkflow.schema.yaml | ||
schemas: | ||
BlowBySchema: | ||
name: blow_by | ||
description: 'Table to store blow by data for watercraft observer.' | ||
baseSchema: RecordSchema | ||
meta: | ||
resource: true | ||
api: /mussels/blow-bys | ||
base: api | ||
resource: true | ||
baseModel: Record | ||
columns: | ||
id: | ||
name: blow_by_id | ||
comment: Auto generated primary key | ||
definition: SERIAL PRIMARY KEY | ||
observerWorkflowId: | ||
name: observer_workflow_id | ||
comment: Foreign key to observer_workflow | ||
definition: INT NULL | ||
foreignTable: observer_workflow | ||
refColumn: observer_workflow_id | ||
blowByTime: | ||
name: blow_by_time | ||
comment: Time of blow by | ||
definition: TIMESTAMP NULL | ||
watercraftComplexity: | ||
name: watercraft_complexity | ||
comment: Watercraft complexity | ||
definition: VARCHAR(100) NULL | ||
reportedToRapp: | ||
name: reported_to_rapp | ||
comment: Reported to rapp | ||
definition: BOOLEAN NOT NULL DEFAULT false | ||
relations: | ||
observerWorkflow: | ||
header: | ||
key: blow_by.observer_workflow | ||
default: Observer Workflow | ||
description: | ||
key: blow_by.observer_workflow.description | ||
default: Observer workflow associated with the blow by | ||
type: single | ||
relationshipType: many-to-one | ||
schema: ObserverWorkflowSchema | ||
meta: | ||
skipValidation: true | ||
versions: [] | ||
fields: {} |
41 changes: 41 additions & 0 deletions
41
api/api_sources/schema-migration-sql/BlowBySchema/BlowBySchema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-- ### Creating Table: blow_by ### -- | ||
|
||
|
||
CREATE TABLE blow_by (); | ||
ALTER TABLE blow_by ADD COLUMN blow_by_id SERIAL PRIMARY KEY; | ||
ALTER TABLE blow_by ADD COLUMN observer_workflow_id INT NULL REFERENCES observer_workflow(observer_workflow_id) ON DELETE SET NULL; | ||
ALTER TABLE blow_by ADD COLUMN blow_by_time TIMESTAMP NULL; | ||
ALTER TABLE blow_by ADD COLUMN watercraft_complexity VARCHAR(100) NULL; | ||
ALTER TABLE blow_by ADD COLUMN reported_to_rapp BOOLEAN NOT NULL DEFAULT false; | ||
|
||
|
||
|
||
-- ### Creating Comments on table ### -- | ||
|
||
|
||
COMMENT ON TABLE blow_by IS 'Table to store blow by data for watercraft observer.'; | ||
COMMENT ON COLUMN blow_by.blow_by_id IS 'Auto generated primary key'; | ||
COMMENT ON COLUMN blow_by.observer_workflow_id IS 'Foreign key to observer_workflow'; | ||
COMMENT ON COLUMN blow_by.blow_by_time IS 'Time of blow by'; | ||
COMMENT ON COLUMN blow_by.watercraft_complexity IS 'Watercraft complexity'; | ||
COMMENT ON COLUMN blow_by.reported_to_rapp IS 'Reported to rapp'; | ||
|
||
|
||
|
||
-- ### Creating Timestamp column ### -- | ||
|
||
|
||
ALTER TABLE blow_by ADD COLUMN created_at TIMESTAMP DEFAULT NOW(); | ||
ALTER TABLE blow_by ADD COLUMN updated_at TIMESTAMP DEFAULT NOW(); | ||
COMMENT ON COLUMN blow_by.created_at IS 'Timestamp column to check creation time of record'; | ||
COMMENT ON COLUMN blow_by.updated_at IS 'Timestamp column to check modify time of record'; | ||
|
||
|
||
-- ### Creating User Audit Columns ### -- | ||
|
||
|
||
ALTER TABLE blow_by ADD COLUMN updated_by_user_id INT NULL DEFAULT NULL REFERENCES application_user(user_id) ON DELETE SET NULL; | ||
ALTER TABLE blow_by ADD COLUMN created_by_user_id INT NULL DEFAULT NULL REFERENCES application_user(user_id) ON DELETE SET NULL; | ||
COMMENT ON COLUMN blow_by.updated_by_user_id IS 'Audit column to track creator'; | ||
COMMENT ON COLUMN blow_by.created_by_user_id IS 'Audit column to track modifier'; | ||
-- ### End: blow_by ### -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
api/api_sources/sources/database/migrations/1703285389562-CreateBlowBy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {MigrationInterface, QueryRunner} from 'typeorm'; | ||
import { AppDBMigrator } from '../applicationSchemaInterface'; | ||
import { BlowBySchema, ObserverWorkflowSchema } from '../database-schema'; | ||
|
||
export class CreateBlowBy1703888022971 extends AppDBMigrator implements MigrationInterface { | ||
blowBySchema: BlowBySchema; | ||
observerWorkflowSchema: ObserverWorkflowSchema; | ||
|
||
/** | ||
* Setup | ||
*/ | ||
setup() { | ||
// Adding BlowBy schema to migrator | ||
this.blowBySchema = new BlowBySchema(); | ||
this.observerWorkflowSchema = new ObserverWorkflowSchema(); | ||
|
||
// Create BlowBy table | ||
this.addSchemaInitVersion(this.blowBySchema); | ||
} | ||
|
||
/** | ||
* UP: Create DB method | ||
*/ | ||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
// Start Log | ||
this.log('[START]', 'UP'); | ||
// Running all up migration files | ||
await this.runQuerySqlFiles(this.upMigrations(), queryRunner); | ||
this.log('[END]', 'UP'); | ||
} | ||
|
||
/** | ||
* Down: Revert | ||
*/ | ||
public async down(queryRunner: QueryRunner): Promise<any> { | ||
this.log('[START]', 'DOWN'); | ||
await queryRunner.query(this.blowBySchema.dropTable()); | ||
await queryRunner.query(this.observerWorkflowSchema.dropTable()); | ||
this.log('[END]', 'DOWN'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ** Model: BlowBy from schema BlowBySchema ** | ||
|
||
import { Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm'; | ||
import { BlowBySchema, ObserverWorkflowSchema } from '../database-schema'; | ||
import { ModelProperty, PropertyType, ModelDescription } from '../../libs/core-model'; | ||
import { ObserverWorkflow, Record } from '../models'; | ||
import { DateTimeTransformer } from '../../libs/transformer'; | ||
|
||
/** Interface **/ | ||
/** | ||
* @description BlowBy create interface | ||
*/ | ||
export interface BlowBySpec { | ||
observerWorkflowId: ObserverWorkflow; | ||
blowByTime: string; | ||
watercraftComplexity: string; | ||
reportedToRapp: boolean; | ||
} | ||
// -- End: BlowBySpec -- | ||
|
||
|
||
/** Interface **/ | ||
/** | ||
* @description BlowBy update interface | ||
*/ | ||
export interface BlowByUpdateSpec { | ||
observerWorkflowId?: ObserverWorkflow; | ||
blowByTime?: string; | ||
watercraftComplexity?: string; | ||
reportedToRapp?: boolean; | ||
} | ||
// -- End: BlowByUpdateSpec -- | ||
|
||
/** | ||
* @description Data Model Class for BlowBySchema | ||
*/ | ||
@ModelDescription({ | ||
description: 'Data Model Class for BlowBySchema', | ||
schema: BlowBySchema, | ||
apiResource: false | ||
}) | ||
@Entity( { name: BlowBySchema.dbTable} ) | ||
export class BlowBy extends Record implements BlowBySpec { | ||
|
||
/** | ||
* Class Properties | ||
*/ | ||
|
||
/** | ||
* @description Getter/Setter property for column {blow_by_id} | ||
*/ | ||
@PrimaryGeneratedColumn() | ||
@ModelProperty({type: PropertyType.number}) | ||
blow_by_id: number; | ||
|
||
/** | ||
* @description Getter/Setter property for column {observer_workflow_id} | ||
*/ | ||
@ManyToOne( type => ObserverWorkflow, { eager: true}) | ||
@JoinColumn({ name: BlowBySchema.columns.observerWorkflowId, referencedColumnName: ObserverWorkflowSchema.pk}) | ||
@ModelProperty({type: PropertyType.object}) | ||
observerWorkflowId: ObserverWorkflow; | ||
|
||
/** | ||
* @description Getter/Setter property for column {blow_by_time} | ||
*/ | ||
@Column({ name: BlowBySchema.columns.blowByTime, transformer: new DateTimeTransformer()}) | ||
@ModelProperty({type: PropertyType.string}) | ||
blowByTime: string; | ||
|
||
/** | ||
* @description Getter/Setter property for column {watercraft_complexity} | ||
*/ | ||
@Column({ name: BlowBySchema.columns.watercraftComplexity}) | ||
@ModelProperty({type: PropertyType.string}) | ||
watercraftComplexity: string; | ||
|
||
/** | ||
* @description Getter/Setter property for column {reported_to_rapp} | ||
*/ | ||
@Column({ name: BlowBySchema.columns.reportedToRapp}) | ||
@ModelProperty({type: PropertyType.boolean}) | ||
reportedToRapp: boolean; | ||
|
||
} | ||
|
||
// ------------------------------------- |
49 changes: 49 additions & 0 deletions
49
api/api_sources/sources/database/models/controllers/blowBy.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// ** BlowByController ** // | ||
|
||
import { RecordController } from '../generic.data.models'; | ||
import { BlowBy} from '../../models'; | ||
import { BlowBySchema } from '../../database-schema'; | ||
|
||
// ** BlowByController ** // | ||
|
||
|
||
/** | ||
* @description Data Model Controller Class for BlowBySchema and BlowBy | ||
*/ | ||
export class BlowByController extends RecordController<BlowBy> { | ||
/** | ||
* @description Getter for shared instance | ||
*/ | ||
public static get shared(): BlowByController { | ||
return this.sharedInstance<BlowBy>(BlowBy, BlowBySchema) as BlowByController; | ||
} | ||
|
||
public async all(query?: any): Promise<BlowBy[]> { | ||
const options = query || {}; | ||
options.relations = ['observerWorkflowId']; | ||
return await this.repo.find(options) as BlowBy[]; | ||
} | ||
|
||
get exportKeyPriorities(): {[key: string]: number} { | ||
const basePriority = 1000; | ||
const topPriority = 100; | ||
return { | ||
id: basePriority + topPriority, | ||
observerWorkflowId: (basePriority + topPriority - 10), | ||
blowByTime: (basePriority + topPriority - 50), | ||
watercraftComplexity: (basePriority + topPriority - 60), | ||
reportedToRapp: (basePriority + topPriority - 70), | ||
}; | ||
} | ||
|
||
processForExport(data: BlowBy): any { | ||
const result: any = {}; | ||
Object.keys(data).forEach((key) => { | ||
if (this.exportKeyMapper[key]) { | ||
result[this.exportKeyMapper[key]] = data[key]; | ||
} | ||
}); | ||
return result; | ||
} | ||
} | ||
// ---------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.