velocious 1.0.85 → 1.0.87
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/bin/velocious.js +10 -1
- package/eslint.config.js +33 -0
- package/package.json +7 -2
- package/peak_flow.yml +6 -0
- package/spec/cli/commands/db/create-spec.js +4 -0
- package/spec/cli/commands/db/migrate-spec.js +4 -2
- package/spec/cli/commands/db/rollback-spec.js +179 -0
- package/spec/cli/commands/destroy/migration-spec.js +4 -0
- package/spec/cli/commands/generate/migration-spec.js +4 -0
- package/spec/cli/commands/init-spec.js +4 -0
- package/spec/dummy/index.js +7 -4
- package/spec/dummy/src/config/configuration.example.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.mariadb.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.mssql.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.pgsql.js +2 -0
- package/spec/dummy/src/config/configuration.peakflow.sqlite.js +2 -0
- package/spec/dummy/src/database/migrations/20250921121002-create-project-details.js +3 -1
- package/src/application.js +12 -0
- package/src/cli/base-command.js +9 -5
- package/src/cli/browser-cli.js +37 -0
- package/src/cli/commands/db/create.js +5 -5
- package/src/cli/commands/db/drop.js +4 -5
- package/src/cli/commands/db/migrate.js +6 -10
- package/src/cli/commands/db/reset.js +8 -12
- package/src/cli/commands/db/rollback.js +15 -0
- package/src/cli/commands/destroy/migration.js +2 -2
- package/src/cli/commands/generate/migration.js +3 -6
- package/src/cli/commands/generate/model.js +3 -6
- package/src/cli/commands/init.js +5 -8
- package/src/cli/commands/server.js +3 -3
- package/src/cli/commands/test.js +1 -1
- package/src/cli/index.js +15 -63
- package/src/cli/use-browser-cli.js +25 -0
- package/src/configuration-resolver.js +1 -1
- package/src/configuration.js +118 -9
- package/src/controller.js +29 -0
- package/src/database/drivers/base-column.js +14 -0
- package/src/database/drivers/base-columns-index.js +3 -0
- package/src/database/drivers/base-foreign-key.js +3 -0
- package/src/database/drivers/base-table.js +3 -0
- package/src/database/drivers/base.js +55 -1
- package/src/database/drivers/mssql/index.js +64 -1
- package/src/database/drivers/mysql/columns-index.js +0 -1
- package/src/database/drivers/sqlite/base.js +39 -0
- package/src/database/drivers/sqlite/connection-remote.js +1 -1
- package/src/database/drivers/sqlite/sql/alter-table.js +1 -1
- package/src/database/drivers/sqlite/sql/delete.js +15 -10
- package/src/database/migration/index.js +122 -1
- package/src/database/migrator/files-finder.js +13 -1
- package/src/database/migrator.js +125 -24
- package/src/database/pool/single-multi-use.js +1 -1
- package/src/database/query/alter-table-base.js +11 -0
- package/src/database/query/base.js +7 -0
- package/src/database/query/create-database-base.js +3 -0
- package/src/database/query/create-index-base.js +3 -1
- package/src/database/query/create-table-base.js +3 -0
- package/src/database/query/drop-table-base.js +4 -1
- package/src/database/query/from-base.js +7 -0
- package/src/database/query/index.js +96 -6
- package/src/database/query/insert-base.js +6 -0
- package/src/database/query/join-base.js +3 -0
- package/src/database/query/order-base.js +3 -0
- package/src/database/query/select-base.js +3 -0
- package/src/database/query/update-base.js +3 -0
- package/src/database/query/where-base.js +3 -0
- package/src/database/record/index.js +272 -19
- package/src/database/record/instance-relationships/base.js +66 -1
- package/src/database/record/relationships/base.js +41 -1
- package/src/database/record/validators/base.js +10 -0
- package/src/database/record/validators/presence.js +1 -1
- package/src/database/table-data/table-column.js +37 -3
- package/src/database/table-data/table-index.js +1 -1
- package/src/database/use-database.js +2 -2
- package/src/environment-handlers/base.js +53 -0
- package/src/environment-handlers/browser.js +171 -0
- package/src/environment-handlers/node.js +162 -0
- package/src/http-server/client/request-buffer/index.js +9 -9
- package/src/http-server/index.js +6 -0
- package/src/http-server/worker-handler/index.js +20 -19
- package/src/initializer.js +17 -1
- package/src/logger.js +3 -0
- package/src/routes/app-routes.js +6 -2
- package/src/routes/base-route.js +1 -1
- package/src/routes/get-route.js +1 -1
- package/src/routes/namespace-route.js +1 -1
- package/src/routes/post-route.js +1 -1
- package/src/routes/resolver.js +1 -1
- package/src/routes/resource-route.js +1 -1
- package/src/templates/configuration.js +4 -0
- package/src/testing/request-client.js +26 -3
- package/src/testing/test-files-finder.js +2 -2
- package/src/testing/test-runner.js +74 -28
- package/src/testing/test.js +62 -0
- package/src/utils/file-exists.js +7 -5
- package/src/utils/rest-args-error.js +5 -3
|
@@ -90,6 +90,16 @@ export default class VelociousDatabaseDriversBase {
|
|
|
90
90
|
return table
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @param {object} args
|
|
95
|
+
* @param {Array} args.columns
|
|
96
|
+
* @param {object} args.data
|
|
97
|
+
* @param {boolean} args.multiple
|
|
98
|
+
* @param {boolean} args.returnLastInsertedColumnNames
|
|
99
|
+
* @param {Array} args.rows
|
|
100
|
+
* @param {string} args.tableName
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
93
103
|
async insert(...args) {
|
|
94
104
|
const sql = this.insertSql(...args)
|
|
95
105
|
|
|
@@ -108,6 +118,10 @@ export default class VelociousDatabaseDriversBase {
|
|
|
108
118
|
return value
|
|
109
119
|
}
|
|
110
120
|
|
|
121
|
+
/**
|
|
122
|
+
* @param {string} value
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
111
125
|
quote(value) {
|
|
112
126
|
if (typeof value == "number") return value
|
|
113
127
|
|
|
@@ -117,18 +131,33 @@ export default class VelociousDatabaseDriversBase {
|
|
|
117
131
|
return result
|
|
118
132
|
}
|
|
119
133
|
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} columnName
|
|
136
|
+
* @returns {string}
|
|
137
|
+
*/
|
|
120
138
|
quoteColumn(columnName) {
|
|
121
139
|
return this.options().quoteColumnName(columnName)
|
|
122
140
|
}
|
|
123
141
|
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} columnName
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
124
146
|
quoteIndex(columnName) {
|
|
125
147
|
return this.options().quoteIndexName(columnName)
|
|
126
148
|
}
|
|
127
149
|
|
|
150
|
+
/**
|
|
151
|
+
* @param {string} tableName
|
|
152
|
+
* @returns {string}
|
|
153
|
+
*/
|
|
128
154
|
quoteTable(tableName) {
|
|
129
155
|
return this.options().quoteTableName(tableName)
|
|
130
156
|
}
|
|
131
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @returns {Query}
|
|
160
|
+
*/
|
|
132
161
|
newQuery() {
|
|
133
162
|
const handler = new Handler()
|
|
134
163
|
|
|
@@ -138,6 +167,10 @@ export default class VelociousDatabaseDriversBase {
|
|
|
138
167
|
})
|
|
139
168
|
}
|
|
140
169
|
|
|
170
|
+
/**
|
|
171
|
+
* @param {string} tableName
|
|
172
|
+
* @returns {Promise<Array>}
|
|
173
|
+
*/
|
|
141
174
|
async select(tableName) {
|
|
142
175
|
const query = this.newQuery()
|
|
143
176
|
|
|
@@ -152,6 +185,10 @@ export default class VelociousDatabaseDriversBase {
|
|
|
152
185
|
this.idSeq = id
|
|
153
186
|
}
|
|
154
187
|
|
|
188
|
+
/**
|
|
189
|
+
* @param {string} tableName
|
|
190
|
+
* @returns {Promise<boolean>}
|
|
191
|
+
*/
|
|
155
192
|
async tableExists(tableName) {
|
|
156
193
|
const tables = await this.getTables()
|
|
157
194
|
const table = tables.find((table) => table.getName() == tableName)
|
|
@@ -231,6 +268,10 @@ export default class VelociousDatabaseDriversBase {
|
|
|
231
268
|
await this.query("COMMIT")
|
|
232
269
|
}
|
|
233
270
|
|
|
271
|
+
/**
|
|
272
|
+
* @param {string} sql
|
|
273
|
+
* @returns {Promise<Array>}
|
|
274
|
+
*/
|
|
234
275
|
async query(sql) {
|
|
235
276
|
let tries = 0
|
|
236
277
|
|
|
@@ -251,7 +292,7 @@ export default class VelociousDatabaseDriversBase {
|
|
|
251
292
|
}
|
|
252
293
|
}
|
|
253
294
|
|
|
254
|
-
retryableDatabaseError(_error) {
|
|
295
|
+
retryableDatabaseError(_error) { // eslint-disable-line no-unused-vars
|
|
255
296
|
return false
|
|
256
297
|
}
|
|
257
298
|
|
|
@@ -280,6 +321,12 @@ export default class VelociousDatabaseDriversBase {
|
|
|
280
321
|
await this.query(`SAVEPOINT ${savePointName}`)
|
|
281
322
|
}
|
|
282
323
|
|
|
324
|
+
/**
|
|
325
|
+
* @param {string} tableName
|
|
326
|
+
* @param {string} oldColumnName
|
|
327
|
+
* @param {string} newColumnName
|
|
328
|
+
* @returns {Promise<void>}
|
|
329
|
+
*/
|
|
283
330
|
async renameColumn(tableName, oldColumnName, newColumnName) {
|
|
284
331
|
const tableColumn = new TableColumn(oldColumnName)
|
|
285
332
|
|
|
@@ -348,6 +395,13 @@ export default class VelociousDatabaseDriversBase {
|
|
|
348
395
|
})
|
|
349
396
|
}
|
|
350
397
|
|
|
398
|
+
/**
|
|
399
|
+
* @param {object} args
|
|
400
|
+
* @param {object} args.conditions
|
|
401
|
+
* @param {object} args.data
|
|
402
|
+
* @param {string} args.tableName
|
|
403
|
+
* @returns {Promise<void>}
|
|
404
|
+
*/
|
|
351
405
|
async update(...args) {
|
|
352
406
|
const sql = this.updateSql(...args)
|
|
353
407
|
|
|
@@ -33,6 +33,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
33
33
|
this.connection = undefined
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @returns {string}
|
|
38
|
+
*/
|
|
36
39
|
async alterTableSql(tableData) {
|
|
37
40
|
const alterArgs = {tableData, driver: this}
|
|
38
41
|
const alterTable = new AlterTable(alterArgs)
|
|
@@ -40,6 +43,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
40
43
|
return await alterTable.toSqls()
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @returns {string}
|
|
48
|
+
*/
|
|
43
49
|
createDatabaseSql(databaseName, args) {
|
|
44
50
|
const createArgs = Object.assign({databaseName, driver: this}, args)
|
|
45
51
|
const createDatabase = new CreateDatabase(createArgs)
|
|
@@ -47,6 +53,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
47
53
|
return createDatabase.toSql()
|
|
48
54
|
}
|
|
49
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
50
59
|
createIndexSql(indexData) {
|
|
51
60
|
const createArgs = Object.assign({driver: this}, indexData)
|
|
52
61
|
const createIndex = new CreateIndex(createArgs)
|
|
@@ -54,6 +63,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
54
63
|
return createIndex.toSql()
|
|
55
64
|
}
|
|
56
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
57
69
|
createTableSql(tableData) {
|
|
58
70
|
const createArgs = {tableData, driver: this, indexInCreateTable: false}
|
|
59
71
|
const createTable = new CreateTable(createArgs)
|
|
@@ -61,6 +73,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
61
73
|
return createTable.toSql()
|
|
62
74
|
}
|
|
63
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @returns {Promise<string>}
|
|
78
|
+
*/
|
|
64
79
|
async currentDatabase() {
|
|
65
80
|
const rows = await this.query("SELECT DB_NAME() AS db_name")
|
|
66
81
|
|
|
@@ -75,6 +90,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
75
90
|
await this.query("EXEC sp_MSforeachtable @command1=\"print '?'\", @command2=\"ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all\"")
|
|
76
91
|
}
|
|
77
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @returns {string}
|
|
95
|
+
*/
|
|
78
96
|
dropTableSql(tableName, args = {}) {
|
|
79
97
|
const dropArgs = Object.assign({tableName, driver: this}, args)
|
|
80
98
|
const dropTable = new DropTable(dropArgs)
|
|
@@ -82,7 +100,14 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
82
100
|
return dropTable.toSql()
|
|
83
101
|
}
|
|
84
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @returns {string}
|
|
105
|
+
*/
|
|
85
106
|
getType() { return "mssql" }
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
86
111
|
primaryKeyType() { return "bigint" }
|
|
87
112
|
|
|
88
113
|
async _queryActual(sql) {
|
|
@@ -115,9 +140,17 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
115
140
|
return result.recordsets[0]
|
|
116
141
|
}
|
|
117
142
|
|
|
143
|
+
/**
|
|
144
|
+
* @returns {string}
|
|
145
|
+
*/
|
|
118
146
|
queryToSql(query) { return new QueryParser({query}).toSql() }
|
|
147
|
+
|
|
119
148
|
shouldSetAutoIncrementWhenPrimaryKey() { return true }
|
|
120
149
|
|
|
150
|
+
/**
|
|
151
|
+
* @param {*} value
|
|
152
|
+
* @returns {string}
|
|
153
|
+
*/
|
|
121
154
|
escape(value) {
|
|
122
155
|
value = this._convertValue(value)
|
|
123
156
|
|
|
@@ -131,6 +164,10 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
131
164
|
return result
|
|
132
165
|
}
|
|
133
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @param {*} value
|
|
169
|
+
* @returns {string}
|
|
170
|
+
*/
|
|
134
171
|
quote(value) {
|
|
135
172
|
value = this._convertValue(value)
|
|
136
173
|
|
|
@@ -142,19 +179,42 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
142
179
|
return escapeString(value)
|
|
143
180
|
}
|
|
144
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @param {*} string
|
|
184
|
+
* @returns {string}
|
|
185
|
+
*/
|
|
145
186
|
quoteColumn(string) { return this.options().quoteColumnName(string) }
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param {string|number} string
|
|
190
|
+
* @returns {string}
|
|
191
|
+
*/
|
|
146
192
|
quoteTable(string) { return this.options().quoteTableName(string) }
|
|
147
193
|
|
|
194
|
+
/**
|
|
195
|
+
* @param {string} tableName
|
|
196
|
+
* @param {string} oldColumnName
|
|
197
|
+
* @param {string} newColumnName
|
|
198
|
+
* @returns {Promise<void>}
|
|
199
|
+
*/
|
|
148
200
|
async renameColumn(tableName, oldColumnName, newColumnName) {
|
|
149
201
|
await this.query(`EXEC sp_rename ${this.quote(`${tableName}.${oldColumnName}`)}, ${this.quote(newColumnName)}, 'COLUMN'`)
|
|
150
202
|
}
|
|
151
203
|
|
|
204
|
+
/**
|
|
205
|
+
* @param {object} args
|
|
206
|
+
* @param {string} args.tableName
|
|
207
|
+
* @param {object} args.conditions
|
|
208
|
+
*/
|
|
152
209
|
deleteSql({tableName, conditions}) {
|
|
153
210
|
const deleteInstruction = new Delete({conditions, driver: this, tableName})
|
|
154
211
|
|
|
155
212
|
return deleteInstruction.toSql()
|
|
156
213
|
}
|
|
157
214
|
|
|
215
|
+
/**
|
|
216
|
+
* @returns {string} SQL statement
|
|
217
|
+
*/
|
|
158
218
|
insertSql(args) {
|
|
159
219
|
const insertArgs = Object.assign({driver: this}, args)
|
|
160
220
|
const insert = new Insert(insertArgs)
|
|
@@ -228,7 +288,7 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
228
288
|
await this.query(`SAVE TRANSACTION [${savePointName}]`)
|
|
229
289
|
}
|
|
230
290
|
|
|
231
|
-
async _releaseSavePointAction(savePointName) {
|
|
291
|
+
async _releaseSavePointAction(savePointName) { // eslint-disable-line no-unused-vars
|
|
232
292
|
// Do nothing in MS-SQL.
|
|
233
293
|
}
|
|
234
294
|
|
|
@@ -240,6 +300,9 @@ export default class VelociousDatabaseDriversMssql extends Base{
|
|
|
240
300
|
return `sp${new UUID(4).format().replaceAll("-", "")}`.substring(0, 32)
|
|
241
301
|
}
|
|
242
302
|
|
|
303
|
+
/**
|
|
304
|
+
* @returns {string}
|
|
305
|
+
*/
|
|
243
306
|
updateSql({conditions, data, tableName}) {
|
|
244
307
|
const update = new Update({conditions, data, driver: this, tableName})
|
|
245
308
|
|
|
@@ -54,10 +54,27 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
54
54
|
return dropTable.toSql()
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
57
60
|
deleteSql(args) { return new Delete(Object.assign({driver: this}, args)).toSql() }
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
58
65
|
getType() { return "sqlite" }
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
59
70
|
insertSql(args) { return new Insert(Object.assign({driver: this}, args)).toSql() }
|
|
60
71
|
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} tableName
|
|
74
|
+
* @param {object} args
|
|
75
|
+
* @param {boolean} args.throwError
|
|
76
|
+
* @returns {Promise<Table>}
|
|
77
|
+
*/
|
|
61
78
|
async getTableByName(tableName, args) {
|
|
62
79
|
const result = await this.query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${this.quote(tableName)} LIMIT 1`)
|
|
63
80
|
const row = result[0]
|
|
@@ -74,6 +91,9 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
74
91
|
}
|
|
75
92
|
}
|
|
76
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @returns {Promise<Table[]>}
|
|
96
|
+
*/
|
|
77
97
|
async getTables() {
|
|
78
98
|
const result = await this.query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name")
|
|
79
99
|
const tables = []
|
|
@@ -97,6 +117,9 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @returns {boolean}
|
|
122
|
+
*/
|
|
100
123
|
supportsMultipleInsertValues() {
|
|
101
124
|
if (this.versionMajor >= 4) return true
|
|
102
125
|
if (this.versionMajor == 3 && this.versionMinor >= 8) return true
|
|
@@ -105,6 +128,9 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
105
128
|
return false
|
|
106
129
|
}
|
|
107
130
|
|
|
131
|
+
/**
|
|
132
|
+
* @returns {boolean}
|
|
133
|
+
*/
|
|
108
134
|
supportsInsertIntoReturning() {
|
|
109
135
|
if (this.versionMajor >= 4) return true
|
|
110
136
|
if (this.versionMajor == 3 && this.versionMinor >= 35) return true
|
|
@@ -112,6 +138,12 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
112
138
|
return false
|
|
113
139
|
}
|
|
114
140
|
|
|
141
|
+
/**
|
|
142
|
+
* @param {string} tableName
|
|
143
|
+
* @param {string[]} columns
|
|
144
|
+
* @param {any[][]} rows
|
|
145
|
+
* @returns {Promise<any[]>}
|
|
146
|
+
*/
|
|
115
147
|
async insertMultipleWithSingleInsert(tableName, columns, rows) {
|
|
116
148
|
const sql = new Insert({columns, driver: this, rows, tableName}).toSql()
|
|
117
149
|
|
|
@@ -155,7 +187,14 @@ export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
|
155
187
|
return this._options
|
|
156
188
|
}
|
|
157
189
|
|
|
190
|
+
/**
|
|
191
|
+
* @returns {string} - The type of the primary key for this driver.
|
|
192
|
+
*/
|
|
158
193
|
primaryKeyType() { return "integer" } // Because bigint on SQLite doesn't support auto increment
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @returns {string}
|
|
197
|
+
*/
|
|
159
198
|
queryToSql(query) { return new QueryParser({query}).toSql() }
|
|
160
199
|
|
|
161
200
|
async registerVersion() {
|
|
@@ -97,7 +97,7 @@ export default class VelociousDatabaseConnectionDriversSqliteSqlAlterTable exten
|
|
|
97
97
|
// Register foreign key on the column
|
|
98
98
|
const tableDataColumn = newTableData.getColumns().find((newTableDataColumn) => newTableDataColumn.getName() == foreignKey.getColumnName())
|
|
99
99
|
|
|
100
|
-
if (!tableDataColumn) throw new Error(`Couldn't find column for foreign key: ${
|
|
100
|
+
if (!tableDataColumn) throw new Error(`Couldn't find column for foreign key: ${foreignKey.getName()}`)
|
|
101
101
|
|
|
102
102
|
this.logger.debug(() => [`Setting foreign key on column ${tableDataColumn.getName()}`])
|
|
103
103
|
tableDataColumn.setForeignKey(foreignKey)
|
|
@@ -2,18 +2,23 @@ import DeleteBase from "../../../query/delete-base.js"
|
|
|
2
2
|
|
|
3
3
|
export default class VelociousDatabaseConnectionDriversMysqlSqlDelete extends DeleteBase {
|
|
4
4
|
toSql() {
|
|
5
|
-
let sql = `DELETE FROM ${this.getOptions().quoteTableName(this.tableName)}
|
|
6
|
-
let count = 0
|
|
5
|
+
let sql = `DELETE FROM ${this.getOptions().quoteTableName(this.tableName)}`
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (this.conditions && Object.keys(this.conditions).length > 0) {
|
|
8
|
+
sql += " WHERE "
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
10
|
+
let count = 0
|
|
11
|
+
|
|
12
|
+
for (let columnName in this.conditions) {
|
|
13
|
+
if (count > 0) sql += " AND "
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
sql += this.getOptions().quoteColumnName(columnName)
|
|
16
|
+
sql += " = "
|
|
17
|
+
sql += this.getOptions().quote(this.conditions[columnName])
|
|
18
|
+
count++
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return sql
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
}
|
|
@@ -11,6 +11,12 @@ export default class VelociousDatabaseMigration {
|
|
|
11
11
|
return this._databaseIdentifiers
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @param {object} args
|
|
16
|
+
* @param {string} args.configuration
|
|
17
|
+
* @param {string} args.databaseIdentifier
|
|
18
|
+
* @param {object} args.db
|
|
19
|
+
*/
|
|
14
20
|
constructor({configuration, databaseIdentifier = "default", db}) {
|
|
15
21
|
if (!databaseIdentifier) throw new Error("No database identifier given")
|
|
16
22
|
if (!db) throw new Error("No 'db' given")
|
|
@@ -29,10 +35,26 @@ export default class VelociousDatabaseMigration {
|
|
|
29
35
|
getDriver() { return this._db }
|
|
30
36
|
connection() { return this.getDriver() }
|
|
31
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} sql
|
|
40
|
+
* @returns {Promise<Array>}
|
|
41
|
+
*/
|
|
32
42
|
async execute(sql) {
|
|
33
|
-
await this.connection().query(sql)
|
|
43
|
+
return await this.connection().query(sql)
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} tableName
|
|
48
|
+
* @param {string} columnName
|
|
49
|
+
* @param {string} columnType
|
|
50
|
+
* @param {object} args
|
|
51
|
+
* @param {object} args.default
|
|
52
|
+
* @param {object} args.foreignKey
|
|
53
|
+
* @param {object} args.nullable
|
|
54
|
+
* @param {object} args.primaryKey
|
|
55
|
+
* @param {object} args.unique
|
|
56
|
+
* @returns {Promise<void>}
|
|
57
|
+
*/
|
|
36
58
|
async addColumn(tableName, columnName, columnType, args) {
|
|
37
59
|
if (!columnType) throw new Error("No column type given")
|
|
38
60
|
|
|
@@ -48,6 +70,33 @@ export default class VelociousDatabaseMigration {
|
|
|
48
70
|
}
|
|
49
71
|
}
|
|
50
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} tableName
|
|
75
|
+
* @param {string} columnName
|
|
76
|
+
* @returns {Promise<void>}
|
|
77
|
+
*/
|
|
78
|
+
async removeColumn(tableName, columnName) {
|
|
79
|
+
const tableColumnArgs = Object.assign({dropColumn: true})
|
|
80
|
+
const tableData = new TableData(tableName)
|
|
81
|
+
|
|
82
|
+
tableData.addColumn(columnName, tableColumnArgs)
|
|
83
|
+
|
|
84
|
+
const sqls = await this.getDriver().alterTableSql(tableData)
|
|
85
|
+
|
|
86
|
+
for (const sql of sqls) {
|
|
87
|
+
await this.getDriver().query(sql)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {string} tableName
|
|
93
|
+
* @param {Array} columns
|
|
94
|
+
* @param {object} args
|
|
95
|
+
* @param {boolean} args.ifNotExists
|
|
96
|
+
* @param {string} args.name
|
|
97
|
+
* @param {boolean} args.unique
|
|
98
|
+
* @returns {Promise<void>}
|
|
99
|
+
*/
|
|
51
100
|
async addIndex(tableName, columns, args) {
|
|
52
101
|
const createIndexArgs = Object.assign(
|
|
53
102
|
{
|
|
@@ -61,6 +110,11 @@ export default class VelociousDatabaseMigration {
|
|
|
61
110
|
await this.getDriver().query(sql)
|
|
62
111
|
}
|
|
63
112
|
|
|
113
|
+
/**
|
|
114
|
+
* @param {string} tableName
|
|
115
|
+
* @param {string} referenceName
|
|
116
|
+
* @returns {Promise<void>}
|
|
117
|
+
*/
|
|
64
118
|
async addForeignKey(tableName, referenceName) {
|
|
65
119
|
const referenceNameUnderscore = inflection.underscore(referenceName)
|
|
66
120
|
const tableNameUnderscore = inflection.underscore(tableName)
|
|
@@ -79,6 +133,15 @@ export default class VelociousDatabaseMigration {
|
|
|
79
133
|
)
|
|
80
134
|
}
|
|
81
135
|
|
|
136
|
+
/**
|
|
137
|
+
* @param {string} tableName
|
|
138
|
+
* @param {string} referenceName
|
|
139
|
+
* @param {object} args
|
|
140
|
+
* @param {boolean} args.foreignKey
|
|
141
|
+
* @param {string} args.type
|
|
142
|
+
* @param {boolean} args.unique
|
|
143
|
+
* @returns {Promise<void>}
|
|
144
|
+
*/
|
|
82
145
|
async addReference(tableName, referenceName, args) {
|
|
83
146
|
const {foreignKey, type, unique, ...restArgs} = args
|
|
84
147
|
const columnName = `${inflection.underscore(referenceName)}_id`
|
|
@@ -93,6 +156,23 @@ export default class VelociousDatabaseMigration {
|
|
|
93
156
|
}
|
|
94
157
|
}
|
|
95
158
|
|
|
159
|
+
/**
|
|
160
|
+
* @param {string} tableName
|
|
161
|
+
* @param {string} referenceName
|
|
162
|
+
* @returns {Promise<void>}
|
|
163
|
+
*/
|
|
164
|
+
async removeReference(tableName, referenceName) {
|
|
165
|
+
const columnName = `${inflection.underscore(referenceName)}_id`
|
|
166
|
+
|
|
167
|
+
this.removeColumn(tableName, columnName)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {string} tableName
|
|
172
|
+
* @param {string} columnName
|
|
173
|
+
* @param {boolean} nullable
|
|
174
|
+
* @returns {Promise<void>}
|
|
175
|
+
*/
|
|
96
176
|
async changeColumnNull(tableName, columnName, nullable) {
|
|
97
177
|
const table = await this.getDriver().getTableByName(tableName)
|
|
98
178
|
const column = await table.getColumnByName(columnName)
|
|
@@ -100,6 +180,29 @@ export default class VelociousDatabaseMigration {
|
|
|
100
180
|
await column.changeNullable(nullable)
|
|
101
181
|
}
|
|
102
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @param {string} tableName
|
|
185
|
+
* @param {string} columnName
|
|
186
|
+
* @returns {Promise<boolean>}
|
|
187
|
+
*/
|
|
188
|
+
async columnExists(tableName, columnName) {
|
|
189
|
+
const table = await this.getDriver().getTableByName(tableName)
|
|
190
|
+
const column = await table.getColumnByName(columnName)
|
|
191
|
+
|
|
192
|
+
return Boolean(column)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @param {string} tableName
|
|
197
|
+
* @param {function() : void} arg1
|
|
198
|
+
* @returns {Promise<void>}
|
|
199
|
+
*/
|
|
200
|
+
/**
|
|
201
|
+
* @param {string} tableName
|
|
202
|
+
* @param {object} arg1
|
|
203
|
+
* @param {function() : void} arg2
|
|
204
|
+
* @returns {Promise<void>}
|
|
205
|
+
*/
|
|
103
206
|
async createTable(tableName, arg1, arg2) {
|
|
104
207
|
let args
|
|
105
208
|
let callback
|
|
@@ -138,10 +241,28 @@ export default class VelociousDatabaseMigration {
|
|
|
138
241
|
}
|
|
139
242
|
}
|
|
140
243
|
|
|
244
|
+
/**
|
|
245
|
+
* @param {string} tableName
|
|
246
|
+
* @returns {Promise<void>}
|
|
247
|
+
*/
|
|
248
|
+
async dropTable(tableName) {
|
|
249
|
+
await this.getDriver().dropTable(tableName)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @param {string} tableName
|
|
254
|
+
* @param {string} oldColumnName
|
|
255
|
+
* @param {string} newColumnName
|
|
256
|
+
* @returns {Promise<void>}
|
|
257
|
+
*/
|
|
141
258
|
async renameColumn(tableName, oldColumnName, newColumnName) {
|
|
142
259
|
await this.getDriver().renameColumn(tableName, oldColumnName, newColumnName)
|
|
143
260
|
}
|
|
144
261
|
|
|
262
|
+
/**
|
|
263
|
+
* @param {string} tableName
|
|
264
|
+
* @returns {Promise<boolean>}
|
|
265
|
+
*/
|
|
145
266
|
async tableExists(tableName) {
|
|
146
267
|
const exists = await this.getDriver().tableExists(tableName)
|
|
147
268
|
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import fs from "
|
|
1
|
+
import fs from "fs/promises"
|
|
2
2
|
import * as inflection from "inflection"
|
|
3
3
|
|
|
4
4
|
import restArgsError from "../../utils/rest-args-error.js"
|
|
5
5
|
|
|
6
6
|
export default class VelociousDatabaseMigratorFilesFinder {
|
|
7
|
+
/**
|
|
8
|
+
* @param {object} args
|
|
9
|
+
* @param {string} args.path
|
|
10
|
+
*/
|
|
7
11
|
constructor({path, ...restArgs}) {
|
|
8
12
|
restArgsError(restArgs)
|
|
9
13
|
|
|
@@ -12,6 +16,14 @@ export default class VelociousDatabaseMigratorFilesFinder {
|
|
|
12
16
|
this.path = path
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @returns {Promise<Array<{
|
|
21
|
+
* file: string,
|
|
22
|
+
* fullPath: string,
|
|
23
|
+
* date: number,
|
|
24
|
+
* migrationClassName: string
|
|
25
|
+
* }>>}
|
|
26
|
+
*/
|
|
15
27
|
async findFiles() {
|
|
16
28
|
let files = await fs.readdir(this.path)
|
|
17
29
|
|