@ad-sdk/bgd 0.0.8 → 0.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/sqlx/migrations.js +33 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ad-sdk/bgd",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "main": "index.js",
5
5
  "license": "BSD-3-Clause",
6
6
  "repository": {
@@ -39,41 +39,45 @@ async function migrate(driver, directory, options) {
39
39
  const tx = await driver.createTransaction({
40
40
  allowQueryBatch: true
41
41
  });
42
- for (let i = 0; i < contentsList.length; ++i) {
43
- if (!_core.SQL_MIGRATION_FILE_PATTERN.test(contentsList[i].name)) continue;
44
- const currPath = _nodePath.default.join(contentsList[i].parentPath, contentsList[i].name // eslint-disable-line comma-dangle
45
- );
46
- if (contentsList[i].isDirectory() && options?.recursive) {
47
- const res = await migrate(driver, currPath, options);
48
- if (res.isLeft()) {
49
- throw res.value;
42
+ try {
43
+ for (let i = 0; i < contentsList.length; ++i) {
44
+ if (!_core.SQL_MIGRATION_FILE_PATTERN.test(contentsList[i].name)) continue;
45
+ const currPath = _nodePath.default.join(contentsList[i].parentPath, contentsList[i].name // eslint-disable-line comma-dangle
46
+ );
47
+ if (contentsList[i].isDirectory() && options?.recursive) {
48
+ const res = await migrate(driver, currPath, options);
49
+ if (res.isLeft()) {
50
+ throw res.value;
51
+ }
52
+ continue;
50
53
  }
51
- continue;
52
- }
53
- if (!contentsList[i].isFile()) continue;
54
- if (executed.some(item => {
55
- return item.filename === contentsList[i].name;
56
- })) {
57
- options?.logger?.log("[@@migrate] Migration \"%s\" has already executed. Skipping...", contentsList[i].name);
58
- continue;
59
- }
60
- const fc = await fs.promises.readFile(currPath, "utf8");
61
- const res = await tx.execBatch([{
62
- query: fc.trim()
63
- }, {
64
- query: `INSERT INTO bgd_migrations (
54
+ if (!contentsList[i].isFile()) continue;
55
+ if (executed.some(item => {
56
+ return item.filename === contentsList[i].name;
57
+ })) {
58
+ options?.logger?.log("[@@migrate] Migration \"%s\" has already executed. Skipping...", contentsList[i].name);
59
+ continue;
60
+ }
61
+ const fc = await fs.promises.readFile(currPath, "utf8");
62
+ const res = await tx.execBatch([{
63
+ query: fc.trim()
64
+ }, {
65
+ query: `INSERT INTO bgd_migrations (
65
66
  migration_id, filename, order
66
67
  ) VALUES ($1::TEXT, $2::TEXT, $3::VARCHAR)`,
67
- values: [(0, _uidlib.uuidv7)(), contentsList[0].name, contentsList[i].name.split("_")[0]]
68
- }]);
69
- for (let j = 0; j < res.length; ++j) {
70
- if (res[j].isLeft()) {
71
- await tx.rollback();
72
- throw res[j].value;
68
+ values: [(0, _uidlib.uuidv7)(), contentsList[0].name, contentsList[i].name.split("_")[0]]
69
+ }]);
70
+ for (let j = 0; j < res.length; ++j) {
71
+ if (res[j].isLeft()) {
72
+ throw res[j].value;
73
+ }
73
74
  }
74
75
  }
76
+ await tx.commit();
77
+ } catch (e) {
78
+ await tx.rollback();
79
+ throw e;
75
80
  }
76
- await tx.commit();
77
81
  return (0, _either.right)(void 0);
78
82
  } catch (err) {
79
83
  let e = err;