rake-db 2.31.0 → 2.32.0

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,6 +1,6 @@
1
1
  import * as pqb_internal from 'pqb/internal';
2
- import { SearchWeight, RecordOptionalString, DefaultPrivileges, AdapterBase, TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EnumColumn, EmptyObject, DbResult, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, ColumnSchemaConfig, raw, DefaultColumnTypes, DefaultSchemaConfig, Db, QuerySchema, QueryLogger, MaybePromise, QueryLogOptions, ColumnsByType, DbStructureDomainsMap } from 'pqb/internal';
3
- import * as packages_pqb_src_query from 'packages/pqb/src/query';
2
+ import { SearchWeight, RecordOptionalString, DefaultPrivileges, AdapterBase, TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EmptyObject, EnumColumn, DbResult, QueryLogObject, ColumnSchemaConfig, raw, TableDataFn, TableDataItem, DbDomainArg, DefaultColumnTypes, DefaultSchemaConfig, QueryLogger, QueryLogOptions, MaybePromise, ColumnsByType, DbStructureDomainsMap } from 'pqb/internal';
3
+ import { Db, QuerySchema } from 'pqb';
4
4
 
5
5
  declare namespace DbStructure {
6
6
  interface TableNameAndSchemaName {
@@ -430,7 +430,7 @@ declare namespace RakeDbAst {
430
430
  grant?: DefaultPrivilegeObjectConfig;
431
431
  revoke?: DefaultPrivilegeObjectConfig;
432
432
  }
433
- export { };
433
+ export {};
434
434
  }
435
435
 
436
436
  declare function add(item: Column, options?: {
@@ -487,22 +487,22 @@ declare const tableChangeMethods: {
487
487
  columns: Columns;
488
488
  name: string extends Name ? never : Name;
489
489
  };
490
- unique<Columns_1 extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name_1 extends string>(columns: Columns_1, options?: TableData.Index.UniqueOptionsArg<Name_1> | undefined): {
490
+ unique<Columns extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name extends string>(columns: Columns, options?: TableData.Index.UniqueOptionsArg<Name> | undefined): {
491
491
  tableDataItem: true;
492
- columns: Columns_1 extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns_1]: "column" extends keyof Columns_1[I] ? Columns_1[I][keyof Columns_1[I] & "column"] : Columns_1[I]; } : never;
493
- name: string extends Name_1 ? never : Name_1;
492
+ columns: Columns extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns]: "column" extends keyof Columns[I] ? Columns[I][keyof Columns[I] & "column"] : Columns[I]; } : never;
493
+ name: string extends Name ? never : Name;
494
494
  };
495
- index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg | undefined): pqb_internal.NonUniqDataItem;
496
- searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg | undefined): pqb_internal.NonUniqDataItem;
497
- exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options | undefined): pqb_internal.NonUniqDataItem;
495
+ index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg): pqb_internal.NonUniqDataItem;
496
+ searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg): pqb_internal.NonUniqDataItem;
497
+ exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options): pqb_internal.NonUniqDataItem;
498
498
  foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () => new () => {
499
499
  columns: {
500
500
  shape: Shape;
501
501
  };
502
- }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options | undefined): pqb_internal.NonUniqDataItem;
503
- foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options | undefined): pqb_internal.NonUniqDataItem;
504
- check(check: RawSqlBase, name?: string | undefined): pqb_internal.NonUniqDataItem;
505
- sql: packages_pqb_src_query.SqlFn;
502
+ }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
503
+ foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
504
+ check(check: RawSqlBase, name?: string): pqb_internal.NonUniqDataItem;
505
+ sql: pqb_internal.SqlFn;
506
506
  enum(name: string): EnumColumn<pqb_internal.DefaultSchemaConfig, undefined, [string, ...string[]]>;
507
507
  };
508
508
  type TableChanger<CT> = MigrationColumnTypes<CT> & TableChangeMethods;
@@ -574,7 +574,7 @@ interface MigrationInterfaceResult {
574
574
  * @param up - migrate or rollback
575
575
  * @param config - config of `rakeDb`
576
576
  */
577
- declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, 'log' | 'logger'>) => MigrationInterfaceResult;
577
+ declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, "log" | "logger">) => MigrationInterfaceResult;
578
578
  type MigrationAdapter = AdapterBase;
