murmuration 1.0.21 → 1.0.27

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.
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ const { arrayUtilities, fileSystemUtilities } = require("necessary");
4
+
5
+ const { second } = arrayUtilities,
6
+ { readFile } = fileSystemUtilities;
7
+
8
+ class CustomMigration {
9
+ constructor(filePath) {
10
+ this.filePath = filePath;
11
+ }
12
+
13
+ getSQL() {
14
+ const fileContent = readFile(this.filePath),
15
+ sql = fileContent; ///
16
+
17
+ return sql;
18
+ }
19
+
20
+ getVersion() {
21
+ const matches = this.filePath.match(/(\d+)-.+$/),
22
+ secondMatch = second(matches),
23
+ version = secondMatch; ///
24
+
25
+ return version;
26
+ }
27
+
28
+ apply(connection, callback) {
29
+ const log = connection.getLog(),
30
+ version = this.getVersion();
31
+
32
+ log.info(`Applying custom migration version ${version}...`);
33
+
34
+ const error = true;
35
+
36
+ callback(error);
37
+ }
38
+
39
+ static fromFilePath(filePath) {
40
+ const customMigration = new CustomMigration(filePath);
41
+
42
+ return customMigration;
43
+ }
44
+ }
45
+
46
+ module.exports = CustomMigration;
@@ -18,33 +18,54 @@ class Migrations {
18
18
  return migration;
19
19
  }
20
20
 
21
- static fromMigrationsDirectoryPath(migrationsDirectoryPath) {
22
- const entryNames = readDirectory(migrationsDirectoryPath),
23
- fileNames = entryNames.reduce((fileNames, entryName) => {
24
- const entryNameSQLFileName = /.+\.sql/.test(entryName);
25
-
26
- if (entryNameSQLFileName) {
27
- const sqlFileName = entryName, ///
28
- fileName = sqlFileName; ///
29
-
30
- fileNames.push(fileName);
31
- }
32
-
33
- return fileNames;
34
- }, []),
35
- map = fileNames.reduce((map, fileName) => {
36
- const filePath = concatenatePaths(migrationsDirectoryPath, fileName),
37
- migration = Migration.fromFilePath(filePath),
38
- version = migration.getVersion();
39
-
40
- map[version] = migration;
41
-
42
- return map;
43
- }, {}),
44
- migrations = new Migrations(map);
21
+ static fromCustomMigrationMapAndMigrationsDirectoryPath(CustomMigrationMap, migrationsDirectoryPath) {
22
+ const map = {},
23
+ entryNames = readDirectory(migrationsDirectoryPath),
24
+ sqlFileNames = sqlFileNamesFromEntryNames(entryNames),
25
+ customTextFileNames = customTextFileNamesFromEEntryNames(entryNames);
26
+
27
+ sqlFileNames.forEach((sqlFileName) => {
28
+ const filePath = concatenatePaths(migrationsDirectoryPath, sqlFileName),
29
+ migration = Migration.fromFilePath(filePath),
30
+ version = migration.getVersion();
31
+
32
+ map[version] = migration;
33
+ });
34
+
35
+ customTextFileNames.forEach((customTextFileName) => {
36
+ const filePath = concatenatePaths(migrationsDirectoryPath, customTextFileName),
37
+ CustomMigration = CustomMigrationMap[customTextFileName],
38
+ customMigration = CustomMigration.fromFilePath(filePath),
39
+ migration = customMigration, ///
40
+ version = migration.getVersion();
41
+
42
+ map[version] = migration;
43
+ });
44
+
45
+ const migrations = new Migrations(map);
45
46
 
46
47
  return migrations;
47
48
  }
48
49
  }
49
50
 
50
51
  module.exports = Migrations;
52
+
53
+ function customTextFileNamesFromEEntryNames(entryNames) { return fileNamesFromEntryNames(entryNames, (entryName) => /.+CUSTOM\.txt$/.test(entryName)); }
54
+
55
+ function sqlFileNamesFromEntryNames(entryNames) { return fileNamesFromEntryNames(entryNames, (entryName) => /.+\.sql$/.test(entryName)); }
56
+
57
+ function fileNamesFromEntryNames(entryNames, test) {
58
+ const fileNames = entryNames.reduce((fileNames, entryName) => {
59
+ const entryNameSQLFileName = test(entryName);
60
+
61
+ if (entryNameSQLFileName) {
62
+ const fileName = entryName;
63
+
64
+ fileNames.push(fileName);
65
+ }
66
+
67
+ return fileNames;
68
+ }, []);
69
+
70
+ return fileNames;
71
+ }
@@ -11,8 +11,8 @@ const { first } = arrayUtilities,
11
11
  { whilst } = asynchronousUtilities;
12
12
 
13
13
  function applyMigrationsOperation(next, done, context) {
14
- const { configuration, migrationsDirectoryPath } = context,
15
- migrations = Migrations.fromMigrationsDirectoryPath(migrationsDirectoryPath),
14
+ const { configuration, CustomMigrationMap, migrationsDirectoryPath } = context,
15
+ migrations = Migrations.fromCustomMigrationMapAndMigrationsDirectoryPath(CustomMigrationMap, migrationsDirectoryPath),
16
16
  { log } = configuration;
17
17
 
18
18
  if (log) {
package/bin/migrate.js CHANGED
@@ -7,7 +7,13 @@ const { asynchronousUtilities } = require("necessary");
7
7
 
8
8
  const { sequence } = asynchronousUtilities;
9
9
 
10
- function migrate(configuration, migrationsDirectoryPath, callback) {
10
+ function migrate(configuration, migrationsDirectoryPath, CustomMigrationMap, callback) {
11
+ if (callback === undefined) {
12
+ callback = CustomMigrationMap; ///
13
+
14
+ CustomMigrationMap = {};
15
+ }
16
+
11
17
  const callbacks = [
12
18
  initialiseOperation,
13
19
  applyMigrationsOperation
@@ -16,6 +22,7 @@ function migrate(configuration, migrationsDirectoryPath, callback) {
16
22
  context = {
17
23
  error,
18
24
  configuration,
25
+ CustomMigrationMap,
19
26
  migrationsDirectoryPath
20
27
  };
21
28
 
package/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  const migrate = require("./bin/migrate"),
4
4
  database = require("./bin/database"),
5
5
  defaultLog = require("./bin/defaultLog"),
6
- transaction = require("./bin/transaction");
6
+ transaction = require("./bin/transaction"),
7
+ CustomMigration = require("./bin/migrate/customMigration");
7
8
 
8
9
  module.exports = {
9
10
  migrate,
10
11
  database,
11
12
  defaultLog,
12
- transaction
13
+ transaction,
14
+ CustomMigration
13
15
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "murmuration",
3
3
  "author": "James Smith",
4
- "version": "1.0.21",
4
+ "version": "1.0.27",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/murmuration",
7
7
  "description": "Database connections, transactions and migrations.",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/djalbat/murmuration"
11
11
  },
12
12
  "dependencies": {
13
- "necessary": "^10.0.7"
13
+ "necessary": "^11.0.40"
14
14
  },
15
15
  "devDependencies": {},
16
16
  "scripts": {}