velocious 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.7",
6
+ "version": "1.0.8",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "jasmine",
@@ -15,7 +15,9 @@ const configurationResolver = async (args) => {
15
15
  configuration = configurationImport.default
16
16
  } catch (error) {
17
17
  // This might happen during an "init" CLI command where we copy a sample configuration file.
18
- if (error.code != "ERR_MODULE_NOT_FOUND") throw error
18
+ if (!error.message.match(/^Cannot find module '(.+)\/configuration\.js'/)) {
19
+ throw error
20
+ }
19
21
 
20
22
  configuration = new Configuration(args)
21
23
  }
@@ -1,5 +1,6 @@
1
1
  import {digg} from "diggerize"
2
2
 
3
+ import AlterTable from "../sqlite/sql/alter-table.js"
3
4
  import Base from "../base.js"
4
5
  import CreateIndex from "../sqlite/sql/create-index.js"
5
6
  import CreateTable from "../sqlite/sql/create-table.js"
@@ -12,6 +13,13 @@ import Table from "./table"
12
13
  import Update from "../sqlite/sql/update.js"
13
14
 
14
15
  export default class VelociousDatabaseDriversSqliteBase extends Base {
16
+ alterTableSql(columnData) {
17
+ const createArgs = Object.assign({driver: this}, columnData)
18
+ const alterTable = new AlterTable(createArgs)
19
+
20
+ return alterTable.toSqls()
21
+ }
22
+
15
23
  createIndexSql(indexData) {
16
24
  const createArgs = Object.assign({driver: this}, indexData)
17
25
  const createIndex = new CreateIndex(createArgs)
@@ -0,0 +1,4 @@
1
+ import AlterTableBase from "../../../query/alter-table-base.js"
2
+
3
+ export default class VelociousDatabaseConnectionDriversMysqlSqlAlterTable extends AlterTableBase {
4
+ }
@@ -20,7 +20,7 @@ export default class VelociousDatabaseMigrateFromRequireContext {
20
20
 
21
21
  const date = parseInt(match[1])
22
22
  const migrationName = match[2]
23
- const migrationClassName = inflection.camelize(migrationName)
23
+ const migrationClassName = inflection.camelize(migrationName.replaceAll("-", "_"))
24
24
 
25
25
  return {
26
26
  file,
@@ -1,10 +1,22 @@
1
- import TableData from "../table-data/index.js"
1
+ import TableData, {TableColumn} from "../table-data/index.js"
2
2
 
3
3
  export default class VelociousDatabaseMigration {
4
4
  constructor({configuration}) {
5
5
  this.configuration = configuration
6
6
  }
7
7
 
8
+ async addColumn(tableName, columnName, args) {
9
+ const databasePool = this.configuration.getDatabasePool()
10
+ const sqls = databasePool.alterTableSql({
11
+ columns: [new TableColumn(columnName, args)],
12
+ tableName
13
+ })
14
+
15
+ for (const sql of sqls) {
16
+ await databasePool.query(sql)
17
+ }
18
+ }
19
+
8
20
  async addIndex(tableName, columns, args) {
9
21
  const databasePool = this.configuration.getDatabasePool()
10
22
  const createIndexArgs = Object.assign(
@@ -35,6 +35,8 @@ class VelociousDatabasePoolBase {
35
35
  }
36
36
 
37
37
  const forwardMethods = [
38
+ "alterTable",
39
+ "alterTableSql",
38
40
  "createIndex",
39
41
  "createIndexSql",
40
42
  "createTable",
@@ -0,0 +1,26 @@
1
+ import QueryBase from "./base.js"
2
+ import restArgsError from "../../utils/rest-args-error.js"
3
+
4
+ export default class VelociousDatabaseQueryAlterTableBase extends QueryBase {
5
+ constructor({columns, driver, tableName, ...restArgs}) {
6
+ restArgsError(restArgs)
7
+
8
+ super({driver})
9
+ this.columns = columns
10
+ this.tableName = tableName
11
+ }
12
+
13
+ toSqls() {
14
+ const sqls = []
15
+
16
+ for (const column of this.columns) {
17
+ let sql = `ALTER TABLE ${this.driver.quoteTable(this.tableName)} ADD `
18
+
19
+ sql += this.driver.quoteColumn(column.getName())
20
+
21
+ sqls.push(sql)
22
+ }
23
+
24
+ return sqls
25
+ }
26
+ }
@@ -3,6 +3,8 @@ class TableColumn {
3
3
  this.args = args
4
4
  this.name = name
5
5
  }
6
+
7
+ getName = () => this.name
6
8
  }
7
9
 
8
10
  class TableIndex {
@@ -23,6 +25,8 @@ class TableReference {
23
25
  }
24
26
  }
25
27
 
28
+ export {TableColumn}
29
+
26
30
  export default class TableData {
27
31
  _columns = []
28
32
  _indexes = []