579
579
  declare class Migration<CT = unknown> {
580
580
  adapter: MigrationAdapter;
@@ -1531,7 +1531,7 @@ interface OrmParam {
1531
1531
  }
1532
1532
  type DbParam = OrmParam | AdapterBase;
1533
1533
 
1534
- declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, 'migrationsTable'>) => Promise<void>;
1534
+ declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<void>;
1535
1535
  declare const createMigrationsSchemaAndTable: (db: DbParam, config: {
1536
1536
  migrationsTable: string;
1537
1537
  logger?: QueryLogger;
@@ -1556,6 +1556,10 @@ interface MigrateConfigBase extends QueryLogOptions {
1556
1556
  afterMigrate?: MigrationCallback;
1557
1557
  beforeRollback?: MigrationCallback;
1558
1558
  afterRollback?: MigrationCallback;
1559
+ snakeCase?: boolean;
1560
+ language?: string;
1561
+ noPrimaryKey?: NoPrimaryKeyOption;
1562
+ baseTable?: RakeDbBaseTable<unknown>;
1559
1563
  }
1560
1564
  interface MigrateConfigFileBased extends MigrateConfigBase {
1561
1565
  basePath?: string;
@@ -1916,11 +1920,11 @@ interface StructureToAstTableData {
1916
1920
  constraints: DbStructure.Constraint[];
1917
1921
  roles?: DbStructure.Role[];
1918
1922
  }
1919
- declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, 'snakeCase' | 'schemaConfig'>, currentSchema: string) => StructureToAstCtx;
1920
- declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, 'migrationsTable'>) => Promise<RakeDbAst[]>;
1923
+ declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, "snakeCase" | "schemaConfig">, currentSchema: string) => StructureToAstCtx;
1924
+ declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<RakeDbAst[]>;
1921
1925
  declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
1922
1926
  declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column<pqb_internal.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
1923
- declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
1927
+ declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: "create" | "drop", domains: DbStructureDomainsMap) => RakeDbAst.Table;
1924
1928
  declare const getDbStructureTableData: (data: IntrospectedStructure, { name, schemaName }: DbStructure.Table) => StructureToAstTableData;
