|
|
|
@ -1,12 +1,8 @@
|
|
|
|
|
import Noco from '../../../Noco'; |
|
|
|
|
|
|
|
|
|
import { Knex } from 'knex'; |
|
|
|
|
import axios from 'axios'; |
|
|
|
|
import Project from '../../../models/Project'; |
|
|
|
|
import NcConnectionMgrv2 from '../../../utils/common/NcConnectionMgrv2'; |
|
|
|
|
import resetMetaSakilaSqliteProject from './resetMetaSakilaSqliteProject'; |
|
|
|
|
import resetMysqlSakilaProject from './resetMysqlSakilaProject'; |
|
|
|
|
import Model from '../../../models/Model'; |
|
|
|
|
import resetPgSakilaProject from './resetPgSakilaProject'; |
|
|
|
|
import User from '../../../models/User'; |
|
|
|
|
import NocoCache from '../../../cache/NocoCache'; |
|
|
|
@ -29,7 +25,6 @@ const projectTitleByType = {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export class TestResetService { |
|
|
|
|
private knex: Knex | null = null; |
|
|
|
|
private readonly parallelId; |
|
|
|
|
private readonly dbType; |
|
|
|
|
private readonly isEmptyProject: boolean; |
|
|
|
@ -43,7 +38,6 @@ export class TestResetService {
|
|
|
|
|
dbType: string; |
|
|
|
|
isEmptyProject: boolean; |
|
|
|
|
}) { |
|
|
|
|
this.knex = Noco.ncMeta.knex; |
|
|
|
|
this.parallelId = parallelId; |
|
|
|
|
this.dbType = dbType; |
|
|
|
|
this.isEmptyProject = isEmptyProject; |
|
|
|
@ -54,12 +48,12 @@ export class TestResetService {
|
|
|
|
|
const token = await loginRootUser(); |
|
|
|
|
|
|
|
|
|
const { project } = await this.resetProject({ |
|
|
|
|
metaKnex: this.knex, |
|
|
|
|
token, |
|
|
|
|
dbType: this.dbType, |
|
|
|
|
parallelId: this.parallelId, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await removeAllProjectCreatedByTheTest(this.parallelId); |
|
|
|
|
await removeAllPrefixedUsersExceptSuper(this.parallelId); |
|
|
|
|
|
|
|
|
|
return { token, project }; |
|
|
|
@ -70,12 +64,10 @@ export class TestResetService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async resetProject({ |
|
|
|
|
metaKnex, |
|
|
|
|
token, |
|
|
|
|
dbType, |
|
|
|
|
parallelId, |
|
|
|
|
}: { |
|
|
|
|
metaKnex: Knex; |
|
|
|
|
token: string; |
|
|
|
|
dbType: string; |
|
|
|
|
parallelId: string; |
|
|
|
@ -87,7 +79,7 @@ export class TestResetService {
|
|
|
|
|
await removeProjectUsersFromCache(project); |
|
|
|
|
|
|
|
|
|
const bases = await project.getBases(); |
|
|
|
|
if (dbType == 'sqlite') await dropTablesOfProject(metaKnex, project); |
|
|
|
|
|
|
|
|
|
await Project.delete(project.id); |
|
|
|
|
|
|
|
|
|
if (bases.length > 0) await NcConnectionMgrv2.deleteAwait(bases[0]); |
|
|
|
@ -124,17 +116,12 @@ export class TestResetService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const dropTablesOfProject = async (knex: Knex, project: Project) => { |
|
|
|
|
const tables = await Model.list({ |
|
|
|
|
project_id: project.id, |
|
|
|
|
base_id: (await project.getBases())[0].id, |
|
|
|
|
}); |
|
|
|
|
const removeAllProjectCreatedByTheTest = async (parallelId: string) => { |
|
|
|
|
const projects = await Project.list({}); |
|
|
|
|
|
|
|
|
|
for (const table of tables) { |
|
|
|
|
if (table.type == 'table') { |
|
|
|
|
await knex.raw(`DROP TABLE IF EXISTS ${table.table_name}`); |
|
|
|
|
} else { |
|
|
|
|
await knex.raw(`DROP VIEW IF EXISTS ${table.table_name}`); |
|
|
|
|
for (const project of projects) { |
|
|
|
|
if (project.title.startsWith(`nc_test_${parallelId}_`)) { |
|
|
|
|
await Project.delete(project.id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|