rake-db 2.31.0 → 2.31.1

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,5 @@
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, Db, QuerySchema, QueryLogger, QueryLogOptions, MaybePromise, ColumnsByType, DbStructureDomainsMap } from 'pqb/internal';
4
3
 
5
4
  declare namespace DbStructure {
6
5
  interface TableNameAndSchemaName {
@@ -430,7 +429,7 @@ declare namespace RakeDbAst {
430
429
  grant?: DefaultPrivilegeObjectConfig;
431
430
  revoke?: DefaultPrivilegeObjectConfig;
432
431
  }
433
- export { };
432
+ export {};
434
433
  }
435
434
 
436
435
  declare function add(item: Column, options?: {
@@ -487,22 +486,22 @@ declare const tableChangeMethods: {
487
486
  columns: Columns;
488
487
  name: string extends Name ? never : Name;
489
488
  };
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): {
489
+ 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
490
  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;
491
+ 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;
492
+ name: string extends Name ? never : Name;
494
493
  };
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;
494
+ index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg): pqb_internal.NonUniqDataItem;
495
+ searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg): pqb_internal.NonUniqDataItem;
496
+ exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options): pqb_internal.NonUniqDataItem;
498
497
  foreignKey<Shape>(columns: [string, ...string[]], fnOrTable: () => new () => {
499
498
  columns: {
500
499
  shape: Shape;
501
500
  };
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;
501
+ }, foreignColumns: [keyof Shape, ...(keyof Shape)[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
502
+ foreignKey(columns: [string, ...string[]], fnOrTable: string, foreignColumns: [string, ...string[]], options?: TableData.References.Options): pqb_internal.NonUniqDataItem;
503
+ check(check: RawSqlBase, name?: string): pqb_internal.NonUniqDataItem;
504
+ sql: pqb_internal.SqlFn;
506
505
  enum(name: string): EnumColumn<pqb_internal.DefaultSchemaConfig, undefined, [string, ...string[]]>;
507
506
  };
508
507
  type TableChanger<CT> = MigrationColumnTypes<CT> & TableChangeMethods;
@@ -574,7 +573,7 @@ interface MigrationInterfaceResult {
574
573
  * @param up - migrate or rollback
575
574
  * @param config - config of `rakeDb`
576
575
  */
577
- declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, 'log' | 'logger'>) => MigrationInterfaceResult;
576
+ declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, "log" | "logger">) => MigrationInterfaceResult;
578
577
  type MigrationAdapter = AdapterBase;
579
578
  declare class Migration<CT = unknown> {
580
579
  adapter: MigrationAdapter;
@@ -1531,7 +1530,7 @@ interface OrmParam {
1531
1530
  }
1532
1531
  type DbParam = OrmParam | AdapterBase;
1533
1532
 
1534
- declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, 'migrationsTable'>) => Promise<void>;
1533
+ declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<void>;
1535
1534
  declare const createMigrationsSchemaAndTable: (db: DbParam, config: {
1536
1535
  migrationsTable: string;
1537
1536
  logger?: QueryLogger;
@@ -1916,11 +1915,11 @@ interface StructureToAstTableData {
1916
1915
  constraints: DbStructure.Constraint[];
1917
1916
  roles?: DbStructure.Role[];
1918
1917
  }
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[]>;
1918
+ declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, "snakeCase" | "schemaConfig">, currentSchema: string) => StructureToAstCtx;
1919
+ declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, "migrationsTable">) => Promise<RakeDbAst[]>;
1921
1920
  declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
1922
1921
  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;
1922
+ declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: "create" | "drop", domains: DbStructureDomainsMap) => RakeDbAst.Table;
1924
1923
  declare const getDbStructureTableData: (data: IntrospectedStructure, { name, schemaName }: DbStructure.Table) => StructureToAstTableData;
1925
1924
  interface ColumnChecks {
1926
1925
  [K: string]: string[];
@@ -1986,7 +1985,7 @@ declare const dropDatabase: (db: DbParam, { database }: {
1986
1985
  * const result: 'done' | 'already' = await createSchema(db, '"schema"');
1987
1986
  * ```
1988
1987
  */
1989
- declare const createSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1988
+ declare const createSchema: (db: DbParam, sql: string) => Promise<"done" | "already">;
1990
1989
  /**
1991
1990
  * `dropSchema` uses a savepoint when it is called in a transaction to not break it if the schema does not exist.
1992
1991
  *
@@ -1998,7 +1997,7 @@ declare const createSchema: (db: DbParam, sql: string) => Promise<'done' | 'alre
1998
1997
  * const result: 'done' | 'already' = await dropSchema(db, '"schema"');
1999
1998
  * ```
2000
1999
  */
2001
- declare const dropSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2000
+ declare const dropSchema: (db: DbParam, sql: string) => Promise<"done" | "already">;
2002
2001
  /**
2003
2002
  * `createTable` uses a savepoint when it is called in a transaction to not break it if the table already exists.
2004
2003
  *
@@ -2010,7 +2009,7 @@ declare const dropSchema: (db: DbParam, sql: string) => Promise<'done' | 'alread
2010
2009
  * const result: 'done' | 'already' = await createTable(db, '"table"');
2011
2010
  * ```
2012
2011
  */
2013
- declare const createTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2012
+ declare const createTable: (db: DbParam, sql: string) => Promise<"done" | "already">;
2014
2013
  /**
2015
2014
  * `dropTable` uses a savepoint when it is called in a transaction to not break it if the table does not exist.
2016
2015
  *
@@ -2022,9 +2021,10 @@ declare const createTable: (db: DbParam, sql: string) => Promise<'done' | 'alrea
2022
2021
  * const result: 'done' | 'already' = await dropTable(db, '"table"');
2023
2022
  * ```
2024
2023
  */
2025
- declare const dropTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
2024
+ declare const dropTable: (db: DbParam, sql: string) => Promise<"done" | "already">;
2026
2025
 
2027
2026
  declare class RakeDbError extends Error {
2028
2027
  }
2029
2028
 
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 };
2029
+ 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 };
2030
+ 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
@@ -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(
@@ -3669,7 +3656,7 @@ const redo = makeMigrateFn(
3669
3656
  );
3670
3657
  }
3671
3658
  );
3672
- const getDb = (adapter) => internal.createDbWithAdapter({ adapter });
3659
+ const getDb = (adapter) => pqb.createDbWithAdapter({ adapter });
3673
3660
  const migrateOrRollback = async (trx, config, set, versions, count, up, redo2, force, skipLock) => {
3674
3661
  const { sequence, map: versionsMap } = versions;
3675
3662
  if (up) {
@@ -4024,7 +4011,7 @@ const runRecurrentMigrations = async (adapters, config) => {
4024
4011
  let files = 0;
4025
4012
  await readdirRecursive(config.recurrentPath, async (path) => {
4026
4013
  files++;
4027
- dbs ?? (dbs = adapters.map((adapter) => internal.createDbWithAdapter({ adapter })));
4014
+ dbs ?? (dbs = adapters.map((adapter) => pqb.createDbWithAdapter({ adapter })));
4028
4015
  const sql = await fs.readFile(path, "utf-8");
4029
4016
  await Promise.all(
4030
4017
  dbs.map(async (db) => {