Skip to content

Commit

Permalink
fix(migration): remove north oibus and history queries with north oibus
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerni10 committed May 22, 2024
1 parent 036e3ee commit 9baac30
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions backend/src/db/entity-migrations/v3.4.0-deprecate-north-oibus.ts
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> {}
2 changes: 1 addition & 1 deletion backend/src/north/north-amazon-s3/north-amazon-s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import RepositoryService from '../../service/repository.service';
import pino from 'pino';
import { NorthAmazonS3Settings } from '../../../../shared/model/north-settings.model';
import { createProxyAgent } from '../../service/proxy-agent';
import { OIBusContent, OIBusTimeValue } from '../../../../shared/model/engine.model';
import { OIBusContent } from '../../../../shared/model/engine.model';

/**
* Class NorthAmazonS3 - sends files to Amazon AWS S3
Expand Down

0 comments on commit 9baac30

Please sign in to comment.