@loomcore/api 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,8 +3,8 @@ import { CreateOrganizationsTableMigration } from "./002-create-organizations-ta
|
|
|
3
3
|
import { doesTableExist } from "../utils/does-table-exist.util.js";
|
|
4
4
|
import { CreateMetaOrgMigration } from "./005-create-meta-org.migration.js";
|
|
5
5
|
import { randomUUID } from 'crypto';
|
|
6
|
-
import { OrganizationService } from "../../../services/index.js";
|
|
7
6
|
import { PostgresDatabase } from "../postgres.database.js";
|
|
7
|
+
import { OrganizationService } from "../../../services/index.js";
|
|
8
8
|
import { EmptyUserContext } from "@loomcore/common/models";
|
|
9
9
|
export async function setupDatabaseForMultitenant(client, orgName, orgCode) {
|
|
10
10
|
let runMigrations = [];
|
|
@@ -27,6 +27,14 @@ export async function setupDatabaseForMultitenant(client, orgName, orgCode) {
|
|
|
27
27
|
return { success: false, metaOrgId: metaOrgId, error: result.error };
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
else {
|
|
31
|
+
const database = new PostgresDatabase(client);
|
|
32
|
+
const organizationService = new OrganizationService(database);
|
|
33
|
+
const metaOrg = await organizationService.getMetaOrg(EmptyUserContext);
|
|
34
|
+
if (metaOrg) {
|
|
35
|
+
metaOrgId = metaOrg._id;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
30
38
|
if (!runMigrations.includes(2)) {
|
|
31
39
|
const createOrganizationTableMigration = new CreateOrganizationsTableMigration(client, orgName, orgCode);
|
|
32
40
|
const result = await createOrganizationTableMigration.execute(metaOrgId);
|
|
@@ -43,15 +51,5 @@ export async function setupDatabaseForMultitenant(client, orgName, orgCode) {
|
|
|
43
51
|
return { success: false, metaOrgId: metaOrgId, error: result.error };
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
|
-
else {
|
|
47
|
-
const database = new PostgresDatabase(client);
|
|
48
|
-
const organizationService = new OrganizationService(database);
|
|
49
|
-
const metaOrg = await organizationService.getMetaOrg(EmptyUserContext);
|
|
50
|
-
console.log('setupDatabaseForMultitenant: metaOrg', metaOrg);
|
|
51
|
-
if (!metaOrg) {
|
|
52
|
-
return { success: false, metaOrgId: metaOrgId, error: new Error('error getting meta org') };
|
|
53
|
-
}
|
|
54
|
-
metaOrgId = metaOrg._id;
|
|
55
|
-
}
|
|
56
54
|
return { success: true, metaOrgId: metaOrgId, error: null };
|
|
57
55
|
}
|