-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor oibus engine service, controller and tests
- Loading branch information
1 parent
5a15709
commit 24b930f
Showing
98 changed files
with
3,885 additions
and
4,623 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts
This file was deleted.
Oops, something went wrong.
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,111 @@ | ||
import { Knex } from 'knex'; | ||
import { HISTORY_QUERIES_TABLE } from '../../repository/history-query.repository'; | ||
import { NORTH_CONNECTORS_TABLE } from '../../repository/north-connector.repository'; | ||
import path from 'node:path'; | ||
import { filesExists } from '../../service/utils'; | ||
import fs from 'node:fs/promises'; | ||
import { HISTORY_ITEMS_TABLE } from '../../repository/history-query-item.repository'; | ||
import { OIANALYTICS_MESSAGE_TABLE } from '../../repository/oianalytics-message.repository'; | ||
import { COMMANDS_TABLE } from '../../repository/oianalytics-command.repository'; | ||
import { SOUTH_CONNECTORS_TABLE } from '../../repository/south-connector.repository'; | ||
|
||
const EXTERNAL_SOURCES_TABLE = 'external_sources'; | ||
const EXTERNAL_SUBSCRIPTION_TABLE = 'external_subscription'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await removeNorthOIBusConnectors(knex); | ||
await removeNorthOIBusHistoryQueries(knex); | ||
await removeExternalSubscriptions(knex); | ||
await updateOIAMessageTable(knex); | ||
await recreateCommandTable(knex); | ||
await updateSouthConnectorsTable(knex); | ||
await updateHistoryQueriesTable(knex); | ||
} | ||
|
||
async function removeNorthOIBusConnectors(knex: Knex): Promise<void> { | ||
const northConnectors: Array<{ id: string; name: string }> = await knex(NORTH_CONNECTORS_TABLE) | ||
.select('id', 'name') | ||
.where('type', 'oibus'); | ||
await knex(NORTH_CONNECTORS_TABLE).delete().where('type', 'oibus'); | ||
for (const north of northConnectors) { | ||
const baseFolder = path.resolve('./cache/data-stream', `north-${north.id}`); | ||
if (await filesExists(baseFolder)) { | ||
await fs.rm(baseFolder, { recursive: true }); | ||
} | ||
} | ||
} | ||
|
||
async function removeNorthOIBusHistoryQueries(knex: Knex): Promise<void> { | ||
const historyQueries: Array<{ id: string; name: string }> = await knex(HISTORY_QUERIES_TABLE) | ||
.select('id', 'name') | ||
.where('north_type', 'oibus'); | ||
|
||
for (const history of historyQueries) { | ||
await knex(HISTORY_ITEMS_TABLE).delete().where('history_id', history.id); | ||
const baseFolder = path.resolve('./cache/history-query', `history-${history.id}`); | ||
if (await filesExists(baseFolder)) { | ||
await fs.rm(baseFolder, { recursive: true }); | ||
} | ||
} | ||
await knex(HISTORY_QUERIES_TABLE).delete().where('north_type', 'oibus'); | ||
} | ||
|
||
async function removeExternalSubscriptions(knex: Knex): Promise<void> { | ||
await knex.schema.dropTableIfExists(EXTERNAL_SUBSCRIPTION_TABLE); | ||
await knex.schema.dropTableIfExists(EXTERNAL_SOURCES_TABLE); | ||
} | ||
|
||
async function updateOIAMessageTable(knex: Knex): Promise<void> { | ||
await knex.schema.raw(`delete | ||
from ${OIANALYTICS_MESSAGE_TABLE}`); | ||
await knex.schema.alterTable(OIANALYTICS_MESSAGE_TABLE, table => { | ||
table.dropColumn('content'); | ||
}); | ||
} | ||
|
||
async function recreateCommandTable(knex: Knex): Promise<void> { | ||
await knex.schema.raw( | ||
`create table temporary_table | ||
( | ||
id char(36) primary key, | ||
created_at datetime default CURRENT_TIMESTAMP not null, | ||
updated_at datetime default CURRENT_TIMESTAMP not null, | ||
type text not null, | ||
status text not null, | ||
ack boolean default '0' not null, | ||
retrieved_date varchar(255), | ||
completed_date varchar(255), | ||
result varchar(255), | ||
upgrade_version varchar(255), | ||
upgrade_asset_id varchar(255), | ||
command_content text | ||
); | ||
` | ||
); | ||
await knex.schema.raw(`INSERT INTO temporary_table | ||
SELECT *, '' | ||
FROM ${COMMANDS_TABLE}`); | ||
await knex.schema.raw(`DROP TABLE ${COMMANDS_TABLE}`); | ||
await knex.schema.raw(`ALTER TABLE temporary_table | ||
RENAME TO ${COMMANDS_TABLE}`); | ||
await knex.schema.alterTable(COMMANDS_TABLE, table => { | ||
table.string('south_connector_id', 255); | ||
table.string('north_connector_id', 255); | ||
table.string('scan_mode_id', 255); | ||
table.string('target_version', 255); | ||
}); | ||
} | ||
|
||
async function updateSouthConnectorsTable(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable(SOUTH_CONNECTORS_TABLE, table => { | ||
table.boolean('shared_connection').defaultTo(false); | ||
}); | ||
} | ||
|
||
async function updateHistoryQueriesTable(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable(HISTORY_QUERIES_TABLE, table => { | ||
table.boolean('south_shared_connection').defaultTo(false); | ||
}); | ||
} | ||
|
||
export async function down(): Promise<void> {} |
51 changes: 0 additions & 51 deletions
51
backend/src/db/entity-migrations/v3.4.1-edit-oia-message.ts
This file was deleted.
Oops, something went wrong.
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.