Browse Source

chore: upgrade TestResetService knex

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4280/head
mertmit 2 years ago
parent
commit
1dfc870f67
  1. 2
      packages/nocodb/src/lib/services/test/TestResetService/index.ts
  2. 2
      packages/nocodb/src/lib/services/test/TestResetService/resetMetaSakilaSqliteProject.ts
  3. 16
      packages/nocodb/src/lib/services/test/TestResetService/resetMysqlSakilaProject.ts
  4. 8
      packages/nocodb/src/lib/services/test/TestResetService/resetPgSakilaProject.ts

2
packages/nocodb/src/lib/services/test/TestResetService/index.ts

@ -1,6 +1,6 @@
import Noco from '../../../Noco';
import Knex from 'knex';
import { Knex } from 'knex';
import axios from 'axios';
import Project from '../../../models/Project';
import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2';

2
packages/nocodb/src/lib/services/test/TestResetService/resetMetaSakilaSqliteProject.ts

@ -1,5 +1,5 @@
import axios from 'axios';
import Knex from 'knex';
import { Knex } from 'knex';
import { promises as fs } from 'fs';
import { sakilaTableNames } from '../../../utils/globals';

16
packages/nocodb/src/lib/services/test/TestResetService/resetMysqlSakilaProject.ts

@ -1,5 +1,5 @@
import axios from 'axios';
import Knex from 'knex';
import { Knex, knex } from 'knex';
import { promises as fs } from 'fs';
import Audit from '../../../models/Audit';
@ -119,20 +119,20 @@ const resetMysqlSakilaProject = async ({
oldProject?: Project | undefined;
isEmptyProject: boolean;
}) => {
const knex = Knex(config);
const nc_knex = knex(config);
try {
await knex.raw(`USE test_sakila_${parallelId}`);
await nc_knex.raw(`USE test_sakila_${parallelId}`);
} catch (e) {
await knex.raw(`CREATE DATABASE test_sakila_${parallelId}`);
await knex.raw(`USE test_sakila_${parallelId}`);
await nc_knex.raw(`CREATE DATABASE test_sakila_${parallelId}`);
await nc_knex.raw(`USE test_sakila_${parallelId}`);
}
if (
isEmptyProject ||
(await isSakilaMysqlToBeReset(knex, parallelId, oldProject))
(await isSakilaMysqlToBeReset(nc_knex, parallelId, oldProject))
) {
await resetSakilaMysql(knex, parallelId, isEmptyProject);
await resetSakilaMysql(nc_knex, parallelId, isEmptyProject);
}
const response = await axios.post(
@ -148,7 +148,7 @@ const resetMysqlSakilaProject = async ({
console.error('Error creating project', response.data);
}
await knex.destroy();
await nc_knex.destroy();
};
export default resetMysqlSakilaProject;

8
packages/nocodb/src/lib/services/test/TestResetService/resetPgSakilaProject.ts

@ -1,5 +1,5 @@
import axios from 'axios';
import Knex from 'knex';
import { Knex, knex } from 'knex';
import { promises as fs } from 'fs';
const util = require('util');
@ -81,7 +81,7 @@ const resetSakilaPg = async (
if (isEmptyProject) return;
const sakilaKnex = Knex(sakilaKnexConfig(parallelId));
const sakilaKnex = knex(sakilaKnexConfig(parallelId));
const schemaFile = await fs.readFile(
`${testsDir}/pg-sakila-db/03-postgres-sakila-schema.sql`
@ -117,13 +117,13 @@ const resetPgSakilaProject = async ({
oldProject?: Project | undefined;
isEmptyProject: boolean;
}) => {
const pgknex = Knex(config);
const pgknex = knex(config);
try {
await pgknex.raw(`CREATE DATABASE sakila_${parallelId}`);
} catch (e) {}
const sakilaKnex = Knex(sakilaKnexConfig(parallelId));
const sakilaKnex = knex(sakilaKnexConfig(parallelId));
if (isEmptyProject || (await isSakilaPgToBeReset(sakilaKnex, oldProject))) {
await sakilaKnex.destroy();

Loading…
Cancel
Save