rake-db 2.27.26 → 2.27.28

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as pqb from 'pqb';
2
- import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, MaybeArray, Column, RawSQLBase, RecordString, EnumColumn, EmptyObject, ColumnSchemaConfig, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, AdapterBase, DbResult, MaybePromise, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap, QueryBase } from 'pqb';
2
+ import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EnumColumn, EmptyObject, ColumnSchemaConfig, DefaultColumnTypes, DefaultSchemaConfig, QueryLogOptions, AdapterBase, DbResult, MaybePromise, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap, Query } from 'pqb';
3
3
 
4
4
  interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
5
5
  table: Db<Table, Shape>;
@@ -44,8 +44,8 @@ declare namespace RakeDbAst {
44
44
  using?: ChangeUsing;
45
45
  }
46
46
  interface ChangeUsing {
47
- usingUp?: RawSQLBase;
48
- usingDown?: RawSQLBase;
47
+ usingUp?: RawSqlBase;
48
+ usingDown?: RawSqlBase;
49
49
  }
50
50
  interface Rename {
51
51
  type: 'rename';
@@ -56,7 +56,7 @@ declare namespace RakeDbAst {
56
56
  column?: Column;
57
57
  type?: string;
58
58
  collate?: string;
59
- default?: unknown | RawSQLBase;
59
+ default?: unknown | RawSqlBase;
60
60
  nullable?: boolean;
61
61
  comment?: string | null;
62
62
  compression?: string;
@@ -176,7 +176,7 @@ declare namespace RakeDbAst {
176
176
  schema?: string;
177
177
  name: string;
178
178
  shape: ColumnsShape;
179
- sql: RawSQLBase;
179
+ sql: RawSqlBase;
180
180
  options: ViewOptions;
181
181
  deps: {
182
182
  schemaName: string;
@@ -223,7 +223,7 @@ declare const tableChangeMethods: {
223
223
  add: typeof add;
224
224
  drop: typeof add;
225
225
  change(from: Column | OneWayChange, to: Column | OneWayChange, using?: ChangeOptions): Change;
226
- default(value: unknown | RawSQLBase): OneWayChange;
226
+ default(value: unknown | RawSqlBase): OneWayChange;
227
227
  nullable(): OneWayChange;
228
228
  nonNullable(): OneWayChange;
229
229
  comment(comment: string | null): OneWayChange;
@@ -266,7 +266,7 @@ declare const tableChangeMethods: {
266
266
  };
267
267
  }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
268
268
  foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
269
- check(check: RawSQLBase<Column.Pick.QueryColumn, unknown>, name?: string | undefined): pqb.NonUniqDataItem;
269
+ check(check: RawSqlBase, name?: string | undefined): pqb.NonUniqDataItem;
270
270
  sql: pqb.SqlFn;
271
271
  enum(name: string): EnumColumn<pqb.DefaultSchemaConfig, undefined, [string, ...string[]]>;
272
272
  };
@@ -905,14 +905,14 @@ declare class Migration<CT> {
905
905
  * @param tableName - name of the table to add the check into
906
906
  * @param check - raw SQL for the check
907
907
  */
908
- addCheck(tableName: string, check: RawSQLBase): Promise<void>;
908
+ addCheck(tableName: string, check: RawSqlBase): Promise<void>;
909
909
  /**
910
910
  * Drop the schema, create it on rollback. See {@link addCheck}.
911
911
  *
912
912
  * @param tableName - name of the table to add the check into
913
913
  * @param check - raw SQL for the check
914
914
  */
915
- dropCheck(tableName: string, check: RawSQLBase): Promise<void>;
915
+ dropCheck(tableName: string, check: RawSqlBase): Promise<void>;
916
916
  /**
917
917
  * Rename a table constraint such as a primary key or a database check.
918
918
  *
@@ -1371,14 +1371,14 @@ declare class Migration<CT> {
1371
1371
  * @param options - view options
1372
1372
  * @param sql - SQL to create the view with
1373
1373
  */
1374
- createView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSQLBase): Promise<void>;
1374
+ createView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1375
1375
  /**
1376
1376
  * See {@link createView}
1377
1377
  *
1378
1378
  * @param name - name of the view
1379
1379
  * @param sql - SQL to create the view with
1380
1380
  */
1381
- createView(name: string, sql: string | RawSQLBase): Promise<void>;
1381
+ createView(name: string, sql: string | RawSqlBase): Promise<void>;
1382
1382
  /**
1383
1383
  * Drop the view, create it on rollback. See {@link createView}.
1384
1384
  *
@@ -1386,14 +1386,14 @@ declare class Migration<CT> {
1386
1386
  * @param options - view options
1387
1387
  * @param sql - SQL to create the view with
1388
1388
  */
1389
- dropView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSQLBase): Promise<void>;
1389
+ dropView(name: string, options: RakeDbAst.ViewOptions, sql: string | RawSqlBase): Promise<void>;
1390
1390
  /**
1391
1391
  * Drop the view, create it on rollback. See {@link createView}.
1392
1392
  *
1393
1393
  * @param name - name of the view
1394
1394
  * @param sql - SQL to create the view with
1395
1395
  */
1396
- dropView(name: string, sql: string | RawSQLBase): Promise<void>;
1396
+ dropView(name: string, sql: string | RawSqlBase): Promise<void>;
1397
1397
  /**
1398
1398
  * Returns boolean to know if table exists:
1399
1399
  *
@@ -1748,7 +1748,7 @@ declare const writeMigrationFile: (config: AnyRakeDbConfig, version: string, nam
1748
1748
  declare const makeFileVersion: (ctx: RakeDbCtx, config: AnyRakeDbConfig) => Promise<string>;
1749
1749
 
1750
1750
  interface OrmParam {
1751
- $qb: QueryBase;
1751
+ $qb: Query;
1752
1752
  }
1753
1753
  type UnknownPromiseFns = (() => Promise<unknown>)[];
1754
1754
  declare const migrateFiles: (db: OrmParam, files: UnknownPromiseFns) => Promise<void>;
package/dist/index.js CHANGED
@@ -975,6 +975,12 @@ const astToQueries = (ast, snakeCase, language) => {
975
975
  }
976
976
  }
977
977
  const prependAlterTable = [];
978
+ if (dropPrimaryKeys.change && addPrimaryKeys.change && dropPrimaryKeys.name === addPrimaryKeys.name && dropPrimaryKeys.columns.length === addPrimaryKeys.columns.length && dropPrimaryKeys.columns.every(
979
+ (column, i) => column === addPrimaryKeys.columns[i]
980
+ )) {
981
+ dropPrimaryKeys.change = addPrimaryKeys.change = void 0;
982
+ dropPrimaryKeys.columns.length = addPrimaryKeys.columns.length = 0;
983
+ }
978
984
  if (ast.drop.primaryKey || dropPrimaryKeys.change || dropPrimaryKeys.columns.length > 1) {
979
985
  const name = dropPrimaryKeys.name || `${ast.name}_pkey`;
980
986
  prependAlterTable.push(`DROP CONSTRAINT "${name}"`);
@@ -4274,7 +4280,7 @@ const makeDomainsMap = (ctx, data) => {
4274
4280
  });
4275
4281
  if (it.checks) {
4276
4282
  column.data.checks = it.checks.map((check) => ({
4277
- sql: new pqb.RawSQL([[check]])
4283
+ sql: new pqb.RawSql([[check]])
4278
4284
  }));
4279
4285
  }
4280
4286
  domains[`${it.schemaName}.${it.name}`] = column;
@@ -4542,7 +4548,7 @@ const dbColumnToAst = (ctx, data, domains, tableName, item, table, tableData, ch
4542
4548
  const columnChecks = checks?.[item.name];
4543
4549
  if (columnChecks) {
4544
4550
  column.data.checks = columnChecks.map((check) => ({
4545
- sql: new pqb.RawSQL([[check]])
4551
+ sql: new pqb.RawSql([[check]])
4546
4552
  }));
4547
4553
  }
4548
4554
  const camelCaseName = pqb.toCamelCase(item.name);
@@ -5149,10 +5155,12 @@ const astEncoders = {
5149
5155
  pqb.addCode(line, ", {");
5150
5156
  const u = [];
5151
5157
  if (change.using.usingUp) {
5152
- u.push(`usingUp: ${change.using.usingUp.toCode("t")},`);
5158
+ u.push(`usingUp: ${pqb.rawSqlToCode(change.using.usingUp, "t")},`);
5153
5159
  }
5154
5160
  if (change.using.usingDown) {
5155
- u.push(`usingDown: ${change.using.usingDown.toCode("t")},`);
5161
+ u.push(
5162
+ `usingDown: ${pqb.rawSqlToCode(change.using.usingDown, "t")},`
5163
+ );
5156
5164
  }
5157
5165
  pqb.addCode(line, u);
5158
5166
  pqb.addCode(line, "}");
@@ -5311,7 +5319,7 @@ const astEncoders = {
5311
5319
  }
5312
5320
  const check = ast.check;
5313
5321
  return [
5314
- `await db.addCheck(${table}, ${check.toCode("t")}${ast.name ? `, ${pqb.singleQuote(ast.name)}` : ""});`
5322
+ `await db.addCheck(${table}, ${pqb.rawSqlToCode(check, "t")}${ast.name ? `, ${pqb.singleQuote(ast.name)}` : ""});`
5315
5323
  ];
5316
5324
  },
5317
5325
  renameTableItem(ast) {
@@ -5353,7 +5361,7 @@ const astEncoders = {
5353
5361
  }
5354
5362
  pqb.addCode(code, pqb.backtickQuote(sql));
5355
5363
  } else {
5356
- pqb.addCode(code, ast.sql.toCode("db"));
5364
+ pqb.addCode(code, pqb.rawSqlToCode(ast.sql, "db"));
5357
5365
  }
5358
5366
  pqb.addCode(code, ");");
5359
5367
  return code;