1925
1929
  interface ColumnChecks {
1926
1930
  [K: string]: string[];
@@ -1986,7 +1990,7 @@ declare const dropDatabase: (db: DbParam, { database }: {
1986
1990
  * const result: 'done' | 'already' = await createSchema(db, '"schema"');
1987
1991
  * ```
1988
1992
  */
1989
- declare const createSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1993
+ declare const createSchema: (db: DbParam, sql: string) => Promise<"done" | "already">;
1990
1994
  /**
1991
1995
  * `dropSchema` uses a savepoint when it is called in a transaction to not break it if the schema does not exist.
1992
1996
  *
@@ -1998,7 +2002,7 @@ declare const createSchema: (db: DbParam, sql: string) => Promise<'done' | 'alre
1998
2002
  * const result: 'done' | 'already' = await dropSchema(db, '"schema"');
1999
2003
  * ```
2000
2004
  */
2001
- declare const dropSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2005
+ declare const dropSchema: (db: DbParam, sql: string) => Promise<"done" | "already">;
2002
2006
  /**
2003
2007
  * `createTable` uses a savepoint when it is called in a transaction to not break it if the table already exists.
2004
2008
  *
@@ -2010,7 +2014,7 @@ declare const dropSchema: (db: DbParam, sql: string) => Promise<'done' | 'alread
2010
2014
  * const result: 'done' | 'already' = await createTable(db, '"table"');
2011
2015
  * ```
2012
2016
  */
2013
- declare const createTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2017
+ declare const createTable: (db: DbParam, sql: string) => Promise<"done" | "already">;
2014
2018
  /**
2015
2019
  * `dropTable` uses a savepoint when it is called in a transaction to not break it if the table does not exist.
2016
2020
  *
@@ -2022,9 +2026,10 @@ declare const createTable: (db: DbParam, sql: string) => Promise<'done' | 'alrea
2022
2026
  * const result: 'done' | 'already' = await dropTable(db, '"table"');
2023
2027
  * ```
2024
2028
  */
2025
- declare const dropTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2029
+ declare const dropTable: (db: DbParam, sql: string) => Promise<"done" | "already">;
2026
2030
 
2027
2031
  declare class RakeDbError extends Error {
2028
2032
  }
2029
2033
 
2030
- export { type ChangeCallback$1 as ChangeCallback, type DbMigration, DbStructure, type IntrospectedStructure, type MigrateConfig, type MigrateFn, type MigrationChangeFn, RakeDbAst, type RakeDbChangeFnConfig, type RakeDbCliConfigInput, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
2034
+ export { DbStructure, RakeDbAst, RakeDbError, astToMigration, concatSchemaAndName, createDatabase, createMigrationChangeFn, createMigrationInterface, createMigrationsSchemaAndTable, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getDbVersion, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, rakeDbConfigDefaults, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
2035
+ export type { ChangeCallback$1 as ChangeCallback, DbMigration, IntrospectedStructure, MigrateConfig, MigrateFn, MigrationChangeFn, RakeDbChangeFnConfig, RakeDbCliConfigInput, RakeDbCliResult, RakeDbConfig, RakeDbFn, SilentQueries, StructureToAstCtx, StructureToAstTableData };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var internal = require('pqb/internal');
4
4
  var path = require('path');
5
5
  var node_url = require('node:url');
6
+ var pqb = require('pqb');
6
7
  var fs = require('fs/promises');
7
8
  var path$1 = require('node:path');
8
9
 
@@ -160,7 +161,6 @@ const columnToSql = (schema, name, item, values, hasMultiplePrimaryKeys, snakeCa
160
161
  referencesToSql(
161
162
  schema,
162
163
  {
163
- columns: [name],
164
164
  ...foreignKey
165
165
  },
166
166
  snakeCase
@@ -1390,7 +1390,7 @@ const pushIndexesOrExcludes = (key, from, to, name, add2, drop2) => {
1390
1390
  };
1391
1391
  const getChangeColumnName = (what, change, key, snakeCase) => {
1392
1392
  return change.name || (change[what].column ? (
1393
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1393
+ //
1394
1394
  getColumnName(change[what].column, key, snakeCase)
1395
1395
  ) : snakeCase ? internal.toSnakeCase(key) : key);
1396
1396
  };
@@ -1751,7 +1751,7 @@ const createMigrationInterface = (tx, up, config) => {
1751
1751
  getDb(columnTypes) {
1752
1752
  let db = dbPerColumnTypes.get(columnTypes);
1753
1753
  if (!db) {
1754
- db = internal.createDbWithAdapter({
1754
+ db = pqb.createDbWithAdapter({
1755
1755
  adapter,
1756
1756
  columnTypes
1757
1757
  });
@@ -2282,7 +2282,6 @@ class Migration {
2282
2282
  enumName
2283
2283
  );
2284
2284
  const ast = {
2285
- type: "renameEnumValues",
2286
2285
  schema,
2287
2286
  name,
2288
2287
  values
@@ -2698,10 +2697,7 @@ const addCheck = (migration, up, tableName, check) => {
2698
2697
  };
2699
2698
  const createSchema$1 = async (migration, up, name) => {
2700
2699
  const ast = {
2701
- type: "schema",
2702
- action: up ? "create" : "drop",
2703
- name
2704
- };
2700
+ action: up ? "create" : "drop"};
2705
2701
  await migration.adapter.query(
2706
2702
  `${ast.action === "create" ? "CREATE" : "DROP"} SCHEMA "${name}"`
2707
2703
  );
@@ -2712,7 +2708,6 @@ const createExtension = async (migration, up, fullName, options) => {
2712
2708
  fullName
2713
2709
  );
2714
2710
  const ast = {
2715
- type: "extension",
2716
2711
  action: up ? "create" : "drop",
2717
2712
  schema,
2718
2713
  name,
@@ -2732,11 +2727,9 @@ const createEnum = async (migration, up, name, values, options = {}) => {
2732
2727
  name
2733
2728
  );
2734
2729
  const ast = {
2735
- type: "enum",
2736
2730
  action: up ? "create" : "drop",
2737
2731
  schema,
2738
2732
  name: enumName,
2739
- values,
2740
2733
  ...options
2741
2734
  };
2742
2735
  let query;
@@ -2754,7 +2747,6 @@ const createDomain = async (migration, up, name, fn) => {
2754
2747
  name
2755
2748
  );
2756
2749
  const ast = {
2757
- type: "domain",
2758
2750
  action: up ? "create" : "drop",
2759
2751
  schema,
2760
2752
  name: domainName,
@@ -2787,7 +2779,6 @@ const createCollation = async (migration, up, name, options) => {
2787
2779
  name
2788
2780
  );
2789
2781
  const ast = {
2790
- type: "collation",
2791
2782
  action: up ? "create" : "drop",
2792
2783
  schema,
2793
2784
  name: collationName,
@@ -2833,7 +2824,6 @@ const renameType = async (migration, from, to, kind) => {
2833
2824
  migration.up ? to : from
2834
2825
  );
2835
2826
  const ast = {
2836
- type: "renameType",
2837
2827
  kind,
2838
2828
  fromSchema,
2839
2829
  from: f,
@@ -2872,7 +2862,6 @@ const addOrDropEnumValues = async (migration, up, enumName, values, options) =>
2872
2862
  );
2873
2863
  const quotedName = quoteTable(schema, name);
2874
2864
  const ast = {
2875
- type: "enumValues",
2876
2865
  action: up ? "add" : "drop",
2877
2866
  schema,
2878
2867
  name,
@@ -2915,10 +2904,8 @@ const changeEnumValues = async (migration, enumName, fromValues, toValues) => {
2915
2904
  toValues = values;
2916
2905
  }
2917
2906
  const ast = {
2918
- type: "changeEnumValues",
2919
2907
  schema,
2920
2908
  name,
2921
- fromValues,
2922
2909
  toValues
2923
2910
  };
2924
2911
  await recreateEnum(
@@ -3543,12 +3530,18 @@ const processMigrateConfig = (config) => {
3543
3530
  migrationsPath = path$1.resolve(config.basePath, migrationsPath);
3544
3531
  }
3545
3532
  }
3546
- return {
3533
+ const result = {
3547
3534
  ...migrateConfigDefaults,
3548
3535
  ...config,
3549
3536
  migrationsPath,
3550
3537
  logger: handleConfigLogger(config)
3551
3538
  };
3539
+ if ("baseTable" in config && config.baseTable) {
3540
+ const { snakeCase, language } = config.baseTable.prototype;
3541
+ if (snakeCase) result.snakeCase = true;
3542
+ if (language) result.language = language;
3543
+ }
3544
+ return result;
3552
3545
  };
3553
3546
  const transactionIfSingle = (adapter, config, fn) => {
3554
3547
  return config.transaction === "single" ? transaction(adapter, config, fn) : fn(adapter);
@@ -3669,7 +3662,7 @@ const redo = makeMigrateFn(
3669
3662
  );
3670
3663
  }
3671
3664
  );
3672
- const getDb = (adapter) => internal.createDbWithAdapter({ adapter });
3665
+ const getDb = (adapter) => pqb.createDbWithAdapter({ adapter });
3673
3666
  const migrateOrRollback = async (trx, config, set, versions, count, up, redo2, force, skipLock) => {
3674
3667
  const { sequence, map: versionsMap } = versions;
3675
3668
  if (up) {
@@ -4024,7 +4017,7 @@ const runRecurrentMigrations = async (adapters, config) => {
4024
4017
  let files = 0;
4025
4018
  await readdirRecursive(config.recurrentPath, async (path) => {
4026
4019
  files++;
4027
- dbs ?? (dbs = adapters.map((adapter) => internal.createDbWithAdapter({ adapter })));
4020
+ dbs ?? (dbs = adapters.map((adapter) => pqb.createDbWithAdapter({ adapter })));
4028
4021
  const sql = await fs.readFile(path, "utf-8");
4029
4022
  await Promise.all(
4030
4023
  dbs.map(async (db) => {
@@ -6574,10 +6567,8 @@ const makeRakeDbConfig = (config, args) => {
6574
6567
  result.recurrentPath = path.resolve(result.basePath, result.recurrentPath);
6575
6568
  }
6576
6569
  if ("baseTable" in config && config.baseTable) {
6577
- const { types, snakeCase, language } = config.baseTable.prototype;
6570
+ const { types } = config.baseTable.prototype;
6578
6571
  result.columnTypes = types || internal.makeColumnTypes(internal.defaultSchemaConfig);
6579
- if (snakeCase) result.snakeCase = true;
6580
- if (language) result.language = language;
6581
6572
  } else {
6582
6573
  const ct = "columnTypes" in config && config.columnTypes;
6583
6574
  result.columnTypes = (typeof ct === "function" ? ct(