rake-db 2.0.1 → 2.0.2

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.
@@ -1,5 +1,4 @@
1
1
  import {
2
- Adapter,
3
2
  ColumnType,
4
3
  ForeignKeyModel,
5
4
  ForeignKeyOptions,
@@ -10,7 +9,7 @@ import {
10
9
  toArray,
11
10
  } from 'pqb';
12
11
  import { ColumnComment, ColumnIndex, Migration } from './migration';
13
- import { joinColumns, joinWords } from '../common';
12
+ import { joinColumns, joinWords, quoteTable } from '../common';
14
13
 
15
14
  export const columnToSql = (
16
15
  key: string,
@@ -121,7 +120,9 @@ export const referencesToSql = (
121
120
  columns: string[],
122
121
  foreignKey: Pick<ForeignKeyOptions, 'match' | 'onDelete' | 'onUpdate'>,
123
122
  ) => {
124
- const sql: string[] = [`REFERENCES "${table}"(${joinColumns(columns)})`];
123
+ const sql: string[] = [
124
+ `REFERENCES ${quoteTable(table)}(${joinColumns(columns)})`,
125
+ ];
125
126
 
126
127
  if (foreignKey.match) {
127
128
  sql.push(`MATCH ${foreignKey.match.toUpperCase()}`);
@@ -176,7 +177,7 @@ export const migrateIndex = (
176
177
  sql.push('UNIQUE');
177
178
  }
178
179
 
179
- sql.push(`INDEX "${indexName}" ON "${state.tableName}"`);
180
+ sql.push(`INDEX "${indexName}" ON ${quoteTable(state.tableName)}`);
180
181
 
181
182
  if (options.using) {
182
183
  sql.push(`USING ${options.using}`);
@@ -243,7 +244,9 @@ export const migrateComments = async (
243
244
  ) => {
244
245
  for (const { column, comment } of comments) {
245
246
  await state.migration.query(
246
- `COMMENT ON COLUMN "${state.tableName}"."${column}" IS ${quote(comment)}`,
247
+ `COMMENT ON COLUMN ${quoteTable(state.tableName)}."${column}" IS ${quote(
248
+ comment,
249
+ )}`,
247
250
  );
248
251
  }
249
252
  };
@@ -258,11 +261,12 @@ export const primaryKeyToSql = (
258
261
  };
259
262
 
260
263
  export const getPrimaryKeysOfTable = async (
261
- db: Adapter,
264
+ db: Migration,
262
265
  tableName: string,
263
266
  ): Promise<{ name: string; type: string }[]> => {
264
- const { rows } = await db.query<{ name: string; type: string }>({
265
- text: `SELECT
267
+ const { rows } = await db.query<{ name: string; type: string }>(
268
+ {
269
+ text: `SELECT
266
270
  pg_attribute.attname AS name,
267
271
  format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type
268
272
  FROM pg_index, pg_class, pg_attribute, pg_namespace
@@ -274,8 +278,11 @@ WHERE
274
278
  pg_attribute.attrelid = pg_class.oid AND
275
279
  pg_attribute.attnum = any(pg_index.indkey) AND
276
280
  indisprimary`,
277
- values: [tableName],
278
- });
281
+ values: [tableName],
282
+ },
283
+ db.types,
284
+ undefined,
285
+ );
279
286
 
280
287
  return rows;
281
288
  };
package/src/rakeDb.ts CHANGED
@@ -18,9 +18,9 @@ export const rakeDb = async (
18
18
  } else if (command === 'drop') {
19
19
  await dropDb(options);
20
20
  } else if (command === 'migrate') {
21
- await migrate(options, config);
21
+ await migrate(options, config, args.slice(1));
22
22
  } else if (command === 'rollback') {
23
- await rollback(options, config);
23
+ await rollback(options, config, args.slice(1));
24
24
  } else if (command === 'g' || command === 'generate') {
25
25
  await generate(config, args.slice(1));
26
26
  } else {
package/src/test-utils.ts CHANGED
@@ -6,7 +6,9 @@ let db: Migration | undefined;
6
6
  export const getDb = () => {
7
7
  if (db) return db;
8
8
 
9
- db = new Migration({} as unknown as TransactionAdapter, true);
9
+ db = new Migration({} as unknown as TransactionAdapter, true, {
10
+ log: false,
11
+ });
10
12
  db.query = queryMock;
11
13
  return db;
12
14
  };
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
- "include": ["./src", "jest-setup.ts"],
3
+ "include": ["./src", "jest-setup.ts", "db.ts", "./migrations"],
4
4
  "compilerOptions": {
5
5
  "outDir": "./dist",
6
6
  "noEmit": false,
@@ -1,5 +0,0 @@
1
- import { change } from '../src';
2
-
3
- change(async () => {
4
- console.log('second');
5
- });