-
-
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.
fix(migration): remove north oibus and history queries with north oibus
- Loading branch information
1 parent
036e3ee
commit 9baac30
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.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 { 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'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await removeNorthOIBusConnectors(knex); | ||
await removeNorthOIBusHistoryQueries(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'); | ||
} | ||
|
||
export async function down(): Promise<void> {} |
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