rake-db 2.25.15 → 2.25.17

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/index.mjs CHANGED
@@ -5,9 +5,9 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
5
5
  import fs, { mkdir, writeFile, readdir, stat, readFile } from 'fs/promises';
6
6
 
7
7
  const getFirstWordAndRest = (input) => {
8
- const i = input.search(/(?=[A-Z])|[-_]/);
8
+ const i = input.search(/(?=[A-Z])|[-_ ]/);
9
9
  if (i !== -1) {
10
- const restStart = input[i] === "-" || input[i] === "_" ? i + 1 : i;
10
+ const restStart = input[i] === "-" || input[i] === "_" || input[i] === " " ? i + 1 : i;
11
11
  const rest = input.slice(restStart);
12
12
  return [input.slice(0, i), rest[0].toLowerCase() + rest.slice(1)];
13
13
  } else {
@@ -17,17 +17,17 @@ const getFirstWordAndRest = (input) => {
17
17
  const getTextAfterRegExp = (input, regex, length) => {
18
18
  let i = input.search(regex);
19
19
  if (i === -1) return;
20
- if (input[i] === "-" || input[i] === "_") i++;
20
+ if (input[i] === "-" || input[i] === "_" || input[i] === " ") i++;
21
21
  i += length;
22
- const start = input[i] == "-" || input[i] === "_" ? i + 1 : i;
22
+ const start = input[i] == "-" || input[i] === "_" || input[i] === " " ? i + 1 : i;
23
23
  const text = input.slice(start);
24
24
  return text[0].toLowerCase() + text.slice(1);
25
25
  };
26
26
  const getTextAfterTo = (input) => {
27
- return getTextAfterRegExp(input, /(To|-to|_to)[A-Z-_]/, 2);
27
+ return getTextAfterRegExp(input, /(To|-to|_to| to)[A-Z-_ ]/, 2);
28
28
  };
29
29
  const getTextAfterFrom = (input) => {
30
- return getTextAfterRegExp(input, /(From|-from|_from)[A-Z-_]/, 4);
30
+ return getTextAfterRegExp(input, /(From|-from|_from| from)[A-Z-_ ]/, 4);
31
31
  };
32
32
  const joinWords = (...words) => {
33
33
  return words.slice(1).reduce(
@@ -2531,7 +2531,10 @@ GROUP BY n.nspname, c.relname`
2531
2531
 
2532
2532
  const writeMigrationFile = async (config, version, name, migrationCode) => {
2533
2533
  await mkdir(config.migrationsPath, { recursive: true });
2534
- const filePath = path.resolve(config.migrationsPath, `${version}_${name}.ts`);
2534
+ const filePath = path.resolve(
2535
+ config.migrationsPath,
2536
+ `${version}_${name.replaceAll(" ", "-")}.ts`
2537
+ );
2535
2538
  const importPath = getImportPath(
2536
2539
  filePath,
2537
2540
  path.join(config.basePath, config.dbScript)
@@ -3164,6 +3167,24 @@ const migrateOrRollback = async (trx, config, set, versions, count, up, redo2, f
3164
3167
  return migrations;
3165
3168
  };
3166
3169
  const checkMigrationOrder = (config, set, { sequence, map }, force) => {
3170
+ if (config.migrationId !== "timestamp") {
3171
+ let prev = set.migrations[0];
3172
+ for (let i = 1; i < set.migrations.length; i++) {
3173
+ const file = set.migrations[i];
3174
+ const version = +file.version;
3175
+ const prevVersion = +prev.version;
3176
+ if (version === prevVersion) {
3177
+ throw new Error(
3178
+ `Found migrations with the same number: ${prev.path} and ${file.path}`
3179
+ );
3180
+ } else if (version - prevVersion > 1) {
3181
+ throw new Error(
3182
+ `There is a gap between migrations ${prev.path} and ${file.path}`
3183
+ );
3184
+ }
3185
+ prev = file;
3186
+ }
3187
+ }
3167
3188
  const last = sequence[sequence.length - 1];
3168
3189
  if (last) {
3169
3190
  for (const file of set.migrations) {