db-migrate 1.0.0-beta.14 → 1.0.0-beta.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.
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
21
21
  );
22
22
 
23
23
  if (internals.locTitle) {
24
- migrator.migrationsDir = path.resolve(
24
+ migrator.directory = path.resolve(
25
25
  internals.argv['migrations-dir'],
26
26
  internals.locTitle
27
27
  );
28
28
  } else {
29
- migrator.migrationsDir = path.resolve(internals.argv['migrations-dir']);
29
+ migrator.directory = path.resolve(internals.argv['migrations-dir']);
30
30
  }
31
31
 
32
- internals.migrationsDir = migrator.migrationsDir;
32
+ internals.migrationsDir = migrator.directory;
33
33
 
34
34
  await migrator.createMigrationsTable();
35
35
  log.verbose('migration table created');
@@ -5,18 +5,38 @@ const log = require('db-migrate-shared').log;
5
5
  const mkdirp = Promise.promisify(require('mkdirp'));
6
6
  const fs = require('fs');
7
7
  const stat = Promise.promisify(fs.stat);
8
+ const writeFile = Promise.promisify(fs.writeFile);
8
9
  const yargs = require('yargs');
9
10
  const util = require('util');
11
+ const path = require('path');
10
12
 
11
13
  async function createMigrationDir (dir) {
12
14
  const res = await stat(dir).catch(_ => {
13
15
  return { err: true };
14
16
  });
15
17
  if (res && res.err === true) {
16
- return mkdirp(dir);
18
+ await mkdirp(dir);
17
19
  }
18
20
 
19
- return Promise.resolve();
21
+ // Create migrations/package.json to ensure migration files are
22
+ // executed as CJS and not ESM
23
+ // https://github.com/db-migrate/node-db-migrate/issues/721
24
+ const packageJsonPath = path.resolve(dir, 'package.json');
25
+
26
+ await stat(packageJsonPath).then(
27
+ async () => {
28
+ const packageJson = require(packageJsonPath);
29
+ packageJson.type = 'commonjs';
30
+ const packageJsonStr = JSON.stringify(packageJson, null, 2);
31
+ await writeFile(packageJsonPath, packageJsonStr, 'utf-8');
32
+ },
33
+ async (err) => {
34
+ const packageJson = JSON.stringify({
35
+ type: 'commonjs'
36
+ }, null, 2)
37
+ await writeFile(packageJsonPath, packageJson, 'utf-8');
38
+ }
39
+ )
20
40
  }
21
41
 
22
42
  async function executeCreateMigration (internals, config) {
@@ -22,7 +22,7 @@ async function prepare (internals, config) {
22
22
  Migrator
23
23
  );
24
24
 
25
- migrator.migrationsDir = path.resolve(internals.argv['migrations-dir']);
25
+ migrator.directory = path.resolve(internals.argv['migrations-dir']);
26
26
 
27
27
  await migrator.createMigrationsTable();
28
28
  log.verbose('migration table created');
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
21
21
  );
22
22
 
23
23
  if (internals.locTitle) {
24
- migrator.migrationsDir = path.resolve(
24
+ migrator.directory = path.resolve(
25
25
  internals.argv['migrations-dir'],
26
26
  internals.locTitle
27
27
  );
28
28
  } else {
29
- migrator.migrationsDir = path.resolve(internals.argv['migrations-dir']);
29
+ migrator.directory = path.resolve(internals.argv['migrations-dir']);
30
30
  }
31
31
 
32
- internals.migrationsDir = migrator.migrationsDir;
32
+ internals.migrationsDir = migrator.directory;
33
33
 
34
34
  await migrator.createMigrationsTable();
35
35
  log.verbose('migration table created');
@@ -21,15 +21,15 @@ async function prepare (internals, config) {
21
21
  );
22
22
 
23
23
  if (internals.locTitle) {
24
- migrator.migrationsDir = path.resolve(
24
+ migrator.directory = path.resolve(
25
25
  internals.argv['migrations-dir'],
26
26
  internals.locTitle
27
27
  );
28
28
  } else {
29
- migrator.migrationsDir = path.resolve(internals.argv['migrations-dir']);
29
+ migrator.directory = path.resolve(internals.argv['migrations-dir']);
30
30
  }
31
31
 
32
- internals.migrationsDir = migrator.migrationsDir;
32
+ internals.migrationsDir = migrator.directory;
33
33
 
34
34
  await migrator.createMigrationsTable();
35
35
  log.verbose('migration table created');
package/lib/learn.js CHANGED
@@ -17,6 +17,10 @@ class STD {
17
17
  this.indizies = schema.i;
18
18
  this.schema = schema.c;
19
19
  this.foreign = schema.f;
20
+ if (!schema.e) {
21
+ schema.e = {};
22
+ }
23
+ this.extra = schema.e;
20
24
  this.modS = mod.c;
21
25
  this.modI = mod.i;
22
26
  this.modF = mod.f;
@@ -87,6 +91,16 @@ class STD {
87
91
  delete this.schema[t];
88
92
  }
89
93
 
94
+ if (this.foreign[t]) {
95
+ this.modF[n] = this.foreign[n];
96
+ delete this.foreign[t];
97
+ }
98
+
99
+ if (this.indizies[t]) {
100
+ this.modI[n] = this.indizies[t];
101
+ delete this.indizies[t];
102
+ }
103
+
90
104
  this.modC.push({ t: 0, a: 'renameTable', c: [n, t] });
91
105
 
92
106
  return Promise.resolve();
package/lib/walker.js CHANGED
@@ -34,8 +34,9 @@ const Walker = function (driver, directory, mode, intern, prefix) {
34
34
  * i: index
35
35
  * c: schema
36
36
  * f: foreignKey
37
+ * e: extra items for the schema (like ENUM tyes)
37
38
  */
38
- this.internals.schema = { i: {}, c: {}, f: {} };
39
+ this.internals.schema = { i: {}, c: {}, f: {}, e: {} };
39
40
  /**
40
41
  * s: commands
41
42
  * i: index
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "programable",
32
32
  "api"
33
33
  ],
34
- "version": "1.0.0-beta.14",
34
+ "version": "1.0.0-beta.18",
35
35
  "engines": {
36
36
  "node": ">=8.0.0"
37
37
  },