@forge/sql 2.0.1-next.0 → 2.1.0-next.2
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/README.md +13 -4
- package/out/__test__/migration.test.d.ts +2 -0
- package/out/__test__/migration.test.d.ts.map +1 -0
- package/out/__test__/migration.test.js +121 -0
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +4 -1
- package/out/migration.d.ts +23 -0
- package/out/migration.d.ts.map +1 -0
- package/out/migration.js +64 -0
- package/out/utils/response-handler.d.ts +10 -0
- package/out/utils/response-handler.d.ts.map +1 -1
- package/out/utils/response-handler.js +21 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,11 +2,20 @@ Library for Forge environment.
|
|
|
2
2
|
|
|
3
3
|
Usage example:
|
|
4
4
|
```typescript
|
|
5
|
-
import sql from "@forge/sql";
|
|
5
|
+
import sql, { migrationRunner } from "@forge/sql";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const migrationResults = await migrationRunner
|
|
8
|
+
.enqueue(
|
|
9
|
+
'v001_create_example_table',
|
|
10
|
+
`CREATE TABLE IF NOT EXISTS example (id INT PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL);`
|
|
11
|
+
)
|
|
12
|
+
.enqueue('v002_alter_example_table_add_age', `ALTER TABLE example ADD COLUMN age INT NOT NULL;`)
|
|
13
|
+
.enqueue('v003_alter_example_table_add_index_age', `CREATE INDEX idx_example_age ON example (age);`)
|
|
14
|
+
.run();
|
|
8
15
|
|
|
9
|
-
const
|
|
16
|
+
const listExamples = await sql.executeRaw('SELECT * FROM example');
|
|
10
17
|
|
|
11
|
-
const
|
|
18
|
+
const statement = sql.prepare('INSERT INTO test example(name, age) VALUES (?, ?)');
|
|
19
|
+
|
|
20
|
+
const insertUserResult = await statement.bindParams('John Doe', 42).execute();
|
|
12
21
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.test.d.ts","sourceRoot":"","sources":["../../src/__test__/migration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const migration_1 = require("../migration");
|
|
4
|
+
const sql_1 = require("../sql");
|
|
5
|
+
const errorCodes_1 = require("../errorCodes");
|
|
6
|
+
const jest_when_1 = require("jest-when");
|
|
7
|
+
const sql_statement_1 = require("../sql-statement");
|
|
8
|
+
jest.mock('../sql');
|
|
9
|
+
describe('Migration', () => {
|
|
10
|
+
let migrationRunner;
|
|
11
|
+
let mockSqlClient;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
mockSqlClient = new sql_1.SqlClient();
|
|
14
|
+
migrationRunner = new migration_1.MigrationRunner(mockSqlClient);
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
describe('enqueueMigration', () => {
|
|
20
|
+
const versionOne = 'v001_create_table_testtest';
|
|
21
|
+
it('should store just one migration with the same name already exists', () => {
|
|
22
|
+
const createTableTest = 'CREATE TABLE test (id INT)';
|
|
23
|
+
migrationRunner.enqueue(versionOne, createTableTest);
|
|
24
|
+
migrationRunner.enqueue(versionOne, createTableTest);
|
|
25
|
+
expect(migrationRunner.getEnqueued().length).toBe(1);
|
|
26
|
+
expect(migrationRunner.getEnqueued()[0].name).toBe(versionOne);
|
|
27
|
+
expect(migrationRunner.getEnqueued()[0].statement).toBe(createTableTest);
|
|
28
|
+
});
|
|
29
|
+
it('should not throw an error if a migration names are unique, even when sql statements with the same name already exists', () => {
|
|
30
|
+
const versionTwo = 'v002_alter_table_test_add_column_foo';
|
|
31
|
+
migrationRunner.enqueue(versionOne, 'CREATE TABLE IF NOT EXISTS test (id INT)');
|
|
32
|
+
migrationRunner.enqueue(versionTwo, 'ALTER TABLE test ADD COLUMN foo BOOLEAN DEFAULT FALSE;');
|
|
33
|
+
expect(migrationRunner.getEnqueued().length).toBe(2);
|
|
34
|
+
expect(migrationRunner.getEnqueued()[0].name).toBe(versionOne);
|
|
35
|
+
expect(migrationRunner.getEnqueued()[1].name).toBe(versionTwo);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('list', () => {
|
|
39
|
+
it('should list all previously migrations', async () => {
|
|
40
|
+
const migratedAtDate = new Date();
|
|
41
|
+
mockSqlClient.executeRaw.mockResolvedValueOnce({
|
|
42
|
+
rows: [{ id: 1, name: 'create-table-test', migratedAt: migratedAtDate }]
|
|
43
|
+
});
|
|
44
|
+
const migrations = await migrationRunner.list();
|
|
45
|
+
expect(migrations.length).toBe(1);
|
|
46
|
+
expect(migrations[0]).toEqual({ id: 1, name: 'create-table-test', migratedAt: migratedAtDate });
|
|
47
|
+
expect(mockSqlClient.executeRaw).toHaveBeenCalledWith('SELECT id, name, migratedAt FROM __migrations;');
|
|
48
|
+
});
|
|
49
|
+
it('should be empty when no previous migrations exist', async () => {
|
|
50
|
+
mockSqlClient.executeRaw.mockResolvedValueOnce({
|
|
51
|
+
rows: []
|
|
52
|
+
});
|
|
53
|
+
const migrations = await migrationRunner.list();
|
|
54
|
+
expect(migrations.length).toBe(0);
|
|
55
|
+
expect(mockSqlClient.executeRaw).toHaveBeenCalledWith('SELECT id, name, migratedAt FROM __migrations;');
|
|
56
|
+
});
|
|
57
|
+
it('should raise an error when schema version table does not exist', async () => {
|
|
58
|
+
const tableDoesNotExistError = new Error(errorCodes_1.errorCodes.SQL_EXECUTION_ERROR);
|
|
59
|
+
mockSqlClient.executeRaw.mockRejectedValue(tableDoesNotExistError);
|
|
60
|
+
await expect(migrationRunner.list()).rejects.toThrow(tableDoesNotExistError);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('run', () => {
|
|
64
|
+
const insertMigrationVersionQueryTemplate = 'INSERT INTO __migrations (name) VALUES (?);';
|
|
65
|
+
const CREATE_TABLE_FOO_QUERY = 'CREATE TABLE IF NOT EXISTS foo (id INT);';
|
|
66
|
+
const CREATE_TABLE_BAR_QUERY = 'CREATE TABLE IF NOT EXISTS bar (id INT);';
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
(0, jest_when_1.verifyAllWhenMocksCalled)();
|
|
69
|
+
(0, jest_when_1.resetAllWhenMocks)();
|
|
70
|
+
});
|
|
71
|
+
describe('when few migrations have been successfully run in the past', () => {
|
|
72
|
+
it('should execute migrations that have not been previously run', async () => {
|
|
73
|
+
migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
|
|
74
|
+
migrationRunner.enqueue('v_002_create_table_bar', CREATE_TABLE_BAR_QUERY);
|
|
75
|
+
(0, jest_when_1.when)(mockSqlClient.executeRaw)
|
|
76
|
+
.calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
|
|
77
|
+
.mockResolvedValue({ rows: [] });
|
|
78
|
+
(0, jest_when_1.when)(mockSqlClient.executeRaw)
|
|
79
|
+
.calledWith('SELECT id, name, migratedAt FROM __migrations;')
|
|
80
|
+
.mockResolvedValue({
|
|
81
|
+
rows: [{ name: 'v_001_create_table_foo', statement: CREATE_TABLE_FOO_QUERY, migratedAt: new Date() }]
|
|
82
|
+
});
|
|
83
|
+
const mockApiCall = jest.fn();
|
|
84
|
+
(0, jest_when_1.when)(mockApiCall)
|
|
85
|
+
.expectCalledWith(insertMigrationVersionQueryTemplate, (0, jest_when_1.when)((arg) => arg[0] === 'v_002_create_table_bar'))
|
|
86
|
+
.mockResolvedValue({});
|
|
87
|
+
(0, jest_when_1.when)(mockSqlClient.prepare)
|
|
88
|
+
.calledWith(insertMigrationVersionQueryTemplate)
|
|
89
|
+
.mockReturnValue(new sql_statement_1.SqlStatement(insertMigrationVersionQueryTemplate, mockApiCall));
|
|
90
|
+
const result = await migrationRunner.run();
|
|
91
|
+
expect(result).toEqual(['v_002_create_table_bar']);
|
|
92
|
+
expect(mockSqlClient.prepare).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(mockSqlClient.executeRaw).toHaveBeenCalledTimes(3);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('when no migrations have been run in the past', () => {
|
|
97
|
+
it('should execute migrations that have not been previously run', async () => {
|
|
98
|
+
const CREATE_TABLE_FOO_QUERY = 'CREATE TABLE IF NOT EXISTS foo (id INT)';
|
|
99
|
+
migrationRunner.enqueue('v_001_create_table_foo', CREATE_TABLE_FOO_QUERY);
|
|
100
|
+
migrationRunner.enqueue('v_002_create_table_bar', 'CREATE TABLE IF NOT EXISTS bar (id INT)');
|
|
101
|
+
(0, jest_when_1.when)(mockSqlClient.executeRaw).calledWith('SELECT id, name, migratedAt FROM __migrations;').mockResolvedValue({
|
|
102
|
+
rows: []
|
|
103
|
+
});
|
|
104
|
+
(0, jest_when_1.when)(mockSqlClient.executeRaw)
|
|
105
|
+
.calledWith((0, jest_when_1.when)((arg) => arg.startsWith('CREATE TABLE IF NOT EXISTS __migrations')))
|
|
106
|
+
.mockResolvedValue({ rows: [] });
|
|
107
|
+
const mockApiCall = jest.fn();
|
|
108
|
+
(0, jest_when_1.when)(mockApiCall)
|
|
109
|
+
.expectCalledWith(insertMigrationVersionQueryTemplate, (0, jest_when_1.when)((arg) => arg[0] === 'v_001_create_table_foo' || arg[0] === 'v_002_create_table_bar'))
|
|
110
|
+
.mockResolvedValue({});
|
|
111
|
+
(0, jest_when_1.when)(mockSqlClient.prepare)
|
|
112
|
+
.calledWith(insertMigrationVersionQueryTemplate)
|
|
113
|
+
.mockReturnValue(new sql_statement_1.SqlStatement(insertMigrationVersionQueryTemplate, mockApiCall));
|
|
114
|
+
const result = await migrationRunner.run();
|
|
115
|
+
expect(result).toEqual(['v_001_create_table_foo', 'v_002_create_table_bar']);
|
|
116
|
+
expect(mockSqlClient.prepare).toHaveBeenCalledTimes(2);
|
|
117
|
+
expect(mockSqlClient.executeRaw).toHaveBeenCalledTimes(4);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
});
|
package/out/index.d.ts
CHANGED
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC;AAC5C,eAAe,GAAG,CAAC"}
|
package/out/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorCodes = void 0;
|
|
3
|
+
exports.sql = exports.migrationRunner = exports.errorCodes = void 0;
|
|
4
4
|
const sql_1 = require("./sql");
|
|
5
|
+
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return sql_1.sql; } });
|
|
5
6
|
const errorCodes_1 = require("./errorCodes");
|
|
6
7
|
Object.defineProperty(exports, "errorCodes", { enumerable: true, get: function () { return errorCodes_1.errorCodes; } });
|
|
8
|
+
const migration_1 = require("./migration");
|
|
9
|
+
Object.defineProperty(exports, "migrationRunner", { enumerable: true, get: function () { return migration_1.migrationRunner; } });
|
|
7
10
|
exports.default = sql_1.sql;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SqlClient } from './sql';
|
|
2
|
+
declare type MigrationRecord = {
|
|
3
|
+
name: string;
|
|
4
|
+
statement: string;
|
|
5
|
+
};
|
|
6
|
+
declare type MigrationVersion = {
|
|
7
|
+
id: number;
|
|
8
|
+
name: string;
|
|
9
|
+
migratedAt: Date;
|
|
10
|
+
};
|
|
11
|
+
export declare class MigrationRunner {
|
|
12
|
+
private readonly sqlClient;
|
|
13
|
+
private readonly migrations;
|
|
14
|
+
constructor(sqlClient: SqlClient);
|
|
15
|
+
initialize(): Promise<void>;
|
|
16
|
+
enqueue(name: string, statement: string): MigrationRunner;
|
|
17
|
+
getEnqueued(): MigrationRecord[];
|
|
18
|
+
list(): Promise<MigrationVersion[]>;
|
|
19
|
+
run(): Promise<string[]>;
|
|
20
|
+
}
|
|
21
|
+
export declare const migrationRunner: MigrationRunner;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,aAAK,gBAAgB,GAAG;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,IAAI,CAAC;CAClB,CAAC;AAOF,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,SAAS,EAAE,SAAS;IAK1B,UAAU;IAIT,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,eAAe;IAQzD,WAAW,IAAI,eAAe,EAAE;IAIjC,IAAI,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAYnC,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAiC/B;AAED,eAAO,MAAM,eAAe,iBAA2B,CAAC"}
|
package/out/migration.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrationRunner = exports.MigrationRunner = void 0;
|
|
4
|
+
const sql_1 = require("./sql");
|
|
5
|
+
const response_handler_1 = require("./utils/response-handler");
|
|
6
|
+
const SCHEMA_VERSION_TABLE_CREATE_QUERY = 'CREATE TABLE IF NOT EXISTS __migrations (id BIGINT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL, migratedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP);';
|
|
7
|
+
const INSERT_SCHEMA_VERSION_QUERY = 'INSERT INTO __migrations (name) VALUES (?);';
|
|
8
|
+
const LIST_MIGRATIONS_QUERY = 'SELECT id, name, migratedAt FROM __migrations;';
|
|
9
|
+
class MigrationRunner {
|
|
10
|
+
sqlClient;
|
|
11
|
+
migrations;
|
|
12
|
+
constructor(sqlClient) {
|
|
13
|
+
this.sqlClient = sqlClient;
|
|
14
|
+
this.migrations = [];
|
|
15
|
+
}
|
|
16
|
+
async initialize() {
|
|
17
|
+
await this.sqlClient.executeRaw(SCHEMA_VERSION_TABLE_CREATE_QUERY);
|
|
18
|
+
}
|
|
19
|
+
enqueue(name, statement) {
|
|
20
|
+
if (this.migrations.some((migration) => migration.name === name)) {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
this.migrations.push({ name, statement });
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
getEnqueued() {
|
|
27
|
+
return this.migrations;
|
|
28
|
+
}
|
|
29
|
+
async list() {
|
|
30
|
+
const result = await this.sqlClient.executeRaw(LIST_MIGRATIONS_QUERY);
|
|
31
|
+
const migrations = new Array();
|
|
32
|
+
for (const row of result.rows) {
|
|
33
|
+
const migratedAt = new Date(row.migratedAt);
|
|
34
|
+
const id = row.id;
|
|
35
|
+
const name = row.name;
|
|
36
|
+
migrations.push({ id, name, migratedAt });
|
|
37
|
+
}
|
|
38
|
+
return migrations;
|
|
39
|
+
}
|
|
40
|
+
async run() {
|
|
41
|
+
await this.initialize();
|
|
42
|
+
const previousMigrations = await this.list();
|
|
43
|
+
const migrationsToRun = this.migrations.filter((migration) => !previousMigrations.some((prev) => prev.name === migration.name));
|
|
44
|
+
const migrationsSuccessfullyRun = [];
|
|
45
|
+
for (const migration of migrationsToRun) {
|
|
46
|
+
try {
|
|
47
|
+
await this.sqlClient.executeRaw(migration.statement);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new response_handler_1.MigrationExecutionError(migration.name, migrationsToRun.map((m) => m.name));
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
await this.sqlClient.prepare(INSERT_SCHEMA_VERSION_QUERY).bindParams(migration.name).execute();
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new response_handler_1.MigrationCheckPointError(migration.name, migrationsToRun.map((m) => m.name));
|
|
57
|
+
}
|
|
58
|
+
migrationsSuccessfullyRun.push(migration.name);
|
|
59
|
+
}
|
|
60
|
+
return migrationsSuccessfullyRun;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.MigrationRunner = MigrationRunner;
|
|
64
|
+
exports.migrationRunner = new MigrationRunner(sql_1.sql);
|
|
@@ -6,5 +6,15 @@ export declare class ApiError extends Error {
|
|
|
6
6
|
readonly debug?: any;
|
|
7
7
|
constructor(status: number, code: string, message: string, suggestion?: string | undefined, debug?: any);
|
|
8
8
|
}
|
|
9
|
+
export declare class MigrationExecutionError extends Error {
|
|
10
|
+
readonly migrationName: string;
|
|
11
|
+
readonly migrationsYetToRun: string[];
|
|
12
|
+
constructor(migrationName: string, migrationsYetToRun: string[]);
|
|
13
|
+
}
|
|
14
|
+
export declare class MigrationCheckPointError extends Error {
|
|
15
|
+
readonly migrationName: string;
|
|
16
|
+
readonly migrationsYetToRun: string[];
|
|
17
|
+
constructor(migrationName: string, migrationsYetToRun: string[]);
|
|
18
|
+
}
|
|
9
19
|
export declare function getResponseBody(response: Response): Promise<Result>;
|
|
10
20
|
//# sourceMappingURL=response-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,qBAAa,QAAS,SAAQ,KAAK;IAE/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC;gBAJN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,CAAC,oBAAQ,EACnB,KAAK,CAAC,KAAK;CAIvB;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BzE"}
|
|
1
|
+
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,qBAAa,QAAS,SAAQ,KAAK;IAE/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC;gBAJN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,CAAC,oBAAQ,EACnB,KAAK,CAAC,KAAK;CAIvB;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAE9C,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE;gBAD5B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,MAAM,EAAE;CAIxC;AAED,qBAAa,wBAAyB,SAAQ,KAAK;IAE/C,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,EAAE;gBAD5B,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,MAAM,EAAE;CAIxC;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BzE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getResponseBody = exports.ApiError = void 0;
|
|
3
|
+
exports.getResponseBody = exports.MigrationCheckPointError = exports.MigrationExecutionError = exports.ApiError = void 0;
|
|
4
4
|
class ApiError extends Error {
|
|
5
5
|
status;
|
|
6
6
|
code;
|
|
@@ -15,6 +15,26 @@ class ApiError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.ApiError = ApiError;
|
|
18
|
+
class MigrationExecutionError extends Error {
|
|
19
|
+
migrationName;
|
|
20
|
+
migrationsYetToRun;
|
|
21
|
+
constructor(migrationName, migrationsYetToRun) {
|
|
22
|
+
super(`Failed to execute migration with name ${migrationName}`);
|
|
23
|
+
this.migrationName = migrationName;
|
|
24
|
+
this.migrationsYetToRun = migrationsYetToRun;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.MigrationExecutionError = MigrationExecutionError;
|
|
28
|
+
class MigrationCheckPointError extends Error {
|
|
29
|
+
migrationName;
|
|
30
|
+
migrationsYetToRun;
|
|
31
|
+
constructor(migrationName, migrationsYetToRun) {
|
|
32
|
+
super(`Failed to checkpoint after running migration with name ${migrationName}`);
|
|
33
|
+
this.migrationName = migrationName;
|
|
34
|
+
this.migrationsYetToRun = migrationsYetToRun;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.MigrationCheckPointError = MigrationCheckPointError;
|
|
18
38
|
async function getResponseBody(response) {
|
|
19
39
|
const responseText = await response.text();
|
|
20
40
|
if (!response.ok) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/sql",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0-next.2",
|
|
4
4
|
"description": "Forge SQL sdk",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"@types/node": "14.18.63",
|
|
19
19
|
"@types/node-fetch": "^2.6.11",
|
|
20
20
|
"expect-type": "^0.17.3",
|
|
21
|
-
"node-fetch": "2.7.0"
|
|
21
|
+
"node-fetch": "2.7.0",
|
|
22
|
+
"jest-when": "^3.6.0"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@forge/api": "^
|
|
25
|
+
"@forge/api": "^4.0.0-next.1"
|
|
25
26
|
}
|
|
26
27
|
}
|