Skip to content
代码片段 群组 项目
提交 68fa640a 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Clean up the misnaming of columns.

The naming standard is:
  ANY column that ends with '_ID' is a primary key in the table.
  ANY column that ends with '_REF' is a foreign key in the table.
  So 'ENDPOINT_ID' and 'NETWORK_ID' were misnamed in the ENDPOINT table, and were changed to 'ENDPOINT_IDENTIFIER' and 'NETWORK_IDENTIFIER'.
上级 057302ae
No related branches found
No related tags found
无相关合并请求
...@@ -191,12 +191,12 @@ export const dbMap = { ...@@ -191,12 +191,12 @@ export const dbMap = {
endpoint: (x) => { endpoint: (x) => {
if (x == null) return undefined if (x == null) return undefined
return { return {
endpointRef: x.ENDPOINT_REF, endpointRef: x.ENDPOINT_ID,
sessionRef: x.SESSION_REF, sessionRef: x.SESSION_REF,
endpointId: x.ENDPOINT_ID, endpointId: x.ENDPOINT_IDENTIFIER,
endpointTypeRef: x.ENDPOINT_TYPE_REF, endpointTypeRef: x.ENDPOINT_TYPE_REF,
profileId: x.PROFILE, profileId: x.PROFILE,
networkId: x.NETWORK_ID, networkId: x.NETWORK_IDENTIFIER,
} }
}, },
......
...@@ -288,22 +288,22 @@ export function getAllEndpointTypeClusterState(db, endpointTypeId) { ...@@ -288,22 +288,22 @@ export function getAllEndpointTypeClusterState(db, endpointTypeId) {
* @export * @export
* @param {*} db * @param {*} db
* @param {*} sessionId * @param {*} sessionId
* @param {*} endpointId * @param {*} endpointIdentifier
* @param {*} endpointTypeRef * @param {*} endpointTypeRef
* @param {*} networkId * @param {*} networkIdentifier
* @returns Promise to update endpoints. * @returns Promise to update endpoints.
*/ */
export function insertEndpoint( export function insertEndpoint(
db, db,
sessionId, sessionId,
endpointId, endpointIdentifier,
endpointTypeRef, endpointTypeRef,
networkId networkIdentifier
) { ) {
return DbApi.dbInsert( return DbApi.dbInsert(
db, db,
'INSERT OR REPLACE INTO ENDPOINT ( SESSION_REF, ENDPOINT_ID, ENDPOINT_TYPE_REF, NETWORK_ID ) VALUES ( ?, ?, ?, ?)', 'INSERT OR REPLACE INTO ENDPOINT ( SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, NETWORK_IDENTIFIER ) VALUES ( ?, ?, ?, ?)',
[sessionId, endpointId, endpointTypeRef, networkId] [sessionId, endpointIdentifier, endpointTypeRef, networkIdentifier]
) )
} }
...@@ -316,27 +316,21 @@ export function insertEndpoint( ...@@ -316,27 +316,21 @@ export function insertEndpoint(
* @returns Promise to delete an endpoint that resolves with the number of rows that were deleted. * @returns Promise to delete an endpoint that resolves with the number of rows that were deleted.
*/ */
export function deleteEndpoint(db, id) { export function deleteEndpoint(db, id) {
return DbApi.dbRemove(db, 'DELETE FROM ENDPOINT WHERE ENDPOINT_REF = ?', [id]) return DbApi.dbRemove(db, 'DELETE FROM ENDPOINT WHERE ENDPOINT_ID = ?', [id])
} }
export function updateEndpoint( export function updateEndpoint(db, sessionId, endpointId, param, updatedValue) {
db,
sessionId,
endpointRef,
param,
updatedValue
) {
return DbApi.dbUpdate( return DbApi.dbUpdate(
db, db,
`UPDATE ENDPOINT SET ${param} = ? WHERE ENDPOINT_REF = ? AND SESSION_REF = ?`, `UPDATE ENDPOINT SET ${param} = ? WHERE ENDPOINT_ID = ? AND SESSION_REF = ?`,
[updatedValue, endpointRef, sessionId] [updatedValue, endpointId, sessionId]
) )
} }
export function selectEndpoint(db, endpointRef) { export function selectEndpoint(db, endpointRef) {
return DbApi.dbGet( return DbApi.dbGet(
db, db,
'SELECT ENDPOINT_REF, SESSION_REF, ENDPOINT_ID, ENDPOINT_TYPE_REF, PROFILE, NETWORK_ID FROM ENDPOINT WHERE ENDPOINT_REF = ?', 'SELECT ENDPOINT_ID, SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, PROFILE, NETWORK_IDENTIFIER FROM ENDPOINT WHERE ENDPOINT_ID = ?',
[endpointRef] [endpointRef]
).then(DbMapping.dbMap.endpoint) ).then(DbMapping.dbMap.endpoint)
} }
......
...@@ -170,7 +170,7 @@ CREATE TABLE IF NOT EXISTS "STRUCT" ( ...@@ -170,7 +170,7 @@ CREATE TABLE IF NOT EXISTS "STRUCT" (
*/ */
DROP TABLE IF EXISTS "STRUCT_ITEM"; DROP TABLE IF EXISTS "STRUCT_ITEM";
CREATE TABLE IF NOT EXISTS "STRUCT_ITEM" ( CREATE TABLE IF NOT EXISTS "STRUCT_ITEM" (
"STRUCT_REF" integer, "STRUCT_REF" integer,
"NAME" text, "NAME" text,
"TYPE" text, "TYPE" text,
foreign key (STRUCT_REF) references STRUCT(STRUCT_ID) foreign key (STRUCT_REF) references STRUCT(STRUCT_ID)
...@@ -280,12 +280,12 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE" ( ...@@ -280,12 +280,12 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE" (
*/ */
DROP TABLE IF EXISTS "ENDPOINT"; DROP TABLE IF EXISTS "ENDPOINT";
CREATE TABLE IF NOT EXISTS "ENDPOINT" ( CREATE TABLE IF NOT EXISTS "ENDPOINT" (
"ENDPOINT_REF" integer primary key autoincrement, "ENDPOINT_ID" integer primary key autoincrement,
"SESSION_REF" integer, "SESSION_REF" integer,
"ENDPOINT_ID" integer,
"ENDPOINT_TYPE_REF" integer, "ENDPOINT_TYPE_REF" integer,
"PROFILE" integer, "PROFILE" integer,
"NETWORK_ID" integer, "ENDPOINT_IDENTIFIER" integer,
"NETWORK_IDENTIFIER" integer,
foreign key (SESSION_REF) references SESSION(SESSION_ID) on delete cascade, foreign key (SESSION_REF) references SESSION(SESSION_ID) on delete cascade,
foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID)
); );
...@@ -296,7 +296,7 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT" ( ...@@ -296,7 +296,7 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT" (
*/ */
DROP TABLE IF EXISTS "ENDPOINT_TYPE_CLUSTER"; DROP TABLE IF EXISTS "ENDPOINT_TYPE_CLUSTER";
CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_CLUSTER" ( CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_CLUSTER" (
"ENDPOINT_TYPE_CLUSTER_ID" integer primary key autoincrement, "ENDPOINT_TYPE_CLUSTER_ID" integer primary key autoincrement,
"ENDPOINT_TYPE_REF" integer, "ENDPOINT_TYPE_REF" integer,
"CLUSTER_REF" integer, "CLUSTER_REF" integer,
"SIDE" text, "SIDE" text,
...@@ -312,7 +312,7 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_CLUSTER" ( ...@@ -312,7 +312,7 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_CLUSTER" (
DROP TABLE IF EXISTS "ENDPOINT_TYPE_ATTRIBUTE"; DROP TABLE IF EXISTS "ENDPOINT_TYPE_ATTRIBUTE";
CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" ( CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" (
"ENDPOINT_TYPE_REF" integer, "ENDPOINT_TYPE_REF" integer,
"ENDPOINT_TYPE_CLUSTER_REF" integer, "ENDPOINT_TYPE_CLUSTER_REF" integer,
"ATTRIBUTE_REF" integer, "ATTRIBUTE_REF" integer,
"INCLUDED" integer default false, "INCLUDED" integer default false,
"EXTERNAL" integer default false, "EXTERNAL" integer default false,
...@@ -327,7 +327,11 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" ( ...@@ -327,7 +327,11 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" (
foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) on delete cascade, foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) on delete cascade,
foreign key (ENDPOINT_TYPE_CLUSTER_REF) references ENDPOINT_TYPE_CLUSTER(ENDPOINT_TYPE_CLUSTER_ID), foreign key (ENDPOINT_TYPE_CLUSTER_REF) references ENDPOINT_TYPE_CLUSTER(ENDPOINT_TYPE_CLUSTER_ID),
foreign key (ATTRIBUTE_REF) references ATTRIBUTE(ATTRIBUTE_ID), foreign key (ATTRIBUTE_REF) references ATTRIBUTE(ATTRIBUTE_ID),
UNIQUE(ENDPOINT_TYPE_REF, ATTRIBUTE_REF, ENDPOINT_TYPE_CLUSTER_REF) UNIQUE(
ENDPOINT_TYPE_REF,
ATTRIBUTE_REF,
ENDPOINT_TYPE_CLUSTER_REF
)
); );
/* /*
ENDPOINT_TYPE_COMMAND table contains the user data configuration for the various parameters that exist ENDPOINT_TYPE_COMMAND table contains the user data configuration for the various parameters that exist
...@@ -336,16 +340,19 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" ( ...@@ -336,16 +340,19 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_ATTRIBUTE" (
DROP TABLE IF EXISTS "ENDPOINT_TYPE_COMMAND"; DROP TABLE IF EXISTS "ENDPOINT_TYPE_COMMAND";
CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_COMMAND" ( CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_COMMAND" (
"ENDPOINT_TYPE_REF" integer, "ENDPOINT_TYPE_REF" integer,
"ENDPOINT_TYPE_CLUSTER_REF" integer, "ENDPOINT_TYPE_CLUSTER_REF" integer,
"COMMAND_REF" integer, "COMMAND_REF" integer,
"INCOMING" integer default false, "INCOMING" integer default false,
"OUTGOING" integer default false, "OUTGOING" integer default false,
foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) on delete cascade, foreign key (ENDPOINT_TYPE_REF) references ENDPOINT_TYPE(ENDPOINT_TYPE_ID) on delete cascade,
foreign key (ENDPOINT_TYPE_CLUSTER_REF) references ENDPOINT_TYPE_CLUSTER(ENDPOINT_TYPE_CLUSTER_ID), foreign key (ENDPOINT_TYPE_CLUSTER_REF) references ENDPOINT_TYPE_CLUSTER(ENDPOINT_TYPE_CLUSTER_ID),
foreign key (COMMAND_REF) references COMMAND(COMMAND_ID), foreign key (COMMAND_REF) references COMMAND(COMMAND_ID),
UNIQUE(ENDPOINT_TYPE_REF, COMMAND_REF, ENDPOINT_TYPE_CLUSTER_REF) UNIQUE(
ENDPOINT_TYPE_REF,
COMMAND_REF,
ENDPOINT_TYPE_CLUSTER_REF
)
); );
/* /*
* *
* $$$$$$$$\ $$\ * $$$$$$$$\ $$\
...@@ -360,7 +367,6 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_COMMAND" ( ...@@ -360,7 +367,6 @@ CREATE TABLE IF NOT EXISTS "ENDPOINT_TYPE_COMMAND" (
* \$$$$$$ |\$$$$$$ | * \$$$$$$ |\$$$$$$ |
* \______/ \______/ * \______/ \______/
*/ */
CREATE TRIGGER IF NOT EXISTS "INSERT_TRIGGER_ENDPOINT_TYPE_ATTRIBUTE" CREATE TRIGGER IF NOT EXISTS "INSERT_TRIGGER_ENDPOINT_TYPE_ATTRIBUTE"
AFTER AFTER
INSERT ON "ENDPOINT_TYPE_ATTRIBUTE" BEGIN INSERT ON "ENDPOINT_TYPE_ATTRIBUTE" BEGIN
......
...@@ -74,22 +74,22 @@ export function createStateFromDatabase(db, sessionId) { ...@@ -74,22 +74,22 @@ export function createStateFromDatabase(db, sessionId) {
// Deal with the key/value table // Deal with the key/value table
var getKeyValues = Mapping.exportSessionKeyValues(db, sessionId).then( var getKeyValues = Mapping.exportSessionKeyValues(db, sessionId).then(
(rows) => { (data) => {
state.keyValuePairs = rows state.keyValuePairs = data
Env.logInfo(`Retrieved session keys: ${rows.length}`) Env.logInfo(`Retrieved session keys: ${data.length}`)
return Promise.resolve(rows) return Promise.resolve(data)
} }
) )
promises.push(getKeyValues) promises.push(getKeyValues)
var getAllEndpoint = Mapping.exportEndpointTypes(db, sessionId).then( var getAllEndpointTypes = Mapping.exportEndpointTypes(db, sessionId).then(
(rows) => { (data) => {
Env.logInfo(`Retrieved endpoint types: ${rows.length}`) Env.logInfo(`Retrieved endpoint types: ${data.length}`)
state.endpointTypes = rows state.endpointTypes = data
return Promise.resolve(rows) return Promise.resolve(data)
} }
) )
promises.push(getAllEndpoint) promises.push(getAllEndpointTypes)
return Promise.all(promises) return Promise.all(promises)
.then(() => resolve(state)) .then(() => resolve(state))
......
...@@ -274,13 +274,13 @@ export function registerSessionApi(db, app) { ...@@ -274,13 +274,13 @@ export function registerSessionApi(db, app) {
var changeParam = '' var changeParam = ''
switch (context.updatedKey) { switch (context.updatedKey) {
case 'endpointId': case 'endpointId':
changeParam = 'ENDPOINT_ID' changeParam = 'ENDPOINT_IDENTIFIER'
break break
case 'endpointType': case 'endpointType':
changeParam = 'ENDPOINT_TYPE_REF' changeParam = 'ENDPOINT_TYPE_REF'
break break
case 'networkId': case 'networkId':
changeParam = 'NETWORK_ID' changeParam = 'NETWORK_IDENTIFIER'
break break
} }
updateEndpoint( updateEndpoint(
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册