rake-db 2.4.0 → 2.4.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.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import * as pqb from 'pqb';
2
- import { ColumnType, EnumColumn, ColumnTypes, ColumnsShape, DbResult, DefaultColumnTypes, TransactionAdapter, AdapterOptions, TextColumn, IndexColumnOptions, IndexOptions, ForeignKeyOptions, QueryLogObject, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions } from 'pqb';
3
- import * as orchid_core from 'orchid-core';
4
- import { EmptyObject, RawExpression, raw, MaybeArray } from 'orchid-core';
1
+ import { ColumnType, EnumColumn, ColumnTypes, ColumnsShape, DbResult, DefaultColumnTypes, TransactionAdapter, AdapterOptions, QueryLogObject, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions } from 'pqb';
2
+ import { EmptyObject, RawExpression, ColumnTypesBase, raw, MaybeArray } from 'orchid-core';
5
3
 
6
- declare function add(item: ColumnType, options?: {
4
+ declare function add(this: ColumnTypesBase, item: ColumnType, options?: {
7
5
  dropMode?: DropMode;
8
6
  }): RakeDbAst.ChangeTableItem.Column;
9
- declare function add(emptyObject: EmptyObject): EmptyObject;
10
- declare function add(items: Record<string, ColumnType>, options?: {
7
+ declare function add(this: ColumnTypesBase, emptyObject: EmptyObject): EmptyObject;
8
+ declare function add(this: ColumnTypesBase, items: Record<string, ColumnType>, options?: {
11
9
  dropMode?: DropMode;
12
10
  }): Record<string, RakeDbAst.ChangeTableItem.Column>;
13
11
  declare type Change = RakeDbAst.ChangeTableItem.Change & ChangeOptions;
@@ -19,13 +17,13 @@ declare type TableChangeMethods = typeof tableChangeMethods;
19
17
  declare const tableChangeMethods: {
20
18
  add: typeof add;
21
19
  drop: typeof add;
22
- change(from: ColumnType | Change, to: ColumnType | Change, options?: ChangeOptions): Change;
20
+ change(this: ColumnTypesBase, from: ColumnType | Change, to: ColumnType | Change, options?: ChangeOptions): Change;
23
21
  default(value: unknown | RawExpression): Change;
24
22
  nullable(): Change;
25
23
  nonNullable(): Change;
26
24
  comment(comment: string | null): Change;
27
25
  rename(name: string): RakeDbAst.ChangeTableItem.Rename;
28
- enum(this: orchid_core.ColumnTypesBase, name: string): EnumColumn<string, [string, ...string[]]>;
26
+ enum(this: ColumnTypesBase, name: string): EnumColumn<string, [string, ...string[]]>;
29
27
  };
30
28
  declare type TableChanger = MigrationColumnTypes & TableChangeMethods;
31
29
  declare type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | EmptyObject>;
@@ -53,312 +51,8 @@ declare type ColumnComment = {
53
51
  column: string;
54
52
  comment: string | null;
55
53
  };
56
- declare type JoinTableOptions = {
57
- tableName?: string;
58
- comment?: string;
59
- dropMode?: DropMode;
60
- };
61
54
  declare type Migration = DbResult<DefaultColumnTypes> & MigrationBase;
62
- declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, options: RakeDbConfig, adapterOptions: AdapterOptions, appCodeUpdaterCache: object) => pqb.Db<string, Record<string, never>, pqb.RelationsBase, {
63
- name: typeof orchid_core.name;
64
- raw: (sql: string, values?: false | Record<string, unknown> | undefined) => orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>;
65
- smallint(this: orchid_core.ColumnTypesBase): pqb.SmallIntColumn;
66
- integer(this: orchid_core.ColumnTypesBase): pqb.IntegerColumn;
67
- bigint(this: orchid_core.ColumnTypesBase): pqb.BigIntColumn;
68
- numeric<Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision | undefined, scale?: Scale | undefined): pqb.DecimalColumn<Precision, Scale>;
69
- decimal<Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_1 | undefined, scale?: Scale_1 | undefined): pqb.DecimalColumn<Precision_1, Scale_1>;
70
- real(this: orchid_core.ColumnTypesBase): pqb.RealColumn;
71
- doublePrecision(this: orchid_core.ColumnTypesBase): pqb.DoublePrecisionColumn;
72
- smallSerial(this: orchid_core.ColumnTypesBase): pqb.SmallSerialColumn;
73
- serial(this: orchid_core.ColumnTypesBase): pqb.SerialColumn;
74
- bigSerial(this: orchid_core.ColumnTypesBase): pqb.BigSerialColumn;
75
- money(this: orchid_core.ColumnTypesBase): pqb.MoneyColumn;
76
- varchar<Limit extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit | undefined): pqb.VarCharColumn<Limit>;
77
- char<Limit_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit_1 | undefined): pqb.CharColumn<Limit_1>;
78
- text: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
79
- string: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
80
- bytea(this: orchid_core.ColumnTypesBase): pqb.ByteaColumn;
81
- date(this: orchid_core.ColumnTypesBase): pqb.DateColumn;
82
- timestamp<Precision_2 extends number>(this: orchid_core.ColumnTypesBase, precision?: Precision_2 | undefined): pqb.TimestampColumn<Precision_2>;
83
- timestampWithTimeZone<Precision_3 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_3 | undefined): pqb.TimestampWithTimeZoneColumn<number>;
84
- time<Precision_4 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_4 | undefined): pqb.TimeColumn<Precision_4>;
85
- timeWithTimeZone<Precision_5 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_5 | undefined): pqb.TimeWithTimeZoneColumn<Precision_5>;
86
- interval<Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, fields?: Fields | undefined, precision?: Precision_6 | undefined): pqb.IntervalColumn<Fields, Precision_6>;
87
- boolean(this: orchid_core.ColumnTypesBase): pqb.BooleanColumn;
88
- enum<U extends string, T extends [U, ...U[]]>(this: orchid_core.ColumnTypesBase, dataType: string, type: T): EnumColumn<U, T>;
89
- point(this: orchid_core.ColumnTypesBase): pqb.PointColumn;
90
- line(this: orchid_core.ColumnTypesBase): pqb.LineColumn;
91
- lseg(this: orchid_core.ColumnTypesBase): pqb.LsegColumn;
92
- box(this: orchid_core.ColumnTypesBase): pqb.BoxColumn;
93
- path(this: orchid_core.ColumnTypesBase): pqb.PathColumn;
94
- polygon(this: orchid_core.ColumnTypesBase): pqb.PolygonColumn;
95
- circle(this: orchid_core.ColumnTypesBase): pqb.CircleColumn;
96
- cidr(this: orchid_core.ColumnTypesBase): pqb.CidrColumn;
97
- inet(this: orchid_core.ColumnTypesBase): pqb.InetColumn;
98
- macaddr(this: orchid_core.ColumnTypesBase): pqb.MacAddrColumn;
99
- macaddr8(this: orchid_core.ColumnTypesBase): pqb.MacAddr8Column;
100
- bit<Length extends number>(this: orchid_core.ColumnTypesBase, length: Length): pqb.BitColumn<Length>;
101
- bitVarying<Length_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, length?: Length_1 | undefined): pqb.BitVaryingColumn<Length_1>;
102
- tsvector(this: orchid_core.ColumnTypesBase): pqb.TsVectorColumn;
103
- tsquery(this: orchid_core.ColumnTypesBase): pqb.TsQueryColumn;
104
- uuid(this: orchid_core.ColumnTypesBase): pqb.UUIDColumn;
105
- xml(this: orchid_core.ColumnTypesBase): pqb.XMLColumn;
106
- json<Type extends orchid_core.JSONTypeAny>(this: orchid_core.ColumnTypesBase, schemaOrFn: Type | ((j: {
107
- set: <Value extends orchid_core.JSONTypeAny>(valueType: Value) => orchid_core.JSONSet<Value>;
108
- tuple: <T_1 extends [] | orchid_core.JSONTupleItems, Rest extends orchid_core.JSONTypeAny | null = null>(items: T_1, rest?: Rest) => orchid_core.JSONTuple<T_1, Rest>;
109
- union: <T_2 extends [orchid_core.JSONTypeAny, orchid_core.JSONTypeAny, ...orchid_core.JSONTypeAny[]]>(types: T_2) => orchid_core.JSONUnion<T_2>;
110
- any: () => orchid_core.JSONAny;
111
- bigint: () => orchid_core.JSONBigInt;
112
- boolean: () => orchid_core.JSONBoolean;
113
- date: () => orchid_core.JSONDate;
114
- nan: () => orchid_core.JSONNaN;
115
- never: () => orchid_core.JSONNever;
116
- null: () => orchid_core.JSONNull;
117
- number: () => orchid_core.JSONNumber;
118
- string: () => orchid_core.JSONString;
119
- undefined: () => orchid_core.JSONUndefined;
120
- unknown: () => orchid_core.JSONUnknown;
121
- void: () => orchid_core.JSONVoid;
122
- array: <Type_1 extends orchid_core.JSONTypeAny>(element: Type_1) => orchid_core.JSONArray<Type_1, "many">;
123
- discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends orchid_core.Primitive, Types extends [orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => orchid_core.JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
124
- enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => orchid_core.JSONEnum<U_1, T_3>;
125
- instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => orchid_core.JSONInstanceOf<T_4>;
126
- intersection: <Left extends orchid_core.JSONTypeAny, Right extends orchid_core.JSONTypeAny>(left: Left, right: Right) => orchid_core.JSONIntersection<Left, Right>;
127
- lazy: <T_5 extends orchid_core.JSONTypeAny>(fn: () => T_5) => orchid_core.JSONLazy<T_5>;
128
- literal: <T_6 extends orchid_core.Primitive>(value: T_6) => orchid_core.JSONLiteral<T_6>;
129
- map: <Key extends orchid_core.JSONTypeAny, Value_1 extends orchid_core.JSONTypeAny>(keyType: Key, valueType: Value_1) => orchid_core.JSONMap<Key, Value_1>;
130
- nativeEnum: <T_7 extends orchid_core.EnumLike>(givenEnum: T_7) => orchid_core.JSONNativeEnum<T_7>;
131
- nullable: <T_8 extends orchid_core.JSONTypeAny>(type: T_8) => orchid_core.JSONNullable<T_8>;
132
- nullish: <T_9 extends orchid_core.JSONTypeAny>(type: T_9) => orchid_core.JSONNullish<T_9>;
133
- object: <T_10 extends orchid_core.JSONObjectShape, UnknownKeys extends orchid_core.UnknownKeysParam = "strip", Catchall extends orchid_core.JSONTypeAny = orchid_core.JSONTypeAny>(shape: T_10) => orchid_core.JSONObject<T_10, UnknownKeys, Catchall, orchid_core.JSONTypeAny extends Catchall ? orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
134
- [k: string]: Catchall["type"];
135
- } extends infer T_12 extends object ? { [k_2 in keyof T_12]: ((orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
136
- [k: string]: Catchall["type"];
137
- })[k_2]; } : never>;
138
- optional: <T_13 extends orchid_core.JSONTypeAny>(type: T_13) => orchid_core.JSONOptional<T_13>;
139
- record: typeof orchid_core.record;
140
- }) => Type)): pqb.JSONColumn<Type>;
141
- jsonText(this: orchid_core.ColumnTypesBase): pqb.JSONTextColumn;
142
- array<Item extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: orchid_core.ColumnTypesBase, item: Item): pqb.ArrayColumn<Item>;
143
- timestamps: <T_14 extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: {
144
- timestamp(): T_14;
145
- }) => {
146
- createdAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
147
- updatedAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
148
- };
149
- primaryKey(columns: string[], options?: {
150
- name?: string | undefined;
151
- } | undefined): {};
152
- index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
153
- unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
154
- foreignKey: {
155
- <Table extends pqb.ForeignKeyTableWithColumns, Columns extends [Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Table, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
156
- <Table_1 extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table_1, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
157
- };
158
- }> & {
159
- <Table_2 extends string, Shape extends ColumnsShape = ColumnsShape>(table: Table_2, shape?: Shape | ((t: {
160
- name: typeof orchid_core.name;
161
- raw: (sql: string, values?: false | Record<string, unknown> | undefined) => orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>;
162
- smallint(this: orchid_core.ColumnTypesBase): pqb.SmallIntColumn;
163
- integer(this: orchid_core.ColumnTypesBase): pqb.IntegerColumn;
164
- bigint(this: orchid_core.ColumnTypesBase): pqb.BigIntColumn;
165
- numeric<Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision | undefined, scale?: Scale | undefined): pqb.DecimalColumn<Precision, Scale>;
166
- decimal<Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_1 | undefined, scale?: Scale_1 | undefined): pqb.DecimalColumn<Precision_1, Scale_1>;
167
- real(this: orchid_core.ColumnTypesBase): pqb.RealColumn;
168
- doublePrecision(this: orchid_core.ColumnTypesBase): pqb.DoublePrecisionColumn;
169
- smallSerial(this: orchid_core.ColumnTypesBase): pqb.SmallSerialColumn;
170
- serial(this: orchid_core.ColumnTypesBase): pqb.SerialColumn;
171
- bigSerial(this: orchid_core.ColumnTypesBase): pqb.BigSerialColumn;
172
- money(this: orchid_core.ColumnTypesBase): pqb.MoneyColumn;
173
- varchar<Limit extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit | undefined): pqb.VarCharColumn<Limit>;
174
- char<Limit_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit_1 | undefined): pqb.CharColumn<Limit_1>;
175
- text: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
176
- string: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
177
- bytea(this: orchid_core.ColumnTypesBase): pqb.ByteaColumn;
178
- date(this: orchid_core.ColumnTypesBase): pqb.DateColumn;
179
- timestamp<Precision_2 extends number>(this: orchid_core.ColumnTypesBase, precision?: Precision_2 | undefined): pqb.TimestampColumn<Precision_2>;
180
- timestampWithTimeZone<Precision_3 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_3 | undefined): pqb.TimestampWithTimeZoneColumn<number>;
181
- time<Precision_4 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_4 | undefined): pqb.TimeColumn<Precision_4>;
182
- timeWithTimeZone<Precision_5 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_5 | undefined): pqb.TimeWithTimeZoneColumn<Precision_5>;
183
- interval<Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, fields?: Fields | undefined, precision?: Precision_6 | undefined): pqb.IntervalColumn<Fields, Precision_6>;
184
- boolean(this: orchid_core.ColumnTypesBase): pqb.BooleanColumn;
185
- enum<U extends string, T extends [U, ...U[]]>(this: orchid_core.ColumnTypesBase, dataType: string, type: T): EnumColumn<U, T>;
186
- point(this: orchid_core.ColumnTypesBase): pqb.PointColumn;
187
- line(this: orchid_core.ColumnTypesBase): pqb.LineColumn;
188
- lseg(this: orchid_core.ColumnTypesBase): pqb.LsegColumn;
189
- box(this: orchid_core.ColumnTypesBase): pqb.BoxColumn;
190
- path(this: orchid_core.ColumnTypesBase): pqb.PathColumn;
191
- polygon(this: orchid_core.ColumnTypesBase): pqb.PolygonColumn;
192
- circle(this: orchid_core.ColumnTypesBase): pqb.CircleColumn;
193
- cidr(this: orchid_core.ColumnTypesBase): pqb.CidrColumn;
194
- inet(this: orchid_core.ColumnTypesBase): pqb.InetColumn;
195
- macaddr(this: orchid_core.ColumnTypesBase): pqb.MacAddrColumn;
196
- macaddr8(this: orchid_core.ColumnTypesBase): pqb.MacAddr8Column;
197
- bit<Length extends number>(this: orchid_core.ColumnTypesBase, length: Length): pqb.BitColumn<Length>;
198
- bitVarying<Length_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, length?: Length_1 | undefined): pqb.BitVaryingColumn<Length_1>;
199
- tsvector(this: orchid_core.ColumnTypesBase): pqb.TsVectorColumn;
200
- tsquery(this: orchid_core.ColumnTypesBase): pqb.TsQueryColumn;
201
- uuid(this: orchid_core.ColumnTypesBase): pqb.UUIDColumn;
202
- xml(this: orchid_core.ColumnTypesBase): pqb.XMLColumn;
203
- json<Type extends orchid_core.JSONTypeAny>(this: orchid_core.ColumnTypesBase, schemaOrFn: Type | ((j: {
204
- set: <Value extends orchid_core.JSONTypeAny>(valueType: Value) => orchid_core.JSONSet<Value>;
205
- tuple: <T_1 extends [] | orchid_core.JSONTupleItems, Rest extends orchid_core.JSONTypeAny | null = null>(items: T_1, rest?: Rest) => orchid_core.JSONTuple<T_1, Rest>;
206
- union: <T_2 extends [orchid_core.JSONTypeAny, orchid_core.JSONTypeAny, ...orchid_core.JSONTypeAny[]]>(types: T_2) => orchid_core.JSONUnion<T_2>;
207
- any: () => orchid_core.JSONAny;
208
- bigint: () => orchid_core.JSONBigInt;
209
- boolean: () => orchid_core.JSONBoolean;
210
- date: () => orchid_core.JSONDate;
211
- nan: () => orchid_core.JSONNaN;
212
- never: () => orchid_core.JSONNever;
213
- null: () => orchid_core.JSONNull;
214
- number: () => orchid_core.JSONNumber;
215
- string: () => orchid_core.JSONString;
216
- undefined: () => orchid_core.JSONUndefined;
217
- unknown: () => orchid_core.JSONUnknown;
218
- void: () => orchid_core.JSONVoid;
219
- array: <Type_1 extends orchid_core.JSONTypeAny>(element: Type_1) => orchid_core.JSONArray<Type_1, "many">;
220
- discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends orchid_core.Primitive, Types extends [orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => orchid_core.JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
221
- enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => orchid_core.JSONEnum<U_1, T_3>;
222
- instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => orchid_core.JSONInstanceOf<T_4>;
223
- intersection: <Left extends orchid_core.JSONTypeAny, Right extends orchid_core.JSONTypeAny>(left: Left, right: Right) => orchid_core.JSONIntersection<Left, Right>;
224
- lazy: <T_5 extends orchid_core.JSONTypeAny>(fn: () => T_5) => orchid_core.JSONLazy<T_5>;
225
- literal: <T_6 extends orchid_core.Primitive>(value: T_6) => orchid_core.JSONLiteral<T_6>;
226
- map: <Key extends orchid_core.JSONTypeAny, Value_1 extends orchid_core.JSONTypeAny>(keyType: Key, valueType: Value_1) => orchid_core.JSONMap<Key, Value_1>;
227
- nativeEnum: <T_7 extends orchid_core.EnumLike>(givenEnum: T_7) => orchid_core.JSONNativeEnum<T_7>;
228
- nullable: <T_8 extends orchid_core.JSONTypeAny>(type: T_8) => orchid_core.JSONNullable<T_8>;
229
- nullish: <T_9 extends orchid_core.JSONTypeAny>(type: T_9) => orchid_core.JSONNullish<T_9>;
230
- object: <T_10 extends orchid_core.JSONObjectShape, UnknownKeys extends orchid_core.UnknownKeysParam = "strip", Catchall extends orchid_core.JSONTypeAny = orchid_core.JSONTypeAny>(shape: T_10) => orchid_core.JSONObject<T_10, UnknownKeys, Catchall, orchid_core.JSONTypeAny extends Catchall ? orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
231
- [k: string]: Catchall["type"];
232
- } extends infer T_12 extends object ? { [k_2 in keyof T_12]: ((orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
233
- [k: string]: Catchall["type"];
234
- })[k_2]; } : never>;
235
- optional: <T_13 extends orchid_core.JSONTypeAny>(type: T_13) => orchid_core.JSONOptional<T_13>;
236
- record: typeof orchid_core.record;
237
- }) => Type)): pqb.JSONColumn<Type>;
238
- jsonText(this: orchid_core.ColumnTypesBase): pqb.JSONTextColumn;
239
- array<Item extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: orchid_core.ColumnTypesBase, item: Item): pqb.ArrayColumn<Item>;
240
- timestamps: <T_14 extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: {
241
- timestamp(): T_14;
242
- }) => {
243
- createdAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
244
- updatedAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
245
- };
246
- primaryKey(columns: string[], options?: {
247
- name?: string | undefined;
248
- } | undefined): {};
249
- index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
250
- unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
251
- foreignKey: {
252
- <Table extends pqb.ForeignKeyTableWithColumns, Columns extends [Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Table, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
253
- <Table_1 extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table_1, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
254
- };
255
- }) => Shape) | undefined, options?: pqb.DbTableOptions | undefined): pqb.Db<Table_2, Shape, pqb.RelationsBase, {
256
- name: typeof orchid_core.name;
257
- raw: (sql: string, values?: false | Record<string, unknown> | undefined) => orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>;
258
- smallint(this: orchid_core.ColumnTypesBase): pqb.SmallIntColumn;
259
- integer(this: orchid_core.ColumnTypesBase): pqb.IntegerColumn;
260
- bigint(this: orchid_core.ColumnTypesBase): pqb.BigIntColumn;
261
- numeric<Precision extends number | undefined = undefined, Scale extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision | undefined, scale?: Scale | undefined): pqb.DecimalColumn<Precision, Scale>;
262
- decimal<Precision_1 extends number | undefined = undefined, Scale_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_1 | undefined, scale?: Scale_1 | undefined): pqb.DecimalColumn<Precision_1, Scale_1>;
263
- real(this: orchid_core.ColumnTypesBase): pqb.RealColumn;
264
- doublePrecision(this: orchid_core.ColumnTypesBase): pqb.DoublePrecisionColumn;
265
- smallSerial(this: orchid_core.ColumnTypesBase): pqb.SmallSerialColumn;
266
- serial(this: orchid_core.ColumnTypesBase): pqb.SerialColumn;
267
- bigSerial(this: orchid_core.ColumnTypesBase): pqb.BigSerialColumn;
268
- money(this: orchid_core.ColumnTypesBase): pqb.MoneyColumn;
269
- varchar<Limit extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit | undefined): pqb.VarCharColumn<Limit>;
270
- char<Limit_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, limit?: Limit_1 | undefined): pqb.CharColumn<Limit_1>;
271
- text: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
272
- string: (this: orchid_core.ColumnTypesBase, min: number, max: number) => TextColumn;
273
- bytea(this: orchid_core.ColumnTypesBase): pqb.ByteaColumn;
274
- date(this: orchid_core.ColumnTypesBase): pqb.DateColumn;
275
- timestamp<Precision_2 extends number>(this: orchid_core.ColumnTypesBase, precision?: Precision_2 | undefined): pqb.TimestampColumn<Precision_2>;
276
- timestampWithTimeZone<Precision_3 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_3 | undefined): pqb.TimestampWithTimeZoneColumn<number>;
277
- time<Precision_4 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_4 | undefined): pqb.TimeColumn<Precision_4>;
278
- timeWithTimeZone<Precision_5 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, precision?: Precision_5 | undefined): pqb.TimeWithTimeZoneColumn<Precision_5>;
279
- interval<Fields extends string | undefined = undefined, Precision_6 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, fields?: Fields | undefined, precision?: Precision_6 | undefined): pqb.IntervalColumn<Fields, Precision_6>;
280
- boolean(this: orchid_core.ColumnTypesBase): pqb.BooleanColumn;
281
- enum<U extends string, T extends [U, ...U[]]>(this: orchid_core.ColumnTypesBase, dataType: string, type: T): EnumColumn<U, T>;
282
- point(this: orchid_core.ColumnTypesBase): pqb.PointColumn;
283
- line(this: orchid_core.ColumnTypesBase): pqb.LineColumn;
284
- lseg(this: orchid_core.ColumnTypesBase): pqb.LsegColumn;
285
- box(this: orchid_core.ColumnTypesBase): pqb.BoxColumn;
286
- path(this: orchid_core.ColumnTypesBase): pqb.PathColumn;
287
- polygon(this: orchid_core.ColumnTypesBase): pqb.PolygonColumn;
288
- circle(this: orchid_core.ColumnTypesBase): pqb.CircleColumn;
289
- cidr(this: orchid_core.ColumnTypesBase): pqb.CidrColumn;
290
- inet(this: orchid_core.ColumnTypesBase): pqb.InetColumn;
291
- macaddr(this: orchid_core.ColumnTypesBase): pqb.MacAddrColumn;
292
- macaddr8(this: orchid_core.ColumnTypesBase): pqb.MacAddr8Column;
293
- bit<Length extends number>(this: orchid_core.ColumnTypesBase, length: Length): pqb.BitColumn<Length>;
294
- bitVarying<Length_1 extends number | undefined = undefined>(this: orchid_core.ColumnTypesBase, length?: Length_1 | undefined): pqb.BitVaryingColumn<Length_1>;
295
- tsvector(this: orchid_core.ColumnTypesBase): pqb.TsVectorColumn;
296
- tsquery(this: orchid_core.ColumnTypesBase): pqb.TsQueryColumn;
297
- uuid(this: orchid_core.ColumnTypesBase): pqb.UUIDColumn;
298
- xml(this: orchid_core.ColumnTypesBase): pqb.XMLColumn;
299
- json<Type extends orchid_core.JSONTypeAny>(this: orchid_core.ColumnTypesBase, schemaOrFn: Type | ((j: {
300
- set: <Value extends orchid_core.JSONTypeAny>(valueType: Value) => orchid_core.JSONSet<Value>;
301
- tuple: <T_1 extends [] | orchid_core.JSONTupleItems, Rest extends orchid_core.JSONTypeAny | null = null>(items: T_1, rest?: Rest) => orchid_core.JSONTuple<T_1, Rest>;
302
- union: <T_2 extends [orchid_core.JSONTypeAny, orchid_core.JSONTypeAny, ...orchid_core.JSONTypeAny[]]>(types: T_2) => orchid_core.JSONUnion<T_2>;
303
- any: () => orchid_core.JSONAny;
304
- bigint: () => orchid_core.JSONBigInt;
305
- boolean: () => orchid_core.JSONBoolean;
306
- date: () => orchid_core.JSONDate;
307
- nan: () => orchid_core.JSONNaN;
308
- never: () => orchid_core.JSONNever;
309
- null: () => orchid_core.JSONNull;
310
- number: () => orchid_core.JSONNumber;
311
- string: () => orchid_core.JSONString;
312
- undefined: () => orchid_core.JSONUndefined;
313
- unknown: () => orchid_core.JSONUnknown;
314
- void: () => orchid_core.JSONVoid;
315
- array: <Type_1 extends orchid_core.JSONTypeAny>(element: Type_1) => orchid_core.JSONArray<Type_1, "many">;
316
- discriminatedUnion: <Discriminator extends string, DiscriminatorValue extends orchid_core.Primitive, Types extends [orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>, ...orchid_core.JSONDiscriminatedObject<Discriminator, DiscriminatorValue>[]]>(discriminator: Discriminator, options: Types) => orchid_core.JSONDiscriminatedUnion<Discriminator, DiscriminatorValue, Types[number]>;
317
- enum: <U_1 extends string, T_3 extends [U_1, ...U_1[]]>(options: T_3) => orchid_core.JSONEnum<U_1, T_3>;
318
- instanceOf: <T_4 extends new (...args: any[]) => any>(cls: T_4) => orchid_core.JSONInstanceOf<T_4>;
319
- intersection: <Left extends orchid_core.JSONTypeAny, Right extends orchid_core.JSONTypeAny>(left: Left, right: Right) => orchid_core.JSONIntersection<Left, Right>;
320
- lazy: <T_5 extends orchid_core.JSONTypeAny>(fn: () => T_5) => orchid_core.JSONLazy<T_5>;
321
- literal: <T_6 extends orchid_core.Primitive>(value: T_6) => orchid_core.JSONLiteral<T_6>;
322
- map: <Key extends orchid_core.JSONTypeAny, Value_1 extends orchid_core.JSONTypeAny>(keyType: Key, valueType: Value_1) => orchid_core.JSONMap<Key, Value_1>;
323
- nativeEnum: <T_7 extends orchid_core.EnumLike>(givenEnum: T_7) => orchid_core.JSONNativeEnum<T_7>;
324
- nullable: <T_8 extends orchid_core.JSONTypeAny>(type: T_8) => orchid_core.JSONNullable<T_8>;
325
- nullish: <T_9 extends orchid_core.JSONTypeAny>(type: T_9) => orchid_core.JSONNullish<T_9>;
326
- object: <T_10 extends orchid_core.JSONObjectShape, UnknownKeys extends orchid_core.UnknownKeysParam = "strip", Catchall extends orchid_core.JSONTypeAny = orchid_core.JSONTypeAny>(shape: T_10) => orchid_core.JSONObject<T_10, UnknownKeys, Catchall, orchid_core.JSONTypeAny extends Catchall ? orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never : (orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
327
- [k: string]: Catchall["type"];
328
- } extends infer T_12 extends object ? { [k_2 in keyof T_12]: ((orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }> extends infer T_11 extends object ? { [k in keyof T_11]: orchid_core.addQuestionMarks<{ [k_1 in keyof T_10]: T_10[k_1]["type"]; }>[k]; } : never) & {
329
- [k: string]: Catchall["type"];
330
- })[k_2]; } : never>;
331
- optional: <T_13 extends orchid_core.JSONTypeAny>(type: T_13) => orchid_core.JSONOptional<T_13>;
332
- record: typeof orchid_core.record;
333
- }) => Type)): pqb.JSONColumn<Type>;
334
- jsonText(this: orchid_core.ColumnTypesBase): pqb.JSONTextColumn;
335
- array<Item extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: orchid_core.ColumnTypesBase, item: Item): pqb.ArrayColumn<Item>;
336
- timestamps: <T_14 extends ColumnType<unknown, orchid_core.BaseOperators, unknown>>(this: {
337
- timestamp(): T_14;
338
- }) => {
339
- createdAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
340
- updatedAt: orchid_core.ColumnWithDefault<T_14, orchid_core.RawExpression<orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>>;
341
- };
342
- primaryKey(columns: string[], options?: {
343
- name?: string | undefined;
344
- } | undefined): {};
345
- index(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
346
- unique(columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): {};
347
- foreignKey: {
348
- <Table extends pqb.ForeignKeyTableWithColumns, Columns extends [Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>, ...Exclude<keyof InstanceType<Table>["columns"]["shape"], number | symbol>[]]>(columns: string[], fn: () => Table, foreignColumns: Columns, options?: ForeignKeyOptions | undefined): {};
349
- <Table_1 extends string, Columns_1 extends [string, ...string[]]>(columns: string[], table: Table_1, foreignColumns: Columns_1, options?: ForeignKeyOptions | undefined): {};
350
- };
351
- }>;
352
- adapter: pqb.Adapter;
353
- close: () => Promise<void>;
354
- } & MigrationBase & {
355
- adapter: TransactionAdapter;
356
- log: QueryLogObject | undefined;
357
- up: boolean;
358
- options: RakeDbConfig;
359
- adapterOptions: AdapterOptions;
360
- appCodeUpdaterCache: object;
361
- };
55
+ declare const createMigrationInterface: (tx: TransactionAdapter, up: boolean, options: RakeDbConfig, adapterOptions: AdapterOptions, appCodeUpdaterCache: object) => Migration;
362
56
  declare class MigrationBase {
363
57
  adapter: TransactionAdapter;
364
58
  log?: QueryLogObject;
@@ -428,6 +122,7 @@ declare namespace RakeDbAst {
428
122
  };
429
123
  type Change = {
430
124
  type: 'change';
125
+ name?: string;
431
126
  from: ColumnChange;
432
127
  to: ColumnChange;
433
128
  using?: RawExpression;
@@ -500,6 +195,7 @@ declare type RakeDbConfig = {
500
195
  basePath: string;
501
196
  migrationsPath: string;
502
197
  migrationsTable: string;
198
+ snakeCase: boolean;
503
199
  commands: Record<string, (options: AdapterOptions[], config: RakeDbConfig, args: string[]) => Promise<void>>;
504
200
  import(path: string): Promise<void>;
505
201
  noPrimaryKey?: NoPrimaryKeyOption;
@@ -534,4 +230,4 @@ declare const rollback: (options: MaybeArray<AdapterOptions>, config: RakeDbConf
534
230
 
535
231
  declare const rakeDb: (options: MaybeArray<AdapterOptions>, partialConfig?: Partial<RakeDbConfig>, args?: string[]) => Promise<void>;
536
232
 
537
- export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode, JoinTableOptions, Migration, MigrationBase, MigrationColumnTypes, RakeDbAst, RakeDbConfig, TableOptions, change, changeCache, createDb, createMigrationInterface, dropDb, generate, migrate, migrateOrRollback, rakeDb, resetDb, rollback, runCodeUpdater, writeMigrationFile };
233
+ export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode, Migration, MigrationBase, MigrationColumnTypes, RakeDbAst, RakeDbConfig, TableOptions, change, changeCache, createDb, createMigrationInterface, dropDb, generate, migrate, migrateOrRollback, rakeDb, resetDb, rollback, runCodeUpdater, writeMigrationFile };
package/dist/index.js CHANGED
@@ -55,6 +55,7 @@ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
55
55
  const migrationConfigDefaults = {
56
56
  migrationsPath: path__default["default"].join("src", "db", "migrations"),
57
57
  migrationsTable: "schemaMigrations",
58
+ snakeCase: false,
58
59
  commands: {},
59
60
  import: (path2) => (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(path2),
60
61
  log: true,
@@ -296,7 +297,7 @@ var __spreadValues$5 = (a, b) => {
296
297
  };
297
298
  var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
298
299
  const columnToSql = (key, item, values, hasMultiplePrimaryKeys) => {
299
- const line = [`"${key}" ${item.toSQL()}`];
300
+ const line = [`"${item.data.name || key}" ${item.toSQL()}`];
300
301
  if (item.data.compression) {
301
302
  line.push(`COMPRESSION ${item.data.compression}`);
302
303
  }
@@ -509,6 +510,7 @@ var __objRest = (source, exclude) => {
509
510
  };
510
511
  const types = Object.assign(Object.create(pqb.columnTypes), tableMethods);
511
512
  const createTable$1 = async (migration, up, tableName, options, fn) => {
513
+ types[orchidCore.snakeCaseKey] = migration.options.snakeCase;
512
514
  const shape = pqb.getColumnTypes(types, fn);
513
515
  const tableData = pqb.getTableData();
514
516
  const ast = makeAst$1(
@@ -668,7 +670,14 @@ const mergeTableData = (a, b) => {
668
670
  };
669
671
  function add(item, options) {
670
672
  if (item instanceof pqb.ColumnType) {
671
- return { type: "add", item, dropMode: options == null ? void 0 : options.dropMode };
673
+ if (this[orchidCore.nameKey]) {
674
+ item.data.name = this[orchidCore.nameKey];
675
+ }
676
+ return {
677
+ type: "add",
678
+ item,
679
+ dropMode: options == null ? void 0 : options.dropMode
680
+ };
672
681
  } else if (item === orchidCore.emptyObject) {
673
682
  mergeTableData(changeTableData.add, pqb.getTableData());
674
683
  pqb.resetTableData();
@@ -685,9 +694,16 @@ function add(item, options) {
685
694
  return result;
686
695
  }
687
696
  }
688
- const drop = (item, options) => {
697
+ const drop = function(item, options) {
689
698
  if (item instanceof pqb.ColumnType) {
690
- return { type: "drop", item, dropMode: options == null ? void 0 : options.dropMode };
699
+ if (this[orchidCore.nameKey]) {
700
+ item.data.name = this[orchidCore.nameKey];
701
+ }
702
+ return {
703
+ type: "drop",
704
+ item,
705
+ dropMode: options == null ? void 0 : options.dropMode
706
+ };
691
707
  } else if (item === orchidCore.emptyObject) {
692
708
  mergeTableData(changeTableData.drop, pqb.getTableData());
693
709
  pqb.resetTableData();
@@ -727,6 +743,7 @@ const tableChangeMethods = __spreadProps$2(__spreadValues$3({}, tableMethods), {
727
743
  change(from, to, options) {
728
744
  return __spreadValues$3({
729
745
  type: "change",
746
+ name: this[orchidCore.nameKey],
730
747
  from: columnTypeToColumnChange(from),
731
748
  to: columnTypeToColumnChange(to)
732
749
  }, options);
@@ -761,6 +778,7 @@ const changeTable = async (migration, up, tableName, options, fn) => {
761
778
  resetChangeTableData();
762
779
  const tableChanger = Object.create(pqb.columnTypes);
763
780
  Object.assign(tableChanger, tableChangeMethods);
781
+ tableChanger[orchidCore.snakeCaseKey] = migration.options.snakeCase;
764
782
  const changeData = (fn == null ? void 0 : fn(tableChanger)) || {};
765
783
  const ast = makeAst(up, tableName, changeData, changeTableData, options);
766
784
  const queries = astToQueries(ast);
@@ -866,28 +884,28 @@ const astToQueries = (ast) => {
866
884
  } else if (item.type === "drop") {
867
885
  addColumnIndex(dropIndexes, key, item.item);
868
886
  alterTable.push(
869
- `DROP COLUMN "${key}"${item.dropMode ? ` ${item.dropMode}` : ""}`
887
+ `DROP COLUMN "${item.item.data.name || key}"${item.dropMode ? ` ${item.dropMode}` : ""}`
870
888
  );
871
889
  } else if (item.type === "change") {
872
890
  const { from, to } = item;
873
891
  if (from.type !== to.type || from.collate !== to.collate) {
874
892
  alterTable.push(
875
- `ALTER COLUMN "${key}" TYPE ${to.type}${to.collate ? ` COLLATE ${pqb.quote(to.collate)}` : ""}${item.using ? ` USING ${pqb.getRaw(item.using, values)}` : ""}`
893
+ `ALTER COLUMN "${item.name || key}" TYPE ${to.type}${to.collate ? ` COLLATE ${pqb.quote(to.collate)}` : ""}${item.using ? ` USING ${pqb.getRaw(item.using, values)}` : ""}`
876
894
  );
877
895
  }
878
896
  if (from.default !== to.default) {
879
897
  const value = typeof to.default === "object" && to.default && orchidCore.isRaw(to.default) ? pqb.getRaw(to.default, values) : pqb.quote(to.default);
880
898
  const expr = value === void 0 ? "DROP DEFAULT" : `SET DEFAULT ${value}`;
881
- alterTable.push(`ALTER COLUMN "${key}" ${expr}`);
899
+ alterTable.push(`ALTER COLUMN "${item.name || key}" ${expr}`);
882
900
  }
883
901
  if (from.nullable !== to.nullable) {
884
902
  alterTable.push(
885
- `ALTER COLUMN "${key}" ${to.nullable ? "DROP" : "SET"} NOT NULL`
903
+ `ALTER COLUMN "${item.name || key}" ${to.nullable ? "DROP" : "SET"} NOT NULL`
886
904
  );
887
905
  }
888
906
  if (from.compression !== to.compression) {
889
907
  alterTable.push(
890
- `ALTER COLUMN "${key}" SET COMPRESSION ${to.compression || "DEFAULT"}`
908
+ `ALTER COLUMN "${item.name || key}" SET COMPRESSION ${to.compression || "DEFAULT"}`
891
909
  );
892
910
  }
893
911
  const foreignKeysLen = Math.max(
@@ -2047,6 +2065,7 @@ const pushTableAst = (ast, data, table, pendingTables, innerFKeys = data.foreign
2047
2065
  }
2048
2066
  );
2049
2067
  }
2068
+ delete column.data.name;
2050
2069
  shape[item.name] = column;
2051
2070
  }
2052
2071
  ast.push({
@@ -2100,7 +2119,7 @@ const foreignKeyToAst = (fkey) => ({
2100
2119
  }
2101
2120
  });
2102
2121
 
2103
- const astToMigration = (ast) => {
2122
+ const astToMigration = (config, ast) => {
2104
2123
  const first = [];
2105
2124
  const tables = [];
2106
2125
  const foreignKeys = [];
@@ -2116,7 +2135,7 @@ const astToMigration = (ast) => {
2116
2135
  first.push([]);
2117
2136
  first.push(...createEnum(item));
2118
2137
  } else if (item.type === "table" && item.action === "create") {
2119
- tables.push(createTable(item));
2138
+ tables.push(createTable(config, item));
2120
2139
  } else if (item.type === "foreignKey") {
2121
2140
  if (foreignKeys.length)
2122
2141
  foreignKeys.push([]);
@@ -2182,13 +2201,16 @@ const createEnum = (ast) => {
2182
2201
  orchidCore.addCode(code, ");");
2183
2202
  return code;
2184
2203
  };
2185
- const createTable = (ast) => {
2204
+ const createTable = (config, ast) => {
2186
2205
  const code = [];
2187
2206
  orchidCore.addCode(code, `await db.createTable(${quoteSchemaTable(ast)}, (t) => ({`);
2188
- const hasTimestamps = isTimestamp(ast.shape.createdAt) && isTimestamp(ast.shape.updatedAt);
2207
+ const hasTimestamps = !config.snakeCase && isTimestamp(ast.shape.createdAt) && isTimestamp(ast.shape.updatedAt);
2208
+ const hasTimestampsSnake = isTimestamp(ast.shape.created_at) && isTimestamp(ast.shape.updated_at);
2189
2209
  for (const key in ast.shape) {
2190
2210
  if (hasTimestamps && (key === "createdAt" || key === "updatedAt"))
2191
2211
  continue;
2212
+ if (hasTimestampsSnake && (key === "created_at" || key === "updated_at"))
2213
+ continue;
2192
2214
  const line = [`${orchidCore.quoteObjectKey(key)}: `];
2193
2215
  for (const part of ast.shape[key].toCode("t")) {
2194
2216
  orchidCore.addCode(line, part);
@@ -2196,9 +2218,12 @@ const createTable = (ast) => {
2196
2218
  orchidCore.addCode(line, ",");
2197
2219
  code.push(line);
2198
2220
  }
2199
- if (hasTimestamps) {
2221
+ if (hasTimestamps || config.snakeCase && hasTimestampsSnake) {
2200
2222
  code.push(["...t.timestamps(),"]);
2201
2223
  }
2224
+ if (hasTimestampsSnake && !config.snakeCase) {
2225
+ code.push(["...t.timestampsSnakeCase(),"]);
2226
+ }
2202
2227
  if (ast.primaryKey) {
2203
2228
  code.push([pqb.primaryKeyToCode(ast.primaryKey, "t")]);
2204
2229
  }
@@ -2236,7 +2261,7 @@ const pullDbStructure = async (options, config) => {
2236
2261
  const db = new DbStructure(adapter);
2237
2262
  const ast = await structureToAst(db);
2238
2263
  await adapter.close();
2239
- const result = astToMigration(ast);
2264
+ const result = astToMigration(config, ast);
2240
2265
  if (!result)
2241
2266
  return;
2242
2267
  await writeMigrationFile(config, "pull", result);