knex 0.21.20 → 0.21.21
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/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +184 -184
- package/LICENSE +22 -22
- package/README.md +95 -95
- package/bin/cli.js +414 -414
- package/bin/utils/cli-config-utils.js +151 -151
- package/bin/utils/constants.js +7 -7
- package/bin/utils/migrationsLister.js +37 -37
- package/knex.js +8 -8
- package/lib/client.js +413 -413
- package/lib/config-resolver.js +61 -61
- package/lib/constants.js +44 -44
- package/lib/dialects/mssql/index.js +390 -390
- package/lib/dialects/mssql/query/compiler.js +444 -444
- package/lib/dialects/mssql/schema/columncompiler.js +103 -103
- package/lib/dialects/mssql/schema/compiler.js +59 -59
- package/lib/dialects/mssql/schema/tablecompiler.js +245 -245
- package/lib/dialects/mssql/transaction.js +97 -97
- package/lib/dialects/mysql/index.js +191 -191
- package/lib/dialects/mysql/query/compiler.js +142 -142
- package/lib/dialects/mysql/schema/columncompiler.js +171 -171
- package/lib/dialects/mysql/schema/compiler.js +60 -60
- package/lib/dialects/mysql/schema/tablecompiler.js +262 -262
- package/lib/dialects/mysql/transaction.js +48 -48
- package/lib/dialects/mysql2/index.js +35 -35
- package/lib/dialects/mysql2/transaction.js +46 -46
- package/lib/dialects/oracle/DEAD_CODE.md +5 -5
- package/lib/dialects/oracle/formatter.js +20 -20
- package/lib/dialects/oracle/index.js +79 -79
- package/lib/dialects/oracle/query/compiler.js +327 -327
- package/lib/dialects/oracle/schema/columnbuilder.js +18 -18
- package/lib/dialects/oracle/schema/columncompiler.js +139 -139
- package/lib/dialects/oracle/schema/compiler.js +81 -81
- package/lib/dialects/oracle/schema/tablecompiler.js +165 -165
- package/lib/dialects/oracle/schema/trigger.js +126 -126
- package/lib/dialects/oracle/utils.js +86 -86
- package/lib/dialects/oracledb/index.js +489 -489
- package/lib/dialects/oracledb/query/compiler.js +363 -363
- package/lib/dialects/oracledb/schema/columncompiler.js +35 -35
- package/lib/dialects/oracledb/transaction.js +76 -76
- package/lib/dialects/oracledb/utils.js +14 -14
- package/lib/dialects/postgres/index.js +319 -319
- package/lib/dialects/postgres/query/compiler.js +206 -206
- package/lib/dialects/postgres/schema/columncompiler.js +125 -125
- package/lib/dialects/postgres/schema/compiler.js +109 -109
- package/lib/dialects/postgres/schema/tablecompiler.js +183 -183
- package/lib/dialects/redshift/index.js +73 -73
- package/lib/dialects/redshift/query/compiler.js +119 -119
- package/lib/dialects/redshift/schema/columnbuilder.js +20 -20
- package/lib/dialects/redshift/schema/columncompiler.js +60 -60
- package/lib/dialects/redshift/schema/compiler.js +14 -14
- package/lib/dialects/redshift/schema/tablecompiler.js +123 -123
- package/lib/dialects/redshift/transaction.js +18 -18
- package/lib/dialects/sqlite3/formatter.js +21 -21
- package/lib/dialects/sqlite3/index.js +169 -169
- package/lib/dialects/sqlite3/query/compiler.js +222 -222
- package/lib/dialects/sqlite3/schema/columncompiler.js +27 -27
- package/lib/dialects/sqlite3/schema/compiler.js +49 -49
- package/lib/dialects/sqlite3/schema/ddl.js +525 -525
- package/lib/dialects/sqlite3/schema/tablecompiler.js +238 -238
- package/lib/formatter.js +295 -295
- package/lib/functionhelper.js +14 -14
- package/lib/helpers.js +92 -92
- package/lib/index.js +3 -3
- package/lib/interface.js +115 -115
- package/lib/knex.js +42 -42
- package/lib/logger.js +76 -76
- package/lib/migrate/MigrationGenerator.js +82 -82
- package/lib/migrate/Migrator.js +611 -611
- package/lib/migrate/configuration-merger.js +60 -60
- package/lib/migrate/migrate-stub.js +17 -17
- package/lib/migrate/migration-list-resolver.js +36 -36
- package/lib/migrate/sources/fs-migrations.js +99 -99
- package/lib/migrate/stub/cjs.stub +15 -15
- package/lib/migrate/stub/coffee.stub +13 -13
- package/lib/migrate/stub/eg.stub +14 -14
- package/lib/migrate/stub/js.stub +15 -15
- package/lib/migrate/stub/knexfile-coffee.stub +34 -34
- package/lib/migrate/stub/knexfile-eg.stub +43 -43
- package/lib/migrate/stub/knexfile-js.stub +44 -44
- package/lib/migrate/stub/knexfile-ls.stub +35 -35
- package/lib/migrate/stub/knexfile-ts.stub +44 -44
- package/lib/migrate/stub/ls.stub +14 -14
- package/lib/migrate/stub/ts.stub +21 -21
- package/lib/migrate/table-creator.js +67 -67
- package/lib/migrate/table-resolver.js +27 -27
- package/lib/query/builder.js +1372 -1372
- package/lib/query/compiler.js +889 -889
- package/lib/query/constants.js +13 -13
- package/lib/query/joinclause.js +263 -263
- package/lib/query/methods.js +92 -92
- package/lib/query/string.js +190 -190
- package/lib/raw.js +188 -188
- package/lib/ref.js +39 -39
- package/lib/runner.js +285 -285
- package/lib/schema/builder.js +82 -82
- package/lib/schema/columnbuilder.js +117 -117
- package/lib/schema/columncompiler.js +177 -177
- package/lib/schema/compiler.js +101 -101
- package/lib/schema/helpers.js +51 -51
- package/lib/schema/tablebuilder.js +288 -288
- package/lib/schema/tablecompiler.js +296 -296
- package/lib/seed/Seeder.js +203 -203
- package/lib/seed/seed-stub.js +13 -13
- package/lib/seed/stub/coffee.stub +9 -9
- package/lib/seed/stub/eg.stub +11 -11
- package/lib/seed/stub/js.stub +13 -13
- package/lib/seed/stub/ls.stub +11 -11
- package/lib/seed/stub/ts.stub +13 -13
- package/lib/transaction.js +363 -363
- package/lib/util/batchInsert.js +59 -59
- package/lib/util/delay.js +6 -6
- package/lib/util/fake-client.js +9 -9
- package/lib/util/finally-mixin.js +13 -13
- package/lib/util/fs.js +76 -76
- package/lib/util/import-file.js +13 -13
- package/lib/util/is-module-type.js +14 -14
- package/lib/util/is.js +32 -32
- package/lib/util/make-knex.js +338 -338
- package/lib/util/nanoid.js +29 -29
- package/lib/util/noop.js +1 -1
- package/lib/util/parse-connection.js +66 -66
- package/lib/util/save-async-stack.js +14 -14
- package/lib/util/template.js +52 -52
- package/lib/util/timeout.js +29 -29
- package/lib/util/timestamp.js +16 -16
- package/package.json +1 -1
- package/scripts/build.js +125 -125
- package/scripts/docker-compose.yml +111 -111
- package/scripts/next-release-howto.md +24 -24
- package/scripts/release.sh +34 -34
- package/scripts/runkit-example.js +34 -34
- package/scripts/stress-test/README.txt +18 -18
- package/scripts/stress-test/docker-compose.yml +47 -47
- package/scripts/stress-test/knex-stress-test.js +196 -196
- package/scripts/stress-test/mysql2-random-hanging-every-now-and-then.js +145 -145
- package/scripts/stress-test/mysql2-sudden-exit-without-error.js +100 -100
- package/scripts/stress-test/reconnect-test-mysql-based-drivers.js +184 -184
- package/types/index.d.ts +2249 -2249
- package/types/result.d.ts +27 -27
- package/types/tables.d.ts +4 -4
package/lib/seed/Seeder.js
CHANGED
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
// Seeder
|
|
2
|
-
// -------
|
|
3
|
-
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const flatten = require('lodash/flatten');
|
|
6
|
-
const extend = require('lodash/extend');
|
|
7
|
-
const includes = require('lodash/includes');
|
|
8
|
-
const { ensureDirectoryExists, getFilepathsInFolder } = require('../util/fs');
|
|
9
|
-
const { writeJsFileUsingTemplate } = require('../util/template');
|
|
10
|
-
const { yyyymmddhhmmss } = require('../util/timestamp');
|
|
11
|
-
|
|
12
|
-
const filterByLoadExtensions = (extensions) => (value) => {
|
|
13
|
-
const extension = path.extname(value);
|
|
14
|
-
return includes(extensions, extension);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// The new seeds we're performing, typically called from the `knex.seed`
|
|
18
|
-
// interface on the main `knex` object. Passes the `knex` instance performing
|
|
19
|
-
// the seeds.
|
|
20
|
-
class Seeder {
|
|
21
|
-
constructor(knex) {
|
|
22
|
-
this.knex = knex;
|
|
23
|
-
this.config = this.setConfig(knex.client.config.seeds);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Runs seed files for the given environment.
|
|
27
|
-
async run(config) {
|
|
28
|
-
this.config = this.setConfig(config);
|
|
29
|
-
let files = await this._listAll();
|
|
30
|
-
if (config && config.specific) {
|
|
31
|
-
files = files.filter((file) => path.basename(file) === config.specific);
|
|
32
|
-
if (files.length === 0) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Invalid argument provided: the specific seed "${config.specific}" does not exist.`
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return this._runSeeds(files);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Creates a new seed file, with a given name.
|
|
42
|
-
async make(name, config) {
|
|
43
|
-
this.config = this.setConfig(config);
|
|
44
|
-
if (!name)
|
|
45
|
-
throw new Error('A name must be specified for the generated seed');
|
|
46
|
-
await this._ensureFolder(config);
|
|
47
|
-
const seedPath = await this._writeNewSeed(name);
|
|
48
|
-
return seedPath;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Lists all available seed files as a sorted array.
|
|
52
|
-
async _listAll(config) {
|
|
53
|
-
this.config = this.setConfig(config);
|
|
54
|
-
const { loadExtensions, recursive } = this.config;
|
|
55
|
-
const seeds = flatten(
|
|
56
|
-
await Promise.all(
|
|
57
|
-
this._absoluteConfigDirs().map((d) =>
|
|
58
|
-
getFilepathsInFolder(d, recursive)
|
|
59
|
-
)
|
|
60
|
-
)
|
|
61
|
-
);
|
|
62
|
-
// if true, each dir are already sorted
|
|
63
|
-
// (getFilepathsInFolderRecursively does this)
|
|
64
|
-
// if false, we need to sort all the seeds
|
|
65
|
-
if (this.config.sortDirsSeparately) {
|
|
66
|
-
return seeds.filter(filterByLoadExtensions(loadExtensions));
|
|
67
|
-
} else {
|
|
68
|
-
return seeds.filter(filterByLoadExtensions(loadExtensions)).sort();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Ensures a folder for the seeds exist, dependent on the
|
|
73
|
-
// seed config settings.
|
|
74
|
-
_ensureFolder() {
|
|
75
|
-
const dirs = this._absoluteConfigDirs();
|
|
76
|
-
const promises = dirs.map(ensureDirectoryExists);
|
|
77
|
-
return Promise.all(promises);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Run seed files, in sequence.
|
|
81
|
-
_runSeeds(seeds) {
|
|
82
|
-
seeds.forEach((seed) => this._validateSeedStructure(seed));
|
|
83
|
-
return this._waterfallBatch(seeds);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Validates seed files by requiring and checking for a `seed` function.
|
|
87
|
-
async _validateSeedStructure(filepath) {
|
|
88
|
-
const importFile = require('../util/import-file'); // late import
|
|
89
|
-
const seed = await importFile(filepath);
|
|
90
|
-
if (typeof seed.seed !== 'function') {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`Invalid seed file: ${filepath} must have a seed function`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return filepath;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_getStubPath() {
|
|
99
|
-
return (
|
|
100
|
-
this.config.stub ||
|
|
101
|
-
path.join(__dirname, 'stub', this.config.extension + '.stub')
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
_getNewStubFileName(name) {
|
|
106
|
-
if (name[0] === '-') name = name.slice(1);
|
|
107
|
-
|
|
108
|
-
if (this.config.timestampFilenamePrefix === true) {
|
|
109
|
-
name = `${yyyymmddhhmmss()}_${name}`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return `${name}.${this.config.extension}`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
_getNewStubFilePath(name) {
|
|
116
|
-
const fileName = this._getNewStubFileName(name);
|
|
117
|
-
const dirs = this._absoluteConfigDirs();
|
|
118
|
-
const dir = dirs.slice(-1)[0]; // Get last specified directory
|
|
119
|
-
return path.join(dir, fileName);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Write a new seed to disk, using the config and generated filename,
|
|
123
|
-
// passing any `variables` given in the config to the template.
|
|
124
|
-
async _writeNewSeed(name) {
|
|
125
|
-
const seedPath = this._getNewStubFilePath(name);
|
|
126
|
-
await writeJsFileUsingTemplate(
|
|
127
|
-
seedPath,
|
|
128
|
-
this._getStubPath(),
|
|
129
|
-
{ variable: 'd' },
|
|
130
|
-
this.config.variables || {}
|
|
131
|
-
);
|
|
132
|
-
return seedPath;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Runs a batch of seed files.
|
|
136
|
-
async _waterfallBatch(seeds) {
|
|
137
|
-
const { knex } = this;
|
|
138
|
-
const log = [];
|
|
139
|
-
for (const seedPath of seeds) {
|
|
140
|
-
const importFile = require('../util/import-file'); // late import
|
|
141
|
-
const seed = await importFile(seedPath);
|
|
142
|
-
try {
|
|
143
|
-
await seed.seed(knex);
|
|
144
|
-
log.push(seedPath);
|
|
145
|
-
} catch (originalError) {
|
|
146
|
-
const error = new Error(
|
|
147
|
-
`Error while executing "${seedPath}" seed: ${originalError.message}`
|
|
148
|
-
);
|
|
149
|
-
error.original = originalError;
|
|
150
|
-
error.stack =
|
|
151
|
-
error.stack.split('\n').slice(0, 2).join('\n') +
|
|
152
|
-
'\n' +
|
|
153
|
-
originalError.stack;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return [log];
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Return all the config directories
|
|
162
|
-
* @returns {string[]}
|
|
163
|
-
*/
|
|
164
|
-
_absoluteConfigDirs() {
|
|
165
|
-
const directories = Array.isArray(this.config.directory)
|
|
166
|
-
? this.config.directory
|
|
167
|
-
: [this.config.directory];
|
|
168
|
-
return directories.map((directory) => {
|
|
169
|
-
if (!directory) {
|
|
170
|
-
console.warn(
|
|
171
|
-
'Failed to resolve config file, knex cannot determine where to run or make seeds'
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
return path.resolve(process.cwd(), directory);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
setConfig(config) {
|
|
179
|
-
return extend(
|
|
180
|
-
{
|
|
181
|
-
extension: 'js',
|
|
182
|
-
directory: './seeds',
|
|
183
|
-
loadExtensions: [
|
|
184
|
-
'.co',
|
|
185
|
-
'.coffee',
|
|
186
|
-
'.eg',
|
|
187
|
-
'.iced',
|
|
188
|
-
'.js',
|
|
189
|
-
'.litcoffee',
|
|
190
|
-
'.ls',
|
|
191
|
-
'.ts',
|
|
192
|
-
],
|
|
193
|
-
timestampFilenamePrefix: false,
|
|
194
|
-
sortDirsSeparately: false,
|
|
195
|
-
recursive: false,
|
|
196
|
-
},
|
|
197
|
-
this.config || {},
|
|
198
|
-
config
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
module.exports = Seeder;
|
|
1
|
+
// Seeder
|
|
2
|
+
// -------
|
|
3
|
+
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const flatten = require('lodash/flatten');
|
|
6
|
+
const extend = require('lodash/extend');
|
|
7
|
+
const includes = require('lodash/includes');
|
|
8
|
+
const { ensureDirectoryExists, getFilepathsInFolder } = require('../util/fs');
|
|
9
|
+
const { writeJsFileUsingTemplate } = require('../util/template');
|
|
10
|
+
const { yyyymmddhhmmss } = require('../util/timestamp');
|
|
11
|
+
|
|
12
|
+
const filterByLoadExtensions = (extensions) => (value) => {
|
|
13
|
+
const extension = path.extname(value);
|
|
14
|
+
return includes(extensions, extension);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The new seeds we're performing, typically called from the `knex.seed`
|
|
18
|
+
// interface on the main `knex` object. Passes the `knex` instance performing
|
|
19
|
+
// the seeds.
|
|
20
|
+
class Seeder {
|
|
21
|
+
constructor(knex) {
|
|
22
|
+
this.knex = knex;
|
|
23
|
+
this.config = this.setConfig(knex.client.config.seeds);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Runs seed files for the given environment.
|
|
27
|
+
async run(config) {
|
|
28
|
+
this.config = this.setConfig(config);
|
|
29
|
+
let files = await this._listAll();
|
|
30
|
+
if (config && config.specific) {
|
|
31
|
+
files = files.filter((file) => path.basename(file) === config.specific);
|
|
32
|
+
if (files.length === 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Invalid argument provided: the specific seed "${config.specific}" does not exist.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return this._runSeeds(files);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Creates a new seed file, with a given name.
|
|
42
|
+
async make(name, config) {
|
|
43
|
+
this.config = this.setConfig(config);
|
|
44
|
+
if (!name)
|
|
45
|
+
throw new Error('A name must be specified for the generated seed');
|
|
46
|
+
await this._ensureFolder(config);
|
|
47
|
+
const seedPath = await this._writeNewSeed(name);
|
|
48
|
+
return seedPath;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Lists all available seed files as a sorted array.
|
|
52
|
+
async _listAll(config) {
|
|
53
|
+
this.config = this.setConfig(config);
|
|
54
|
+
const { loadExtensions, recursive } = this.config;
|
|
55
|
+
const seeds = flatten(
|
|
56
|
+
await Promise.all(
|
|
57
|
+
this._absoluteConfigDirs().map((d) =>
|
|
58
|
+
getFilepathsInFolder(d, recursive)
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
// if true, each dir are already sorted
|
|
63
|
+
// (getFilepathsInFolderRecursively does this)
|
|
64
|
+
// if false, we need to sort all the seeds
|
|
65
|
+
if (this.config.sortDirsSeparately) {
|
|
66
|
+
return seeds.filter(filterByLoadExtensions(loadExtensions));
|
|
67
|
+
} else {
|
|
68
|
+
return seeds.filter(filterByLoadExtensions(loadExtensions)).sort();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Ensures a folder for the seeds exist, dependent on the
|
|
73
|
+
// seed config settings.
|
|
74
|
+
_ensureFolder() {
|
|
75
|
+
const dirs = this._absoluteConfigDirs();
|
|
76
|
+
const promises = dirs.map(ensureDirectoryExists);
|
|
77
|
+
return Promise.all(promises);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Run seed files, in sequence.
|
|
81
|
+
_runSeeds(seeds) {
|
|
82
|
+
seeds.forEach((seed) => this._validateSeedStructure(seed));
|
|
83
|
+
return this._waterfallBatch(seeds);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Validates seed files by requiring and checking for a `seed` function.
|
|
87
|
+
async _validateSeedStructure(filepath) {
|
|
88
|
+
const importFile = require('../util/import-file'); // late import
|
|
89
|
+
const seed = await importFile(filepath);
|
|
90
|
+
if (typeof seed.seed !== 'function') {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Invalid seed file: ${filepath} must have a seed function`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return filepath;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_getStubPath() {
|
|
99
|
+
return (
|
|
100
|
+
this.config.stub ||
|
|
101
|
+
path.join(__dirname, 'stub', this.config.extension + '.stub')
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_getNewStubFileName(name) {
|
|
106
|
+
if (name[0] === '-') name = name.slice(1);
|
|
107
|
+
|
|
108
|
+
if (this.config.timestampFilenamePrefix === true) {
|
|
109
|
+
name = `${yyyymmddhhmmss()}_${name}`;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return `${name}.${this.config.extension}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_getNewStubFilePath(name) {
|
|
116
|
+
const fileName = this._getNewStubFileName(name);
|
|
117
|
+
const dirs = this._absoluteConfigDirs();
|
|
118
|
+
const dir = dirs.slice(-1)[0]; // Get last specified directory
|
|
119
|
+
return path.join(dir, fileName);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Write a new seed to disk, using the config and generated filename,
|
|
123
|
+
// passing any `variables` given in the config to the template.
|
|
124
|
+
async _writeNewSeed(name) {
|
|
125
|
+
const seedPath = this._getNewStubFilePath(name);
|
|
126
|
+
await writeJsFileUsingTemplate(
|
|
127
|
+
seedPath,
|
|
128
|
+
this._getStubPath(),
|
|
129
|
+
{ variable: 'd' },
|
|
130
|
+
this.config.variables || {}
|
|
131
|
+
);
|
|
132
|
+
return seedPath;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Runs a batch of seed files.
|
|
136
|
+
async _waterfallBatch(seeds) {
|
|
137
|
+
const { knex } = this;
|
|
138
|
+
const log = [];
|
|
139
|
+
for (const seedPath of seeds) {
|
|
140
|
+
const importFile = require('../util/import-file'); // late import
|
|
141
|
+
const seed = await importFile(seedPath);
|
|
142
|
+
try {
|
|
143
|
+
await seed.seed(knex);
|
|
144
|
+
log.push(seedPath);
|
|
145
|
+
} catch (originalError) {
|
|
146
|
+
const error = new Error(
|
|
147
|
+
`Error while executing "${seedPath}" seed: ${originalError.message}`
|
|
148
|
+
);
|
|
149
|
+
error.original = originalError;
|
|
150
|
+
error.stack =
|
|
151
|
+
error.stack.split('\n').slice(0, 2).join('\n') +
|
|
152
|
+
'\n' +
|
|
153
|
+
originalError.stack;
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return [log];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Return all the config directories
|
|
162
|
+
* @returns {string[]}
|
|
163
|
+
*/
|
|
164
|
+
_absoluteConfigDirs() {
|
|
165
|
+
const directories = Array.isArray(this.config.directory)
|
|
166
|
+
? this.config.directory
|
|
167
|
+
: [this.config.directory];
|
|
168
|
+
return directories.map((directory) => {
|
|
169
|
+
if (!directory) {
|
|
170
|
+
console.warn(
|
|
171
|
+
'Failed to resolve config file, knex cannot determine where to run or make seeds'
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return path.resolve(process.cwd(), directory);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setConfig(config) {
|
|
179
|
+
return extend(
|
|
180
|
+
{
|
|
181
|
+
extension: 'js',
|
|
182
|
+
directory: './seeds',
|
|
183
|
+
loadExtensions: [
|
|
184
|
+
'.co',
|
|
185
|
+
'.coffee',
|
|
186
|
+
'.eg',
|
|
187
|
+
'.iced',
|
|
188
|
+
'.js',
|
|
189
|
+
'.litcoffee',
|
|
190
|
+
'.ls',
|
|
191
|
+
'.ts',
|
|
192
|
+
],
|
|
193
|
+
timestampFilenamePrefix: false,
|
|
194
|
+
sortDirsSeparately: false,
|
|
195
|
+
recursive: false,
|
|
196
|
+
},
|
|
197
|
+
this.config || {},
|
|
198
|
+
config
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = Seeder;
|
package/lib/seed/seed-stub.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Stub Seed:
|
|
2
|
-
// Used for now in browser builds, where filesystem access isn't
|
|
3
|
-
// available.
|
|
4
|
-
const StubSeed = (module.exports = function () {});
|
|
5
|
-
|
|
6
|
-
const noSuchMethod = async function () {
|
|
7
|
-
throw new Error('Seeds are not supported');
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
StubSeed.prototype = {
|
|
11
|
-
make: noSuchMethod,
|
|
12
|
-
run: noSuchMethod,
|
|
13
|
-
};
|
|
1
|
+
// Stub Seed:
|
|
2
|
+
// Used for now in browser builds, where filesystem access isn't
|
|
3
|
+
// available.
|
|
4
|
+
const StubSeed = (module.exports = function () {});
|
|
5
|
+
|
|
6
|
+
const noSuchMethod = async function () {
|
|
7
|
+
throw new Error('Seeds are not supported');
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
StubSeed.prototype = {
|
|
11
|
+
make: noSuchMethod,
|
|
12
|
+
run: noSuchMethod,
|
|
13
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
exports.seed = (knex) ->
|
|
2
|
-
knex('table_name').del()
|
|
3
|
-
.then () ->
|
|
4
|
-
# Inserts seed entries
|
|
5
|
-
knex('table_name').insert([
|
|
6
|
-
{id: 1, colName: 'rowValue'}
|
|
7
|
-
{id: 2, colName: 'rowValue2'}
|
|
8
|
-
{id: 3, colName: 'rowValue3'}
|
|
9
|
-
])
|
|
1
|
+
exports.seed = (knex) ->
|
|
2
|
+
knex('table_name').del()
|
|
3
|
+
.then () ->
|
|
4
|
+
# Inserts seed entries
|
|
5
|
+
knex('table_name').insert([
|
|
6
|
+
{id: 1, colName: 'rowValue'}
|
|
7
|
+
{id: 2, colName: 'rowValue2'}
|
|
8
|
+
{id: 3, colName: 'rowValue3'}
|
|
9
|
+
])
|
package/lib/seed/stub/eg.stub
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
provide: seed
|
|
2
|
-
seed = (knex) ->
|
|
3
|
-
;; Deletes ALL existing entries
|
|
4
|
-
knex(.table_name).del()
|
|
5
|
-
.then(() ->
|
|
6
|
-
;; Inserts seed entries
|
|
7
|
-
knex(.table_name).insert with [
|
|
8
|
-
{ id = 1, col-name = .row-value-1 }
|
|
9
|
-
{ id = 2, col-name = .row-value-2 }
|
|
10
|
-
{ id = 3, col-name = .row-value-3 }
|
|
11
|
-
]
|
|
1
|
+
provide: seed
|
|
2
|
+
seed = (knex) ->
|
|
3
|
+
;; Deletes ALL existing entries
|
|
4
|
+
knex(.table_name).del()
|
|
5
|
+
.then(() ->
|
|
6
|
+
;; Inserts seed entries
|
|
7
|
+
knex(.table_name).insert with [
|
|
8
|
+
{ id = 1, col-name = .row-value-1 }
|
|
9
|
+
{ id = 2, col-name = .row-value-2 }
|
|
10
|
+
{ id = 3, col-name = .row-value-3 }
|
|
11
|
+
]
|
package/lib/seed/stub/js.stub
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
exports.seed = function(knex) {
|
|
3
|
-
// Deletes ALL existing entries
|
|
4
|
-
return knex('table_name').del()
|
|
5
|
-
.then(function () {
|
|
6
|
-
// Inserts seed entries
|
|
7
|
-
return knex('table_name').insert([
|
|
8
|
-
{id: 1, colName: 'rowValue1'},
|
|
9
|
-
{id: 2, colName: 'rowValue2'},
|
|
10
|
-
{id: 3, colName: 'rowValue3'}
|
|
11
|
-
]);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
1
|
+
|
|
2
|
+
exports.seed = function(knex) {
|
|
3
|
+
// Deletes ALL existing entries
|
|
4
|
+
return knex('table_name').del()
|
|
5
|
+
.then(function () {
|
|
6
|
+
// Inserts seed entries
|
|
7
|
+
return knex('table_name').insert([
|
|
8
|
+
{id: 1, colName: 'rowValue1'},
|
|
9
|
+
{id: 2, colName: 'rowValue2'},
|
|
10
|
+
{id: 3, colName: 'rowValue3'}
|
|
11
|
+
]);
|
|
12
|
+
});
|
|
13
|
+
};
|
package/lib/seed/stub/ls.stub
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
exports.seed = (knex) ->
|
|
2
|
-
# Deletes ALL existing entries
|
|
3
|
-
knex('table_name').del()
|
|
4
|
-
.then(() ->
|
|
5
|
-
# Inserts seed entries
|
|
6
|
-
knex('table_name').insert([
|
|
7
|
-
{id: 1, colName: 'rowValue1'},
|
|
8
|
-
{id: 2, colName: 'rowValue2'},
|
|
9
|
-
{id: 3, colName: 'rowValue3'}
|
|
10
|
-
])
|
|
11
|
-
)
|
|
1
|
+
exports.seed = (knex) ->
|
|
2
|
+
# Deletes ALL existing entries
|
|
3
|
+
knex('table_name').del()
|
|
4
|
+
.then(() ->
|
|
5
|
+
# Inserts seed entries
|
|
6
|
+
knex('table_name').insert([
|
|
7
|
+
{id: 1, colName: 'rowValue1'},
|
|
8
|
+
{id: 2, colName: 'rowValue2'},
|
|
9
|
+
{id: 3, colName: 'rowValue3'}
|
|
10
|
+
])
|
|
11
|
+
)
|
package/lib/seed/stub/ts.stub
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as Knex from "knex";
|
|
2
|
-
|
|
3
|
-
export async function seed(knex: Knex): Promise<void> {
|
|
4
|
-
// Deletes ALL existing entries
|
|
5
|
-
await knex("table_name").del();
|
|
6
|
-
|
|
7
|
-
// Inserts seed entries
|
|
8
|
-
await knex("table_name").insert([
|
|
9
|
-
{ id: 1, colName: "rowValue1" },
|
|
10
|
-
{ id: 2, colName: "rowValue2" },
|
|
11
|
-
{ id: 3, colName: "rowValue3" }
|
|
12
|
-
]);
|
|
13
|
-
};
|
|
1
|
+
import * as Knex from "knex";
|
|
2
|
+
|
|
3
|
+
export async function seed(knex: Knex): Promise<void> {
|
|
4
|
+
// Deletes ALL existing entries
|
|
5
|
+
await knex("table_name").del();
|
|
6
|
+
|
|
7
|
+
// Inserts seed entries
|
|
8
|
+
await knex("table_name").insert([
|
|
9
|
+
{ id: 1, colName: "rowValue1" },
|
|
10
|
+
{ id: 2, colName: "rowValue2" },
|
|
11
|
+
{ id: 3, colName: "rowValue3" }
|
|
12
|
+
]);
|
|
13
|
+
};
|