Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 12 additions & 10 deletions 01_Data/src/layers/sequelize/model/DeviceModel/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// SPDX-License-Identifier: Apache 2.0

import { ComponentType, CustomDataType, EVSEType, Namespace, VariableType } from "@citrineos/base";
import { BelongsTo, Column, DataType, ForeignKey, HasMany, Model, Table } from "sequelize-typescript";
import { BelongsTo, BelongsToMany, Column, DataType, ForeignKey, Model, Table } from "sequelize-typescript";
import { Evse } from "./Evse";
import { Variable } from "./Variable";
import { ComponentVariable } from "./ComponentVariable";

@Table
export class Component extends Model implements ComponentType {
Expand All @@ -21,30 +22,31 @@ export class Component extends Model implements ComponentType {

@Column({
type: DataType.STRING,
unique: 'evse_name_instance'
unique: 'name_instance'
})
declare name: string;

@Column({
type: DataType.STRING,
unique: 'evse_name_instance'
unique: 'name_instance'
})
declare instance?: string;

/**
* Relations
*/

@BelongsTo(() => Evse)
declare evse?: EVSEType;

@ForeignKey(() => Evse)
@Column({
type: DataType.INTEGER,
unique: 'evse_name_instance'
})
@Column(DataType.INTEGER)
declare evseDatabaseId?: number;

@HasMany(() => Variable)
@BelongsToMany(() => Variable, () => ComponentVariable)
declare variables?: VariableType[];

// Declare the association methods, to be automatically generated by Sequelize at runtime
public addVariable!: (variable: Variable) => Promise<void>;
public getVariables!: () => Promise<Variable[]>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023 S44, LLC
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0

import { Table, Model, ForeignKey, Column, DataType } from "sequelize-typescript";
import { Component } from "./Component";
import { Variable } from "./Variable";

@Table
export class ComponentVariable extends Model {
@ForeignKey(() => Component)
@Column(DataType.INTEGER)
declare componentId: number;

@ForeignKey(() => Variable)
@Column(DataType.INTEGER)
declare variableId: number;
}
25 changes: 13 additions & 12 deletions 01_Data/src/layers/sequelize/model/DeviceModel/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// SPDX-License-Identifier: Apache 2.0

import { ComponentType, CustomDataType, Namespace, VariableCharacteristicsType, VariableType } from "@citrineos/base";
import { BelongsTo, Column, DataType, ForeignKey, HasMany, HasOne, Model, Table } from "sequelize-typescript";
import { BelongsToMany, Column, DataType, HasMany, HasOne, Model, Table } from "sequelize-typescript";
import { Component } from "./Component";
import { VariableAttribute } from "./VariableAttribute";
import { VariableCharacteristics } from "./VariableCharacteristics";
import { ComponentVariable } from "./ComponentVariable";

@Table
export class Variable extends Model implements VariableType {
Expand All @@ -16,16 +17,16 @@ export class Variable extends Model implements VariableType {

declare customData?: CustomDataType;

/**
* Fields
*/
/**
* Fields
*/

@Column({
type: DataType.STRING,
unique: 'name_instance'
})
declare name: string;

@Column({
type: DataType.STRING,
unique: 'name_instance'
Expand All @@ -35,17 +36,17 @@ export class Variable extends Model implements VariableType {
/**
* Relations
*/

@BelongsTo(() => Component)
declare component: ComponentType;

@ForeignKey(() => Component)
@Column(DataType.INTEGER)
declare componentId?: number;
@BelongsToMany(() => Component, () => ComponentVariable)
declare components?: ComponentType[];

@HasMany(() => VariableAttribute)
declare variableAttributes?: VariableAttribute[];

@HasOne(() => VariableCharacteristics)
declare variableCharacteristics: VariableCharacteristicsType;
declare variableCharacteristics?: VariableCharacteristicsType;

// Declare the association methods, to be automatically generated by Sequelize at runtime
public addComponent!: (variable: Component) => Promise<void>;
public getComponents!: () => Promise<Component[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
//
// SPDX-License-Identifier: Apache 2.0

import { AttributeEnumType, ComponentType, CustomDataType, DataEnumType, EVSEType, MutabilityEnumType, Namespace, StatusInfoType, VariableAttributeType, VariableType } from "@citrineos/base";
import { BeforeCreate, BeforeUpdate, BelongsTo, Column, DataType, ForeignKey, HasMany, HasOne, Index, Model, Table } from "sequelize-typescript";
import { AttributeEnumType, ComponentType, CustomDataType, DataEnumType, EVSEType, MutabilityEnumType, Namespace, VariableAttributeType, VariableType } from "@citrineos/base";
import { BelongsTo, Column, DataType, ForeignKey, HasMany, Index, Model, Table } from "sequelize-typescript";
import * as bcrypt from "bcrypt";
import { Variable } from "./Variable";
import { Component } from "./Component";
import { Evse } from "./Evse";
import { Boot } from "../Boot";
import { VariableStatus } from "./VariableStatus";
import { VariableCharacteristics } from "./VariableCharacteristics";

@Table
export class VariableAttribute extends Model implements VariableAttributeType {
Expand All @@ -26,14 +25,14 @@ export class VariableAttribute extends Model implements VariableAttributeType {

@Index
@Column({
unique: 'stationId_type_variableId_componentId_evseDatabaseId'
unique: 'stationId_type_variableId_componentId'
})
declare stationId: string;

@Column({
type: DataType.STRING,
defaultValue: AttributeEnumType.Actual,
unique: 'stationId_type_variableId_componentId_evseDatabaseId'
unique: 'stationId_type_variableId_componentId'
})
declare type?: AttributeEnumType;
// From VariableCharacteristics, which belongs to Variable associated with this VariableAttribute
Expand All @@ -44,7 +43,7 @@ export class VariableAttribute extends Model implements VariableAttributeType {
declare dataType: DataEnumType;

@Column({
// TODO: Make this configurable?
// TODO: Make this configurable? also used in VariableStatus model
type: DataType.STRING(4000),
set(valueString) {
if (valueString) {
Expand Down Expand Up @@ -91,7 +90,7 @@ export class VariableAttribute extends Model implements VariableAttributeType {
@ForeignKey(() => Variable)
@Column({
type: DataType.INTEGER,
unique: 'stationId_type_variableId_componentId_evseDatabaseId'
unique: 'stationId_type_variableId_componentId'
})
declare variableId?: number;

Expand All @@ -101,18 +100,15 @@ export class VariableAttribute extends Model implements VariableAttributeType {
@ForeignKey(() => Component)
@Column({
type: DataType.INTEGER,
unique: 'stationId_type_variableId_componentId_evseDatabaseId'
unique: 'stationId_type_variableId_componentId'
})
declare componentId?: number;

@BelongsTo(() => Evse)
declare evse?: EVSEType;

@ForeignKey(() => Evse)
@Column({
type: DataType.INTEGER,
unique: 'stationId_type_variableId_componentId_evseDatabaseId'
})
@Column(DataType.INTEGER)
declare evseDatabaseId?: number;

// History of variable status. Can be directly from GetVariablesResponse or SetVariablesResponse, or from NotifyReport handling, or from 'setOnCharger' option for data api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class VariableStatus extends Model {

declare customData?: CustomDataType;

@Column(DataType.STRING)
@Column(DataType.STRING(4000))
declare value: string;

@Column(DataType.STRING)
Expand Down
Loading