@loomcore/api 0.1.7 → 0.1.9
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.
- package/dist/__tests__/postgres-test-migrations/001-create-test-entities-table.migration.d.ts +3 -5
- package/dist/__tests__/postgres-test-migrations/001-create-test-entities-table.migration.js +8 -10
- package/dist/__tests__/postgres-test-migrations/002-create-categories-table.migration.d.ts +3 -5
- package/dist/__tests__/postgres-test-migrations/002-create-categories-table.migration.js +8 -10
- package/dist/__tests__/postgres-test-migrations/003-create-products-table.migration.d.ts +3 -5
- package/dist/__tests__/postgres-test-migrations/003-create-products-table.migration.js +8 -10
- package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.d.ts +3 -5
- package/dist/__tests__/postgres-test-migrations/004-create-test-users-table.migration.js +8 -10
- package/dist/__tests__/postgres-test-migrations/005-create-test-items-table.migration.d.ts +3 -5
- package/dist/__tests__/postgres-test-migrations/005-create-test-items-table.migration.js +8 -10
- package/dist/__tests__/postgres-test-migrations/run-test-migrations.d.ts +1 -1
- package/dist/__tests__/postgres-test-migrations/run-test-migrations.js +7 -7
- package/dist/__tests__/postgres.test-database.js +1 -1
- package/dist/databases/postgres/migrations/001-create-migrations-table.migration.d.ts +5 -7
- package/dist/databases/postgres/migrations/001-create-migrations-table.migration.js +19 -24
- package/dist/databases/postgres/migrations/002-create-organizations-table.migration.d.ts +7 -7
- package/dist/databases/postgres/migrations/002-create-organizations-table.migration.js +33 -10
- package/dist/databases/postgres/migrations/003-create-users-table.migration.d.ts +5 -7
- package/dist/databases/postgres/migrations/003-create-users-table.migration.js +14 -11
- package/dist/databases/postgres/migrations/004-create-refresh-token-table.migration.d.ts +5 -7
- package/dist/databases/postgres/migrations/004-create-refresh-token-table.migration.js +14 -11
- package/dist/databases/postgres/migrations/migration.interface.d.ts +3 -4
- package/dist/databases/postgres/migrations/setup-for-auth.migration.d.ts +1 -1
- package/dist/databases/postgres/migrations/setup-for-auth.migration.js +21 -12
- package/dist/databases/postgres/migrations/setup-for-multitenant.migration.d.ts +1 -1
- package/dist/databases/postgres/migrations/setup-for-multitenant.migration.js +19 -6
- package/dist/databases/postgres/utils/does-table-exist.util.d.ts +2 -0
- package/dist/databases/postgres/utils/does-table-exist.util.js +8 -0
- package/package.json +1 -1
package/dist/__tests__/postgres-test-migrations/001-create-test-entities-table.migration.d.ts
CHANGED
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "../../databases/postgres/migrations/migration.interface.js";
|
|
3
3
|
export declare class CreateTestEntitiesTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
9
|
error: Error;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
12
|
error: null;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateTestEntitiesTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 1;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "testEntities" (
|
|
@@ -31,10 +29,10 @@ export class CreateTestEntitiesTableMigration {
|
|
|
31
29
|
catch (error) {
|
|
32
30
|
return { success: false, error: new Error(`Error creating test entities table: ${error.message}`) };
|
|
33
31
|
}
|
|
34
|
-
if (
|
|
32
|
+
if (_orgId) {
|
|
35
33
|
try {
|
|
36
34
|
await this.client.query(`
|
|
37
|
-
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${
|
|
35
|
+
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
38
36
|
`);
|
|
39
37
|
}
|
|
40
38
|
catch (error) {
|
|
@@ -44,7 +42,7 @@ export class CreateTestEntitiesTableMigration {
|
|
|
44
42
|
else {
|
|
45
43
|
try {
|
|
46
44
|
await this.client.query(`
|
|
47
|
-
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${
|
|
45
|
+
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
|
|
48
46
|
`);
|
|
49
47
|
}
|
|
50
48
|
catch (error) {
|
|
@@ -53,7 +51,7 @@ export class CreateTestEntitiesTableMigration {
|
|
|
53
51
|
}
|
|
54
52
|
return { success: true, error: null };
|
|
55
53
|
}
|
|
56
|
-
async revert() {
|
|
54
|
+
async revert(_orgId) {
|
|
57
55
|
try {
|
|
58
56
|
await this.client.query(`
|
|
59
57
|
DROP TABLE test_entities;
|
|
@@ -64,7 +62,7 @@ export class CreateTestEntitiesTableMigration {
|
|
|
64
62
|
}
|
|
65
63
|
try {
|
|
66
64
|
await this.client.query(`
|
|
67
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
65
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
68
66
|
`);
|
|
69
67
|
}
|
|
70
68
|
catch (error) {
|
|
@@ -2,18 +2,16 @@ import { IMigration } from "../../databases/postgres/migrations/index.js";
|
|
|
2
2
|
import { Client } from "pg";
|
|
3
3
|
export declare class CreateCategoriesTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
9
|
error: Error;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
12
|
error: null;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateCategoriesTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 2;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "categories" (
|
|
@@ -21,10 +19,10 @@ export class CreateCategoriesTableMigration {
|
|
|
21
19
|
catch (error) {
|
|
22
20
|
return { success: false, error: new Error(`Error creating categories table: ${error.message}`) };
|
|
23
21
|
}
|
|
24
|
-
if (
|
|
22
|
+
if (_orgId) {
|
|
25
23
|
try {
|
|
26
24
|
await this.client.query(`
|
|
27
|
-
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${
|
|
25
|
+
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
28
26
|
`);
|
|
29
27
|
}
|
|
30
28
|
catch (error) {
|
|
@@ -34,7 +32,7 @@ export class CreateCategoriesTableMigration {
|
|
|
34
32
|
else {
|
|
35
33
|
try {
|
|
36
34
|
await this.client.query(`
|
|
37
|
-
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${
|
|
35
|
+
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
|
|
38
36
|
`);
|
|
39
37
|
}
|
|
40
38
|
catch (error) {
|
|
@@ -43,7 +41,7 @@ export class CreateCategoriesTableMigration {
|
|
|
43
41
|
}
|
|
44
42
|
return { success: true, error: null };
|
|
45
43
|
}
|
|
46
|
-
async revert() {
|
|
44
|
+
async revert(_orgId) {
|
|
47
45
|
try {
|
|
48
46
|
await this.client.query(`
|
|
49
47
|
DROP TABLE "categories";
|
|
@@ -54,7 +52,7 @@ export class CreateCategoriesTableMigration {
|
|
|
54
52
|
}
|
|
55
53
|
try {
|
|
56
54
|
await this.client.query(`
|
|
57
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
55
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
58
56
|
`);
|
|
59
57
|
}
|
|
60
58
|
catch (error) {
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "../../databases/postgres/migrations/index.js";
|
|
3
3
|
export declare class CreateProductsTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
9
|
error: Error;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
12
|
error: null;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateProductsTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 3;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "products" (
|
|
@@ -30,10 +28,10 @@ export class CreateProductsTableMigration {
|
|
|
30
28
|
catch (error) {
|
|
31
29
|
return { success: false, error: new Error(`Error creating products table: ${error.message}`) };
|
|
32
30
|
}
|
|
33
|
-
if (
|
|
31
|
+
if (_orgId) {
|
|
34
32
|
try {
|
|
35
33
|
await this.client.query(`
|
|
36
|
-
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${
|
|
34
|
+
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
37
35
|
`);
|
|
38
36
|
}
|
|
39
37
|
catch (error) {
|
|
@@ -43,7 +41,7 @@ export class CreateProductsTableMigration {
|
|
|
43
41
|
else {
|
|
44
42
|
try {
|
|
45
43
|
await this.client.query(`
|
|
46
|
-
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${
|
|
44
|
+
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
|
|
47
45
|
`);
|
|
48
46
|
}
|
|
49
47
|
catch (error) {
|
|
@@ -52,7 +50,7 @@ export class CreateProductsTableMigration {
|
|
|
52
50
|
}
|
|
53
51
|
return { success: true, error: null };
|
|
54
52
|
}
|
|
55
|
-
async revert() {
|
|
53
|
+
async revert(_orgId) {
|
|
56
54
|
try {
|
|
57
55
|
await this.client.query(`
|
|
58
56
|
DROP TABLE "products";
|
|
@@ -63,7 +61,7 @@ export class CreateProductsTableMigration {
|
|
|
63
61
|
}
|
|
64
62
|
try {
|
|
65
63
|
await this.client.query(`
|
|
66
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
64
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
67
65
|
`);
|
|
68
66
|
}
|
|
69
67
|
catch (error) {
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "../../databases/postgres/migrations/index.js";
|
|
3
3
|
export declare class CreateTestUsersTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
9
|
error: Error;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
12
|
error: null;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateTestUsersTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 4;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "testUsers" (
|
|
@@ -34,10 +32,10 @@ export class CreateTestUsersTableMigration {
|
|
|
34
32
|
catch (error) {
|
|
35
33
|
return { success: false, error: new Error(`Error creating test users table: ${error.message}`) };
|
|
36
34
|
}
|
|
37
|
-
if (
|
|
35
|
+
if (_orgId) {
|
|
38
36
|
try {
|
|
39
37
|
await this.client.query(`
|
|
40
|
-
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${
|
|
38
|
+
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
41
39
|
`);
|
|
42
40
|
}
|
|
43
41
|
catch (error) {
|
|
@@ -47,7 +45,7 @@ export class CreateTestUsersTableMigration {
|
|
|
47
45
|
else {
|
|
48
46
|
try {
|
|
49
47
|
await this.client.query(`
|
|
50
|
-
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${
|
|
48
|
+
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
|
|
51
49
|
`);
|
|
52
50
|
}
|
|
53
51
|
catch (error) {
|
|
@@ -56,7 +54,7 @@ export class CreateTestUsersTableMigration {
|
|
|
56
54
|
}
|
|
57
55
|
return { success: true, error: null };
|
|
58
56
|
}
|
|
59
|
-
async revert() {
|
|
57
|
+
async revert(_orgId) {
|
|
60
58
|
try {
|
|
61
59
|
await this.client.query(`
|
|
62
60
|
DROP TABLE "testUsers";
|
|
@@ -67,7 +65,7 @@ export class CreateTestUsersTableMigration {
|
|
|
67
65
|
}
|
|
68
66
|
try {
|
|
69
67
|
await this.client.query(`
|
|
70
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
68
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
71
69
|
`);
|
|
72
70
|
}
|
|
73
71
|
catch (error) {
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "../../databases/postgres/migrations/index.js";
|
|
3
3
|
export declare class CreateTestItemsTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
9
|
error: Error;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
12
|
error: null;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateTestItemsTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 5;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "testItems" (
|
|
@@ -29,10 +27,10 @@ export class CreateTestItemsTableMigration {
|
|
|
29
27
|
catch (error) {
|
|
30
28
|
return { success: false, error: new Error(`Error creating test items table: ${error.message}`) };
|
|
31
29
|
}
|
|
32
|
-
if (
|
|
30
|
+
if (_orgId) {
|
|
33
31
|
try {
|
|
34
32
|
await this.client.query(`
|
|
35
|
-
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${
|
|
33
|
+
Insert into "migrations" ("_id", "_orgId", "index", "hasRun", "reverted") values ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
36
34
|
`);
|
|
37
35
|
}
|
|
38
36
|
catch (error) {
|
|
@@ -42,7 +40,7 @@ export class CreateTestItemsTableMigration {
|
|
|
42
40
|
else {
|
|
43
41
|
try {
|
|
44
42
|
await this.client.query(`
|
|
45
|
-
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${
|
|
43
|
+
Insert into "migrations" ("_id", "index", "hasRun", "reverted") values ('${_id}', ${this.index}, TRUE, FALSE);
|
|
46
44
|
`);
|
|
47
45
|
}
|
|
48
46
|
catch (error) {
|
|
@@ -51,7 +49,7 @@ export class CreateTestItemsTableMigration {
|
|
|
51
49
|
}
|
|
52
50
|
return { success: true, error: null };
|
|
53
51
|
}
|
|
54
|
-
async revert() {
|
|
52
|
+
async revert(_orgId) {
|
|
55
53
|
try {
|
|
56
54
|
await this.client.query(`
|
|
57
55
|
DROP TABLE "testItems";
|
|
@@ -62,7 +60,7 @@ export class CreateTestItemsTableMigration {
|
|
|
62
60
|
}
|
|
63
61
|
try {
|
|
64
62
|
await this.client.query(`
|
|
65
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
63
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
66
64
|
`);
|
|
67
65
|
}
|
|
68
66
|
catch (error) {
|
|
@@ -3,17 +3,17 @@ import { CreateCategoriesTableMigration } from "./002-create-categories-table.mi
|
|
|
3
3
|
import { CreateProductsTableMigration } from "./003-create-products-table.migration.js";
|
|
4
4
|
import { CreateTestUsersTableMigration } from "./004-create-test-users-table.migration.js";
|
|
5
5
|
import { CreateTestItemsTableMigration } from "./005-create-test-items-table.migration.js";
|
|
6
|
-
export async function runTestMigrations(client,
|
|
6
|
+
export async function runTestMigrations(client, _orgId) {
|
|
7
7
|
const migrations = [
|
|
8
|
-
new CreateTestEntitiesTableMigration(client
|
|
9
|
-
new CreateCategoriesTableMigration(client
|
|
10
|
-
new CreateProductsTableMigration(client
|
|
11
|
-
new CreateTestUsersTableMigration(client
|
|
12
|
-
new CreateTestItemsTableMigration(client
|
|
8
|
+
new CreateTestEntitiesTableMigration(client),
|
|
9
|
+
new CreateCategoriesTableMigration(client),
|
|
10
|
+
new CreateProductsTableMigration(client),
|
|
11
|
+
new CreateTestUsersTableMigration(client),
|
|
12
|
+
new CreateTestItemsTableMigration(client),
|
|
13
13
|
];
|
|
14
14
|
try {
|
|
15
15
|
for (const migration of migrations) {
|
|
16
|
-
await migration.execute();
|
|
16
|
+
await migration.execute(_orgId);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
catch (error) {
|
|
@@ -29,7 +29,7 @@ export class TestPostgresDatabase {
|
|
|
29
29
|
const testDatabase = new PostgresDatabase(postgresClient);
|
|
30
30
|
this.database = testDatabase;
|
|
31
31
|
this.postgresClient = postgresClient;
|
|
32
|
-
let success = await setupDatabaseForMultitenant(postgresClient,
|
|
32
|
+
let success = await setupDatabaseForMultitenant(postgresClient, 'Test Org', 'test-org');
|
|
33
33
|
if (!success) {
|
|
34
34
|
throw new Error('Failed to setup for multitenant');
|
|
35
35
|
}
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "./migration.interface.js";
|
|
3
3
|
export declare class CreateMigrationTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
|
-
error:
|
|
9
|
+
error: null;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
|
-
error:
|
|
12
|
+
error: Error;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
export class CreateMigrationTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 1;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let alreadyRun = false;
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
13
10
|
try {
|
|
14
11
|
await this.client.query(`
|
|
15
12
|
CREATE TABLE "migrations" (
|
|
@@ -22,34 +19,32 @@ export class CreateMigrationTableMigration {
|
|
|
22
19
|
`);
|
|
23
20
|
}
|
|
24
21
|
catch (error) {
|
|
25
|
-
if (error.data
|
|
26
|
-
|
|
22
|
+
if (error.code === '42P07' || error.data?.error?.includes('already exists')) {
|
|
23
|
+
return { success: true, error: null };
|
|
27
24
|
}
|
|
28
25
|
else {
|
|
29
26
|
return { success: false, error: new Error(`Error creating migrations table: ${error.message}`) };
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
VALUES ('${this._id}', '${this.orgId}', ${this.index}, TRUE, FALSE);`);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
await this.client.query(`
|
|
41
|
-
INSERT INTO "migrations" ("_id", "index", "hasRun", "reverted")
|
|
42
|
-
VALUES ('${this._id}', ${this.index}, TRUE, FALSE);
|
|
43
|
-
`);
|
|
44
|
-
}
|
|
29
|
+
try {
|
|
30
|
+
if (_orgId) {
|
|
31
|
+
await this.client.query(`
|
|
32
|
+
INSERT INTO "migrations" ("_id", "_orgId", "index", "hasRun", "reverted")
|
|
33
|
+
VALUES ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);`);
|
|
45
34
|
}
|
|
46
|
-
|
|
47
|
-
|
|
35
|
+
else {
|
|
36
|
+
await this.client.query(`
|
|
37
|
+
INSERT INTO "migrations" ("_id", "index", "hasRun", "reverted")
|
|
38
|
+
VALUES ('${_id}', ${this.index}, TRUE, FALSE);
|
|
39
|
+
`);
|
|
48
40
|
}
|
|
49
41
|
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return { success: false, error: new Error(`Error inserting migration ${this.index} to migrations table: ${error.message}`) };
|
|
44
|
+
}
|
|
50
45
|
return { success: true, error: null };
|
|
51
46
|
}
|
|
52
|
-
async revert() {
|
|
47
|
+
async revert(_orgId) {
|
|
53
48
|
try {
|
|
54
49
|
await this.client.query(`
|
|
55
50
|
DROP TABLE "migrations";
|
|
@@ -2,18 +2,18 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "./migration.interface.js";
|
|
3
3
|
export declare class CreateOrganizationTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
private readonly
|
|
6
|
-
|
|
5
|
+
private readonly orgName;
|
|
6
|
+
private readonly orgCode;
|
|
7
|
+
constructor(client: Client, orgName: string, orgCode: string);
|
|
7
8
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
9
|
+
execute(_orgId?: string): Promise<{
|
|
10
10
|
success: boolean;
|
|
11
|
-
error:
|
|
11
|
+
error: null;
|
|
12
12
|
} | {
|
|
13
13
|
success: boolean;
|
|
14
|
-
error:
|
|
14
|
+
error: Error;
|
|
15
15
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
16
|
+
revert(_orgId?: string): Promise<{
|
|
17
17
|
success: boolean;
|
|
18
18
|
error: Error;
|
|
19
19
|
} | {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateOrganizationTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
orgName;
|
|
5
|
+
orgCode;
|
|
6
|
+
constructor(client, orgName, orgCode) {
|
|
6
7
|
this.client = client;
|
|
7
|
-
this.
|
|
8
|
+
this.orgName = orgName;
|
|
9
|
+
this.orgCode = orgCode;
|
|
8
10
|
}
|
|
9
11
|
index = 2;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
async execute(_orgId) {
|
|
13
|
+
const _id = randomUUID().toString();
|
|
14
|
+
const _orgIdToUse = _orgId || randomUUID().toString();
|
|
12
15
|
try {
|
|
13
16
|
await this.client.query(`
|
|
14
17
|
CREATE TABLE "organizations" (
|
|
@@ -29,12 +32,26 @@ export class CreateOrganizationTableMigration {
|
|
|
29
32
|
`);
|
|
30
33
|
}
|
|
31
34
|
catch (error) {
|
|
32
|
-
|
|
35
|
+
if (error.code === '42P07' || error.data?.error?.includes('already exists')) {
|
|
36
|
+
return { success: true, error: null };
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return { success: false, error: new Error(`Error creating organization table: ${error.message}`) };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
await this.client.query(`
|
|
44
|
+
INSERT INTO "organizations" ("_id", "name", "code", "status", "isMetaOrg", "_created", "_createdBy", "_updated", "_updatedBy")
|
|
45
|
+
VALUES ('${_orgIdToUse}', '${this.orgName}', '${this.orgCode}', 1, true, NOW(), 'system', NOW(), 'system');
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return { success: false, error: new Error(`Error creating meta organization: ${error.message}`) };
|
|
33
50
|
}
|
|
34
51
|
try {
|
|
35
52
|
await this.client.query(`
|
|
36
53
|
INSERT INTO "migrations" ("_id", "_orgId", "index", "hasRun", "reverted")
|
|
37
|
-
VALUES ('${
|
|
54
|
+
VALUES ('${_id}', '${_orgIdToUse}', ${this.index}, TRUE, FALSE);
|
|
38
55
|
`);
|
|
39
56
|
}
|
|
40
57
|
catch (error) {
|
|
@@ -42,7 +59,7 @@ export class CreateOrganizationTableMigration {
|
|
|
42
59
|
}
|
|
43
60
|
return { success: true, error: null };
|
|
44
61
|
}
|
|
45
|
-
async revert() {
|
|
62
|
+
async revert(_orgId) {
|
|
46
63
|
try {
|
|
47
64
|
await this.client.query(`
|
|
48
65
|
DROP TABLE "organizations";
|
|
@@ -52,9 +69,15 @@ export class CreateOrganizationTableMigration {
|
|
|
52
69
|
return { success: false, error: new Error(`Error dropping organizations table: ${error.message}`) };
|
|
53
70
|
}
|
|
54
71
|
try {
|
|
55
|
-
await this.client.query(`
|
|
56
|
-
Update "migrations" SET "reverted" = TRUE WHERE "
|
|
72
|
+
const result = await this.client.query(`
|
|
73
|
+
Update "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
57
74
|
`);
|
|
75
|
+
if (result.rowCount === 0) {
|
|
76
|
+
return {
|
|
77
|
+
success: false, error: new Error(`Error updating migration record: Migration record not found.
|
|
78
|
+
Migration index: ${this.index}, _orgId: ${_orgId}`)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
58
81
|
}
|
|
59
82
|
catch (error) {
|
|
60
83
|
return { success: false, error: new Error(`Error updating migration record: ${error.message}`) };
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "./migration.interface.js";
|
|
3
3
|
export declare class CreateUsersTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
|
-
error:
|
|
9
|
+
error: null;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
|
-
error:
|
|
12
|
+
error: Error;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateUsersTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 3;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "users" (
|
|
@@ -32,13 +30,18 @@ export class CreateUsersTableMigration {
|
|
|
32
30
|
`);
|
|
33
31
|
}
|
|
34
32
|
catch (error) {
|
|
35
|
-
|
|
33
|
+
if (error.code === '42P07' || error.data?.error?.includes('already exists')) {
|
|
34
|
+
return { success: true, error: null };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return { success: false, error: new Error(`Error creating users table: ${error.message}`) };
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
|
-
if (
|
|
40
|
+
if (_orgId) {
|
|
38
41
|
try {
|
|
39
42
|
await this.client.query(`
|
|
40
43
|
INSERT INTO "migrations" ("_id", "_orgId", "index", "hasRun", "reverted")
|
|
41
|
-
VALUES ('${
|
|
44
|
+
VALUES ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
42
45
|
`);
|
|
43
46
|
}
|
|
44
47
|
catch (error) {
|
|
@@ -49,7 +52,7 @@ export class CreateUsersTableMigration {
|
|
|
49
52
|
try {
|
|
50
53
|
await this.client.query(`
|
|
51
54
|
INSERT INTO "migrations" ("_id", "index", "hasRun", "reverted")
|
|
52
|
-
VALUES ('${
|
|
55
|
+
VALUES ('${_id}', ${this.index}, TRUE, FALSE);
|
|
53
56
|
`);
|
|
54
57
|
}
|
|
55
58
|
catch (error) {
|
|
@@ -58,7 +61,7 @@ export class CreateUsersTableMigration {
|
|
|
58
61
|
}
|
|
59
62
|
return { success: true, error: null };
|
|
60
63
|
}
|
|
61
|
-
async revert() {
|
|
64
|
+
async revert(_orgId) {
|
|
62
65
|
try {
|
|
63
66
|
await this.client.query(`
|
|
64
67
|
DROP TABLE "users";
|
|
@@ -69,7 +72,7 @@ export class CreateUsersTableMigration {
|
|
|
69
72
|
}
|
|
70
73
|
try {
|
|
71
74
|
await this.client.query(`
|
|
72
|
-
UPDATE "migrations" SET "reverted" = TRUE WHERE "
|
|
75
|
+
UPDATE "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
73
76
|
`);
|
|
74
77
|
}
|
|
75
78
|
catch (error) {
|
|
@@ -2,18 +2,16 @@ import { Client } from "pg";
|
|
|
2
2
|
import { IMigration } from "./migration.interface.js";
|
|
3
3
|
export declare class CreateRefreshTokenTableMigration implements IMigration {
|
|
4
4
|
private readonly client;
|
|
5
|
-
|
|
6
|
-
constructor(client: Client, orgId?: string | undefined);
|
|
5
|
+
constructor(client: Client);
|
|
7
6
|
index: number;
|
|
8
|
-
|
|
9
|
-
execute(): Promise<{
|
|
7
|
+
execute(_orgId?: string): Promise<{
|
|
10
8
|
success: boolean;
|
|
11
|
-
error:
|
|
9
|
+
error: null;
|
|
12
10
|
} | {
|
|
13
11
|
success: boolean;
|
|
14
|
-
error:
|
|
12
|
+
error: Error;
|
|
15
13
|
}>;
|
|
16
|
-
revert(): Promise<{
|
|
14
|
+
revert(_orgId?: string): Promise<{
|
|
17
15
|
success: boolean;
|
|
18
16
|
error: Error;
|
|
19
17
|
} | {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class CreateRefreshTokenTableMigration {
|
|
3
3
|
client;
|
|
4
|
-
|
|
5
|
-
constructor(client, orgId) {
|
|
4
|
+
constructor(client) {
|
|
6
5
|
this.client = client;
|
|
7
|
-
this.orgId = orgId;
|
|
8
6
|
}
|
|
9
7
|
index = 4;
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
async execute(_orgId) {
|
|
9
|
+
const _id = randomUUID().toString();
|
|
12
10
|
try {
|
|
13
11
|
await this.client.query(`
|
|
14
12
|
CREATE TABLE "refreshTokens" (
|
|
@@ -24,13 +22,18 @@ export class CreateRefreshTokenTableMigration {
|
|
|
24
22
|
`);
|
|
25
23
|
}
|
|
26
24
|
catch (error) {
|
|
27
|
-
|
|
25
|
+
if (error.code === '42P07' || error.data?.error?.includes('already exists')) {
|
|
26
|
+
return { success: true, error: null };
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return { success: false, error: new Error(`Error creating refresh token table: ${error.message}`) };
|
|
30
|
+
}
|
|
28
31
|
}
|
|
29
|
-
if (
|
|
32
|
+
if (_orgId) {
|
|
30
33
|
try {
|
|
31
34
|
await this.client.query(`
|
|
32
35
|
INSERT INTO "migrations" ("_id", "_orgId", "index", "hasRun", "reverted")
|
|
33
|
-
VALUES ('${
|
|
36
|
+
VALUES ('${_id}', '${_orgId}', ${this.index}, TRUE, FALSE);
|
|
34
37
|
`);
|
|
35
38
|
}
|
|
36
39
|
catch (error) {
|
|
@@ -41,7 +44,7 @@ export class CreateRefreshTokenTableMigration {
|
|
|
41
44
|
try {
|
|
42
45
|
await this.client.query(`
|
|
43
46
|
INSERT INTO "migrations" ("_id", "index", "hasRun", "reverted")
|
|
44
|
-
VALUES ('${
|
|
47
|
+
VALUES ('${_id}', ${this.index}, TRUE, FALSE);
|
|
45
48
|
`);
|
|
46
49
|
}
|
|
47
50
|
catch (error) {
|
|
@@ -50,7 +53,7 @@ export class CreateRefreshTokenTableMigration {
|
|
|
50
53
|
}
|
|
51
54
|
return { success: true, error: null };
|
|
52
55
|
}
|
|
53
|
-
async revert() {
|
|
56
|
+
async revert(_orgId) {
|
|
54
57
|
try {
|
|
55
58
|
await this.client.query(`
|
|
56
59
|
DROP TABLE "refreshTokens";
|
|
@@ -61,7 +64,7 @@ export class CreateRefreshTokenTableMigration {
|
|
|
61
64
|
}
|
|
62
65
|
try {
|
|
63
66
|
await this.client.query(`
|
|
64
|
-
UPDATE "migrations" SET "reverted" = TRUE WHERE "
|
|
67
|
+
UPDATE "migrations" SET "reverted" = TRUE WHERE "index" = '${this.index}' AND "_orgId" = '${_orgId}';
|
|
65
68
|
`);
|
|
66
69
|
}
|
|
67
70
|
catch (error) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export interface IMigration extends IEntity {
|
|
1
|
+
export interface IMigration {
|
|
3
2
|
index: number;
|
|
4
|
-
execute(): Promise<{
|
|
3
|
+
execute(_orgId?: string): Promise<{
|
|
5
4
|
success: boolean;
|
|
6
5
|
error: Error | null;
|
|
7
6
|
}>;
|
|
8
|
-
revert(): Promise<{
|
|
7
|
+
revert(_orgId?: string): Promise<{
|
|
9
8
|
success: boolean;
|
|
10
9
|
error: Error | null;
|
|
11
10
|
}>;
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { CreateRefreshTokenTableMigration } from "./004-create-refresh-token-table.migration.js";
|
|
2
2
|
import { CreateMigrationTableMigration } from "./001-create-migrations-table.migration.js";
|
|
3
3
|
import { CreateUsersTableMigration } from "./003-create-users-table.migration.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import { doesTableExist } from "../utils/does-table-exist.util.js";
|
|
5
|
+
export async function setupDatabaseForAuth(client, _orgId) {
|
|
6
|
+
let runMigrations = [];
|
|
7
|
+
if (await doesTableExist(client, 'migrations')) {
|
|
8
|
+
const migrations = await client.query(`
|
|
9
|
+
SELECT "_id", "index"
|
|
10
|
+
FROM migrations
|
|
11
|
+
WHERE "hasRun" = TRUE AND "reverted" = FALSE AND "_orgId" = $1
|
|
12
|
+
`, [_orgId]);
|
|
13
|
+
runMigrations = migrations.rows.map((row) => {
|
|
14
|
+
return row.index;
|
|
15
|
+
});
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
let migrationsToRun = [];
|
|
18
|
+
if (!runMigrations.includes(1))
|
|
19
|
+
migrationsToRun.push(new CreateMigrationTableMigration(client));
|
|
20
|
+
if (!runMigrations.includes(3))
|
|
21
|
+
migrationsToRun.push(new CreateUsersTableMigration(client));
|
|
22
|
+
if (!runMigrations.includes(4))
|
|
23
|
+
migrationsToRun.push(new CreateRefreshTokenTableMigration(client));
|
|
24
|
+
for (const migration of migrationsToRun) {
|
|
25
|
+
await migration.execute(_orgId);
|
|
17
26
|
}
|
|
18
27
|
return { success: true, error: null };
|
|
19
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from "pg";
|
|
2
|
-
export declare function setupDatabaseForMultitenant(client: Client,
|
|
2
|
+
export declare function setupDatabaseForMultitenant(client: Client, orgName: string, orgCode: string): Promise<{
|
|
3
3
|
success: boolean;
|
|
4
4
|
error: Error | null;
|
|
5
5
|
}>;
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { CreateMigrationTableMigration } from "./001-create-migrations-table.migration.js";
|
|
2
2
|
import { CreateOrganizationTableMigration } from "./002-create-organizations-table.migration.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { doesTableExist } from "../utils/does-table-exist.util.js";
|
|
4
|
+
export async function setupDatabaseForMultitenant(client, orgName, orgCode) {
|
|
5
|
+
let runMigrations = [];
|
|
6
|
+
if (await doesTableExist(client, 'migrations')) {
|
|
7
|
+
const migrations = await client.query(`
|
|
8
|
+
SELECT "_id", "index"
|
|
9
|
+
FROM migrations
|
|
10
|
+
WHERE "hasRun" = TRUE AND "reverted" = FALSE AND "_orgId" IS NULL
|
|
11
|
+
`);
|
|
12
|
+
runMigrations = migrations.rows.map((row) => {
|
|
13
|
+
return row.index;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
let migrationsToRun = [];
|
|
17
|
+
if (!runMigrations.includes(1))
|
|
18
|
+
migrationsToRun.push(new CreateMigrationTableMigration(client));
|
|
19
|
+
if (!runMigrations.includes(2))
|
|
20
|
+
migrationsToRun.push(new CreateOrganizationTableMigration(client, orgName, orgCode));
|
|
8
21
|
try {
|
|
9
|
-
for (const migration of
|
|
22
|
+
for (const migration of migrationsToRun) {
|
|
10
23
|
await migration.execute();
|
|
11
24
|
}
|
|
12
25
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export async function doesTableExist(client, tableName) {
|
|
2
|
+
const result = await client.query(`
|
|
3
|
+
SELECT EXISTS (
|
|
4
|
+
SELECT 1 FROM information_schema.tables WHERE table_schema = current_schema() AND table_name = $1
|
|
5
|
+
)
|
|
6
|
+
`, [tableName]);
|
|
7
|
+
return result.rows[0].exists;
|
|
8
|
+
}
|