@systemfsoftware/drizzle-pg-extras 0.0.0-stage → 0.6.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/LICENSE +21 -0
- package/README.md +480 -2
- package/dist/cli.js +2918 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +3380 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +751 -0
- package/dist/index.d.ts +751 -0
- package/dist/index.js +3303 -0
- package/dist/index.js.map +1 -0
- package/package.json +88 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
import { AnyPgColumn, CheckBuilder, ForeignKeyBuilder, IndexBuilder, PgEnum, PgEnumObject, PgMaterializedView, PgTable, PgView, PrimaryKeyBuilder, UniqueConstraintBuilder } from "drizzle-orm/pg-core";
|
|
2
|
+
import { Column, ColumnBuilderBase, SQL, Table } from "drizzle-orm";
|
|
3
|
+
type Casing = 'snake_case' | 'camelCase';
|
|
4
|
+
declare const KIND: unique symbol;
|
|
5
|
+
type PgLanguage = 'plpgsql' | 'sql';
|
|
6
|
+
type PgVolatility = 'volatile' | 'stable' | 'immutable';
|
|
7
|
+
type PgSecurity = 'invoker' | 'definer';
|
|
8
|
+
type TriggerTiming = 'before' | 'after' | 'instead of';
|
|
9
|
+
type TriggerEvent = 'insert' | 'update' | 'delete' | 'truncate';
|
|
10
|
+
type TriggerForEach = 'row' | 'statement';
|
|
11
|
+
type PgType = string | AnyPgColumn;
|
|
12
|
+
type PgFunctionArg = {
|
|
13
|
+
name?: string;
|
|
14
|
+
type: PgType;
|
|
15
|
+
/** SQL expression, such as `0` or `'pending'`. Not a bind parameter. */
|
|
16
|
+
default?: string;
|
|
17
|
+
};
|
|
18
|
+
type PgFunctionConfig = {
|
|
19
|
+
schema?: string;
|
|
20
|
+
args?: readonly PgFunctionArg[];
|
|
21
|
+
returns: PgType;
|
|
22
|
+
language?: PgLanguage;
|
|
23
|
+
body: string | SQL;
|
|
24
|
+
volatility?: PgVolatility;
|
|
25
|
+
security?: PgSecurity;
|
|
26
|
+
/**
|
|
27
|
+
* Pins `search_path` for the function. `[]` emits `SET search_path TO ''`.
|
|
28
|
+
* Set this when `security` is `"definer"`.
|
|
29
|
+
*/
|
|
30
|
+
searchPath?: readonly string[];
|
|
31
|
+
strict?: boolean;
|
|
32
|
+
};
|
|
33
|
+
type PgFunction = {
|
|
34
|
+
readonly [KIND]: 'function';
|
|
35
|
+
readonly name: string;
|
|
36
|
+
readonly schema: string;
|
|
37
|
+
readonly args: readonly PgFunctionArg[];
|
|
38
|
+
readonly returns: PgType;
|
|
39
|
+
readonly language: PgLanguage;
|
|
40
|
+
readonly body: string | SQL;
|
|
41
|
+
readonly volatility: PgVolatility;
|
|
42
|
+
readonly security: PgSecurity;
|
|
43
|
+
readonly searchPath: readonly string[] | null;
|
|
44
|
+
readonly strict: boolean;
|
|
45
|
+
};
|
|
46
|
+
type RowRefs<TTable extends PgTable> = { [K in keyof TTable['_']['columns']]: SQL; };
|
|
47
|
+
type TriggerArg = string | number | boolean | AnyPgColumn | SQL;
|
|
48
|
+
type FunctionCall = PgFunction | {
|
|
49
|
+
name: string;
|
|
50
|
+
schema?: string;
|
|
51
|
+
};
|
|
52
|
+
type UpdatedAtSource = {
|
|
53
|
+
column: AnyPgColumn;
|
|
54
|
+
functionName?: string;
|
|
55
|
+
schema?: string;
|
|
56
|
+
};
|
|
57
|
+
type TriggerInitially = 'immediate' | 'deferred';
|
|
58
|
+
/** Options for `CREATE CONSTRAINT TRIGGER`. `true` means NOT DEFERRABLE. */
|
|
59
|
+
type TriggerConstraint = {
|
|
60
|
+
/** Default false: `NOT DEFERRABLE`. */
|
|
61
|
+
deferrable?: boolean;
|
|
62
|
+
/** Default `"immediate"`. `"deferred"` requires `deferrable: true`. */
|
|
63
|
+
initially?: TriggerInitially;
|
|
64
|
+
/** Referenced table in the `FROM` clause. */
|
|
65
|
+
from?: PgTable | {
|
|
66
|
+
name: string;
|
|
67
|
+
schema?: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/** Statement transition tables: `REFERENCING OLD TABLE AS ... NEW TABLE AS ...`. */
|
|
71
|
+
type TriggerReferencing = {
|
|
72
|
+
oldTable?: string;
|
|
73
|
+
newTable?: string;
|
|
74
|
+
};
|
|
75
|
+
type TriggerRelation = PgTable | PgViewLike | {
|
|
76
|
+
name: string;
|
|
77
|
+
schema?: string;
|
|
78
|
+
};
|
|
79
|
+
type PgTrigger = {
|
|
80
|
+
readonly [KIND]: 'trigger';
|
|
81
|
+
readonly name: string | null;
|
|
82
|
+
readonly table: TriggerRelation;
|
|
83
|
+
readonly timing: TriggerTiming;
|
|
84
|
+
readonly events: readonly TriggerEvent[];
|
|
85
|
+
readonly forEach: TriggerForEach;
|
|
86
|
+
readonly columns: readonly (AnyPgColumn | string)[];
|
|
87
|
+
readonly when: WhenInput | null;
|
|
88
|
+
readonly function: FunctionCall | null;
|
|
89
|
+
readonly args: readonly TriggerArg[];
|
|
90
|
+
readonly updatedAt: UpdatedAtSource | null;
|
|
91
|
+
readonly constraint: boolean;
|
|
92
|
+
readonly deferrable: boolean;
|
|
93
|
+
readonly initially: TriggerInitially;
|
|
94
|
+
readonly from: PgTable | {
|
|
95
|
+
name: string;
|
|
96
|
+
schema?: string;
|
|
97
|
+
} | null;
|
|
98
|
+
readonly oldTable: string | null;
|
|
99
|
+
readonly newTable: string | null;
|
|
100
|
+
/** False emits `ALTER TABLE ... DISABLE TRIGGER` after the trigger exists. */
|
|
101
|
+
readonly enabled: boolean;
|
|
102
|
+
};
|
|
103
|
+
type WhenInput = string | SQL | ((refs: {
|
|
104
|
+
NEW: Record<string, SQL>;
|
|
105
|
+
OLD: Record<string, SQL>;
|
|
106
|
+
}) => SQL | string);
|
|
107
|
+
type PgExtension = {
|
|
108
|
+
readonly [KIND]: 'extension';
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly schema: string | null;
|
|
111
|
+
readonly version: string | null;
|
|
112
|
+
readonly cascade: boolean;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Either `pgEnum` form. A structural type so a specific `pgEnum("role", ["a"])`
|
|
116
|
+
* still assigns; Drizzle's enum generics are invariant.
|
|
117
|
+
*/
|
|
118
|
+
type AnyPgEnum = {
|
|
119
|
+
readonly enumName: string;
|
|
120
|
+
readonly enumValues: readonly string[];
|
|
121
|
+
readonly schema?: string;
|
|
122
|
+
};
|
|
123
|
+
type PgViewLike = PgView | PgMaterializedView;
|
|
124
|
+
type PgCommentTarget = PgTable | AnyPgColumn | AnyPgEnum | PgViewLike | PgFunction | PgTrigger | PgExtension;
|
|
125
|
+
type PgComment = {
|
|
126
|
+
readonly [KIND]: 'comment';
|
|
127
|
+
readonly target: PgCommentTarget;
|
|
128
|
+
readonly text: string;
|
|
129
|
+
};
|
|
130
|
+
type PartitionMethod = 'range' | 'list' | 'hash';
|
|
131
|
+
/** A bound written into `FOR VALUES`. `MINVALUE` and `MAXVALUE` are range keywords, not strings. */
|
|
132
|
+
type PartitionBound = (string & {}) | number | boolean | null | bigint | 'MINVALUE' | 'MAXVALUE';
|
|
133
|
+
type PartitionParent = PgTable | PartitionedTable | {
|
|
134
|
+
name: string;
|
|
135
|
+
schema?: string;
|
|
136
|
+
};
|
|
137
|
+
type PartitionBoundSpec = {
|
|
138
|
+
kind: 'range';
|
|
139
|
+
from: readonly PartitionBound[];
|
|
140
|
+
to: readonly PartitionBound[];
|
|
141
|
+
} | {
|
|
142
|
+
kind: 'list';
|
|
143
|
+
values: readonly (PartitionBound | readonly PartitionBound[])[];
|
|
144
|
+
} | {
|
|
145
|
+
kind: 'hash';
|
|
146
|
+
modulus: number;
|
|
147
|
+
remainder: number;
|
|
148
|
+
} | {
|
|
149
|
+
kind: 'default';
|
|
150
|
+
};
|
|
151
|
+
type PartitionedTable = {
|
|
152
|
+
readonly [KIND]: 'partitionedTable';
|
|
153
|
+
readonly table: PgTable | {
|
|
154
|
+
name: string;
|
|
155
|
+
schema?: string;
|
|
156
|
+
};
|
|
157
|
+
readonly method: PartitionMethod;
|
|
158
|
+
readonly columns: readonly (AnyPgColumn | string)[];
|
|
159
|
+
};
|
|
160
|
+
type PgPartition = {
|
|
161
|
+
readonly [KIND]: 'partition';
|
|
162
|
+
readonly name: string;
|
|
163
|
+
readonly schema: string | null;
|
|
164
|
+
readonly parent: PartitionParent;
|
|
165
|
+
readonly mode: 'create' | 'attach';
|
|
166
|
+
/** Used when this declaration is removed. `drop` deletes the child. `detach` keeps the table. */
|
|
167
|
+
readonly onRemove: 'drop' | 'detach';
|
|
168
|
+
readonly bound: PartitionBoundSpec;
|
|
169
|
+
};
|
|
170
|
+
type PgDetach = {
|
|
171
|
+
readonly [KIND]: 'detach';
|
|
172
|
+
readonly table: PgTable | {
|
|
173
|
+
name: string;
|
|
174
|
+
schema?: string;
|
|
175
|
+
};
|
|
176
|
+
readonly parent: PartitionParent;
|
|
177
|
+
};
|
|
178
|
+
type HypertableOrderSpec = {
|
|
179
|
+
column: AnyPgColumn | string;
|
|
180
|
+
direction: 'asc' | 'desc' | null;
|
|
181
|
+
nulls: 'first' | 'last' | null;
|
|
182
|
+
};
|
|
183
|
+
type HypertableCompression = {
|
|
184
|
+
segmentBy: readonly (AnyPgColumn | string)[];
|
|
185
|
+
orderBy: readonly HypertableOrderSpec[];
|
|
186
|
+
};
|
|
187
|
+
type HypertableRetention = {
|
|
188
|
+
dropAfter: string;
|
|
189
|
+
scheduleInterval: string | null;
|
|
190
|
+
};
|
|
191
|
+
type HypertableCompressionPolicy = {
|
|
192
|
+
compressAfter: string;
|
|
193
|
+
scheduleInterval: string | null;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* A drizzle-kit table that `generate` turns into a TimescaleDB hypertable.
|
|
197
|
+
* The table stays in the Drizzle schema. The migration calls `create_hypertable`.
|
|
198
|
+
*/
|
|
199
|
+
type Hypertable = {
|
|
200
|
+
readonly [KIND]: 'hypertable';
|
|
201
|
+
readonly table: PgTable | {
|
|
202
|
+
name: string;
|
|
203
|
+
schema?: string;
|
|
204
|
+
};
|
|
205
|
+
readonly timeColumn: AnyPgColumn | string;
|
|
206
|
+
readonly chunkTimeInterval: string | null;
|
|
207
|
+
readonly partitioningColumn: AnyPgColumn | string | null;
|
|
208
|
+
readonly numberPartitions: number | null;
|
|
209
|
+
readonly migrateData: boolean;
|
|
210
|
+
readonly compression: HypertableCompression | null;
|
|
211
|
+
readonly retention: HypertableRetention | null;
|
|
212
|
+
readonly compressionPolicy: HypertableCompressionPolicy | null;
|
|
213
|
+
};
|
|
214
|
+
type PgExtras = {
|
|
215
|
+
functions: PgFunction[];
|
|
216
|
+
triggers: PgTrigger[];
|
|
217
|
+
extensions: PgExtension[];
|
|
218
|
+
comments: PgComment[];
|
|
219
|
+
tables: PgTable[];
|
|
220
|
+
enums: AnyPgEnum[];
|
|
221
|
+
views: PgViewLike[];
|
|
222
|
+
partitionedTables: PartitionedTable[];
|
|
223
|
+
partitions: PgPartition[];
|
|
224
|
+
detaches: PgDetach[];
|
|
225
|
+
hypertables: Hypertable[];
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Attach a Postgres comment and return the same object.
|
|
229
|
+
* Column comments are stored on the builder config Drizzle copies onto the built column,
|
|
230
|
+
* so query building and `drizzle-kit` diffs are unchanged. The same is true for indexes
|
|
231
|
+
* and constraints: the comment lives on the builder, which the table callback creates
|
|
232
|
+
* again each time drizzle-kit reads the schema.
|
|
233
|
+
*
|
|
234
|
+
* Wrap a column builder (`text("email")`), not a column already read back off the table.
|
|
235
|
+
* For an existing column, enum, view, function, trigger, or extension, use {@link commentOn}.
|
|
236
|
+
* Call `.as()` or `.existing()` before commenting a view, and `.on()` before commenting an index or unique constraint.
|
|
237
|
+
*/
|
|
238
|
+
export declare function withComment<T extends Table>(target: T, comment: string): T;
|
|
239
|
+
export declare function withComment<T extends ColumnBuilderBase>(target: T, comment: string): T;
|
|
240
|
+
export declare function withComment<T extends Column>(target: T, comment: string): T;
|
|
241
|
+
export declare function withComment<T extends PgEnum<[string, ...string[]]>>(target: T, comment: string): T;
|
|
242
|
+
export declare function withComment<T extends PgEnumObject<object>>(target: T, comment: string): T;
|
|
243
|
+
export declare function withComment<T extends PgView>(target: T, comment: string): T;
|
|
244
|
+
export declare function withComment<T extends PgMaterializedView>(target: T, comment: string): T;
|
|
245
|
+
export declare function withComment<T extends PgFunction>(target: T, comment: string): T;
|
|
246
|
+
export declare function withComment<T extends PgTrigger>(target: T, comment: string): T;
|
|
247
|
+
export declare function withComment<T extends PgExtension>(target: T, comment: string): T;
|
|
248
|
+
export declare function withComment<T extends IndexBuilder>(target: T, comment: string): T;
|
|
249
|
+
export declare function withComment<T extends UniqueConstraintBuilder>(target: T, comment: string): T;
|
|
250
|
+
export declare function withComment<T extends CheckBuilder>(target: T, comment: string): T;
|
|
251
|
+
export declare function withComment<T extends ForeignKeyBuilder>(target: T, comment: string): T;
|
|
252
|
+
export declare function withComment<T extends PrimaryKeyBuilder>(target: T, comment: string): T;
|
|
253
|
+
export declare function readComment(target: object): string | undefined;
|
|
254
|
+
export declare function pgFunction(name: string, config: PgFunctionConfig): PgFunction;
|
|
255
|
+
type TriggerOptions = {
|
|
256
|
+
constraint?: boolean | TriggerConstraint;
|
|
257
|
+
referencing?: TriggerReferencing;
|
|
258
|
+
/** Default true. `false` emits `ALTER TABLE ... DISABLE TRIGGER`. Views cannot be disabled. */
|
|
259
|
+
enabled?: boolean;
|
|
260
|
+
};
|
|
261
|
+
type TableTriggerConfig<TTable extends PgTable> = TriggerOptions & {
|
|
262
|
+
table: TTable;
|
|
263
|
+
timing: 'before' | 'after';
|
|
264
|
+
events: readonly TriggerEvent[];
|
|
265
|
+
forEach?: TriggerForEach;
|
|
266
|
+
columns?: readonly (TTable['_']['columns'][keyof TTable['_']['columns']] | string)[];
|
|
267
|
+
when?: string | SQL | ((refs: {
|
|
268
|
+
NEW: RowRefs<TTable>;
|
|
269
|
+
OLD: RowRefs<TTable>;
|
|
270
|
+
}) => SQL | string);
|
|
271
|
+
function: FunctionCall;
|
|
272
|
+
args?: readonly TriggerArg[];
|
|
273
|
+
};
|
|
274
|
+
type ViewColumn<TView> = Extract<TView[keyof TView], Column>;
|
|
275
|
+
type ViewTriggerConfig<TView extends PgViewLike> = TriggerOptions & {
|
|
276
|
+
table: TView;
|
|
277
|
+
timing: TriggerTiming;
|
|
278
|
+
events: readonly TriggerEvent[];
|
|
279
|
+
forEach?: TriggerForEach;
|
|
280
|
+
columns?: readonly (ViewColumn<TView> | string)[];
|
|
281
|
+
when?: string | SQL;
|
|
282
|
+
function: FunctionCall;
|
|
283
|
+
args?: readonly TriggerArg[];
|
|
284
|
+
};
|
|
285
|
+
type NameTriggerConfig = TriggerOptions & {
|
|
286
|
+
table: {
|
|
287
|
+
name: string;
|
|
288
|
+
schema?: string;
|
|
289
|
+
};
|
|
290
|
+
timing: TriggerTiming;
|
|
291
|
+
events: readonly TriggerEvent[];
|
|
292
|
+
forEach?: TriggerForEach;
|
|
293
|
+
columns?: readonly string[];
|
|
294
|
+
when?: string | SQL;
|
|
295
|
+
function: FunctionCall;
|
|
296
|
+
args?: readonly TriggerArg[];
|
|
297
|
+
};
|
|
298
|
+
export declare function pgTrigger<TTable extends PgTable>(name: string, config: TableTriggerConfig<TTable>): PgTrigger;
|
|
299
|
+
export declare function pgTrigger<TView extends PgViewLike>(name: string, config: ViewTriggerConfig<TView>): PgTrigger;
|
|
300
|
+
export declare function pgTrigger(name: string, config: NameTriggerConfig): PgTrigger;
|
|
301
|
+
export declare function updatedAtTrigger<TTable extends PgTable>(table: TTable, column: TTable['_']['columns'][keyof TTable['_']['columns']], options?: {
|
|
302
|
+
name?: string;
|
|
303
|
+
functionName?: string;
|
|
304
|
+
schema?: string;
|
|
305
|
+
}): PgTrigger;
|
|
306
|
+
export declare function pgExtension(name: string, options?: {
|
|
307
|
+
schema?: string;
|
|
308
|
+
version?: string;
|
|
309
|
+
cascade?: boolean;
|
|
310
|
+
}): PgExtension;
|
|
311
|
+
/**
|
|
312
|
+
* A comment that is not attached with {@link withComment}.
|
|
313
|
+
* Indexes and constraints are recreated whenever the table config runs, so comment those
|
|
314
|
+
* with `withComment` on the builder inside the extra-config callback.
|
|
315
|
+
*/
|
|
316
|
+
export declare function commentOn(target: PgTable, text: string): PgComment;
|
|
317
|
+
export declare function commentOn(target: AnyPgColumn, text: string): PgComment;
|
|
318
|
+
export declare function commentOn<TValues extends [string, ...string[]]>(target: PgEnum<TValues>, text: string): PgComment;
|
|
319
|
+
export declare function commentOn<TValues extends object>(target: PgEnumObject<TValues>, text: string): PgComment;
|
|
320
|
+
export declare function commentOn(target: PgView, text: string): PgComment;
|
|
321
|
+
export declare function commentOn(target: PgMaterializedView, text: string): PgComment;
|
|
322
|
+
export declare function commentOn(target: PgFunction, text: string): PgComment;
|
|
323
|
+
export declare function commentOn(target: PgTrigger, text: string): PgComment;
|
|
324
|
+
export declare function commentOn(target: PgExtension, text: string): PgComment;
|
|
325
|
+
/**
|
|
326
|
+
* Declare that a drizzle-kit table should become partitioned.
|
|
327
|
+
*
|
|
328
|
+
* Postgres only accepts `PARTITION BY` on `CREATE TABLE`. drizzle-kit has already
|
|
329
|
+
* emitted a normal `CREATE TABLE`, so `generate` writes a migration that recreates
|
|
330
|
+
* that table when it is empty and refuses to run once it has rows. The table stays
|
|
331
|
+
* in the Drizzle schema; this package does not emit a second copy of the column list.
|
|
332
|
+
*/
|
|
333
|
+
export declare function partitionedTable<TTable extends PgTable>(table: TTable, config: {
|
|
334
|
+
method: PartitionMethod;
|
|
335
|
+
columns: readonly TTable['_']['columns'][keyof TTable['_']['columns']][];
|
|
336
|
+
}): PartitionedTable;
|
|
337
|
+
export declare function partitionedTable(table: {
|
|
338
|
+
name: string;
|
|
339
|
+
schema?: string;
|
|
340
|
+
}, config: {
|
|
341
|
+
method: PartitionMethod;
|
|
342
|
+
columns: readonly string[];
|
|
343
|
+
}): PartitionedTable;
|
|
344
|
+
/**
|
|
345
|
+
* A child table created with `CREATE TABLE ... PARTITION OF`.
|
|
346
|
+
* `onRemove` defaults to `"drop"`: removing the declaration drops the child when it is empty.
|
|
347
|
+
*/
|
|
348
|
+
export declare function pgPartition(name: string, config: {
|
|
349
|
+
parent: PartitionParent;
|
|
350
|
+
schema?: string;
|
|
351
|
+
onRemove?: 'drop' | 'detach';
|
|
352
|
+
from: readonly PartitionBound[];
|
|
353
|
+
to: readonly PartitionBound[];
|
|
354
|
+
}): PgPartition;
|
|
355
|
+
export declare function pgPartition(name: string, config: {
|
|
356
|
+
parent: PartitionParent;
|
|
357
|
+
schema?: string;
|
|
358
|
+
onRemove?: 'drop' | 'detach';
|
|
359
|
+
in: readonly (PartitionBound | readonly PartitionBound[])[];
|
|
360
|
+
}): PgPartition;
|
|
361
|
+
export declare function pgPartition(name: string, config: {
|
|
362
|
+
parent: PartitionParent;
|
|
363
|
+
schema?: string;
|
|
364
|
+
onRemove?: 'drop' | 'detach';
|
|
365
|
+
modulus: number;
|
|
366
|
+
remainder: number;
|
|
367
|
+
}): PgPartition;
|
|
368
|
+
export declare function pgPartition(name: string, config: {
|
|
369
|
+
parent: PartitionParent;
|
|
370
|
+
schema?: string;
|
|
371
|
+
onRemove?: 'drop' | 'detach';
|
|
372
|
+
default: true;
|
|
373
|
+
}): PgPartition;
|
|
374
|
+
/**
|
|
375
|
+
* Attach a table drizzle-kit already created. Removing the declaration detaches it and leaves the table in place.
|
|
376
|
+
* The table has to match the parent (column order, NOT NULL, unique indexes, and check constraints) or Postgres rejects ATTACH.
|
|
377
|
+
*/
|
|
378
|
+
export declare function pgAttachPartition(table: PgTable, config: {
|
|
379
|
+
parent: PartitionParent;
|
|
380
|
+
from: readonly PartitionBound[];
|
|
381
|
+
to: readonly PartitionBound[];
|
|
382
|
+
}): PgPartition;
|
|
383
|
+
export declare function pgAttachPartition(table: PgTable, config: {
|
|
384
|
+
parent: PartitionParent;
|
|
385
|
+
in: readonly (PartitionBound | readonly PartitionBound[])[];
|
|
386
|
+
}): PgPartition;
|
|
387
|
+
export declare function pgAttachPartition(table: PgTable, config: {
|
|
388
|
+
parent: PartitionParent;
|
|
389
|
+
modulus: number;
|
|
390
|
+
remainder: number;
|
|
391
|
+
}): PgPartition;
|
|
392
|
+
export declare function pgAttachPartition(table: PgTable, config: {
|
|
393
|
+
parent: PartitionParent;
|
|
394
|
+
default: true;
|
|
395
|
+
}): PgPartition;
|
|
396
|
+
export declare function pgAttachPartition(table: {
|
|
397
|
+
name: string;
|
|
398
|
+
schema?: string;
|
|
399
|
+
}, config: {
|
|
400
|
+
parent: PartitionParent;
|
|
401
|
+
from: readonly PartitionBound[];
|
|
402
|
+
to: readonly PartitionBound[];
|
|
403
|
+
}): PgPartition;
|
|
404
|
+
export declare function pgAttachPartition(table: {
|
|
405
|
+
name: string;
|
|
406
|
+
schema?: string;
|
|
407
|
+
}, config: {
|
|
408
|
+
parent: PartitionParent;
|
|
409
|
+
in: readonly (PartitionBound | readonly PartitionBound[])[];
|
|
410
|
+
}): PgPartition;
|
|
411
|
+
export declare function pgAttachPartition(table: {
|
|
412
|
+
name: string;
|
|
413
|
+
schema?: string;
|
|
414
|
+
}, config: {
|
|
415
|
+
parent: PartitionParent;
|
|
416
|
+
modulus: number;
|
|
417
|
+
remainder: number;
|
|
418
|
+
}): PgPartition;
|
|
419
|
+
export declare function pgAttachPartition(table: {
|
|
420
|
+
name: string;
|
|
421
|
+
schema?: string;
|
|
422
|
+
}, config: {
|
|
423
|
+
parent: PartitionParent;
|
|
424
|
+
default: true;
|
|
425
|
+
}): PgPartition;
|
|
426
|
+
/** Keep `table` detached from `parent`. Idempotent when it is not attached. */
|
|
427
|
+
export declare function pgDetachPartition(table: PgTable | {
|
|
428
|
+
name: string;
|
|
429
|
+
schema?: string;
|
|
430
|
+
}, config: {
|
|
431
|
+
parent: PartitionParent;
|
|
432
|
+
}): PgDetach;
|
|
433
|
+
type DrizzleHypertableConfig<TTable extends PgTable> = {
|
|
434
|
+
timeColumn: TTable['_']['columns'][keyof TTable['_']['columns']];
|
|
435
|
+
chunkTimeInterval?: string;
|
|
436
|
+
partitioningColumn?: TTable['_']['columns'][keyof TTable['_']['columns']];
|
|
437
|
+
numberPartitions?: number;
|
|
438
|
+
migrateData?: boolean;
|
|
439
|
+
compression?: {
|
|
440
|
+
segmentBy?: readonly TTable['_']['columns'][keyof TTable['_']['columns']][];
|
|
441
|
+
orderBy?: readonly (TTable['_']['columns'][keyof TTable['_']['columns']] | {
|
|
442
|
+
column: TTable['_']['columns'][keyof TTable['_']['columns']];
|
|
443
|
+
direction?: 'asc' | 'desc';
|
|
444
|
+
nulls?: 'first' | 'last';
|
|
445
|
+
})[];
|
|
446
|
+
};
|
|
447
|
+
retention?: {
|
|
448
|
+
dropAfter: string;
|
|
449
|
+
scheduleInterval?: string;
|
|
450
|
+
};
|
|
451
|
+
compressionPolicy?: {
|
|
452
|
+
compressAfter: string;
|
|
453
|
+
scheduleInterval?: string;
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
type NameHypertableConfig = {
|
|
457
|
+
timeColumn: string;
|
|
458
|
+
chunkTimeInterval?: string;
|
|
459
|
+
partitioningColumn?: string;
|
|
460
|
+
numberPartitions?: number;
|
|
461
|
+
migrateData?: boolean;
|
|
462
|
+
compression?: {
|
|
463
|
+
segmentBy?: readonly string[];
|
|
464
|
+
orderBy?: readonly (string | {
|
|
465
|
+
column: string;
|
|
466
|
+
direction?: 'asc' | 'desc';
|
|
467
|
+
nulls?: 'first' | 'last';
|
|
468
|
+
})[];
|
|
469
|
+
};
|
|
470
|
+
retention?: {
|
|
471
|
+
dropAfter: string;
|
|
472
|
+
scheduleInterval?: string;
|
|
473
|
+
};
|
|
474
|
+
compressionPolicy?: {
|
|
475
|
+
compressAfter: string;
|
|
476
|
+
scheduleInterval?: string;
|
|
477
|
+
};
|
|
478
|
+
};
|
|
479
|
+
/**
|
|
480
|
+
* Turn the empty table drizzle-kit created into a TimescaleDB hypertable.
|
|
481
|
+
*
|
|
482
|
+
* There is no `ALTER TABLE` that does this, and this package does not rewrite the
|
|
483
|
+
* `CREATE TABLE` drizzle-kit already wrote. `generate` appends `create_hypertable`
|
|
484
|
+
* with `if_not_exists => TRUE`. Export `pgExtension("timescaledb")` from the schema too.
|
|
485
|
+
*/
|
|
486
|
+
export declare function hypertable<TTable extends PgTable>(table: TTable, config: DrizzleHypertableConfig<TTable>): Hypertable;
|
|
487
|
+
export declare function hypertable(table: {
|
|
488
|
+
name: string;
|
|
489
|
+
schema?: string;
|
|
490
|
+
}, config: NameHypertableConfig): Hypertable;
|
|
491
|
+
export declare function collectExtras(modules: Record<string, unknown> | readonly Record<string, unknown>[]): PgExtras;
|
|
492
|
+
export declare function defineExtras(input: {
|
|
493
|
+
functions?: readonly PgFunction[];
|
|
494
|
+
triggers?: readonly PgTrigger[];
|
|
495
|
+
extensions?: readonly PgExtension[];
|
|
496
|
+
comments?: readonly PgComment[];
|
|
497
|
+
tables?: readonly PgTable[];
|
|
498
|
+
enums?: readonly AnyPgEnum[];
|
|
499
|
+
views?: readonly PgViewLike[];
|
|
500
|
+
partitionedTables?: readonly PartitionedTable[];
|
|
501
|
+
partitions?: readonly PgPartition[];
|
|
502
|
+
detaches?: readonly PgDetach[];
|
|
503
|
+
hypertables?: readonly Hypertable[];
|
|
504
|
+
}): PgExtras;
|
|
505
|
+
type FunctionArgSnapshot = {
|
|
506
|
+
name: string | null;
|
|
507
|
+
type: string;
|
|
508
|
+
defaultExpr: string | null;
|
|
509
|
+
};
|
|
510
|
+
type FunctionSnapshot = {
|
|
511
|
+
id: string;
|
|
512
|
+
name: string;
|
|
513
|
+
schema: string;
|
|
514
|
+
args: FunctionArgSnapshot[];
|
|
515
|
+
returns: string;
|
|
516
|
+
language: 'plpgsql' | 'sql';
|
|
517
|
+
body: string;
|
|
518
|
+
volatility: 'volatile' | 'stable' | 'immutable';
|
|
519
|
+
security: 'invoker' | 'definer';
|
|
520
|
+
searchPath: string[] | null;
|
|
521
|
+
strict: boolean;
|
|
522
|
+
};
|
|
523
|
+
type TriggerSnapshot = {
|
|
524
|
+
id: string;
|
|
525
|
+
name: string;
|
|
526
|
+
schema: string;
|
|
527
|
+
table: string;
|
|
528
|
+
timing: 'before' | 'after' | 'instead of';
|
|
529
|
+
events: ('insert' | 'update' | 'delete' | 'truncate')[];
|
|
530
|
+
forEach: 'row' | 'statement';
|
|
531
|
+
columns: string[];
|
|
532
|
+
when: string | null;
|
|
533
|
+
functionSchema: string;
|
|
534
|
+
functionName: string;
|
|
535
|
+
functionArgsSql: string[];
|
|
536
|
+
functionId: string | null;
|
|
537
|
+
constraint: boolean;
|
|
538
|
+
deferrable: boolean;
|
|
539
|
+
initially: TriggerInitially;
|
|
540
|
+
fromSchema: string | null;
|
|
541
|
+
fromTable: string | null;
|
|
542
|
+
oldTable: string | null;
|
|
543
|
+
newTable: string | null;
|
|
544
|
+
enabled: boolean;
|
|
545
|
+
};
|
|
546
|
+
type ExtensionSnapshot = {
|
|
547
|
+
id: string;
|
|
548
|
+
name: string;
|
|
549
|
+
schema: string | null;
|
|
550
|
+
version: string | null;
|
|
551
|
+
cascade: boolean;
|
|
552
|
+
};
|
|
553
|
+
type CommentKind = 'table' | 'column' | 'enum' | 'view' | 'materializedView' | 'function' | 'trigger' | 'index' | 'constraint' | 'extension';
|
|
554
|
+
type CommentSnapshot = {
|
|
555
|
+
id: string;
|
|
556
|
+
kind: CommentKind;
|
|
557
|
+
schema: string;
|
|
558
|
+
/** Table, column, enum, view, function, trigger, index, constraint, or extension name. */
|
|
559
|
+
name: string;
|
|
560
|
+
/** Table or view that owns a column, trigger, or constraint. */
|
|
561
|
+
relation: string | null;
|
|
562
|
+
column: string | null;
|
|
563
|
+
argTypes: string[];
|
|
564
|
+
text: string;
|
|
565
|
+
};
|
|
566
|
+
type InventoryTable = {
|
|
567
|
+
schema: string;
|
|
568
|
+
name: string;
|
|
569
|
+
columns: string[];
|
|
570
|
+
};
|
|
571
|
+
type InventoryName = {
|
|
572
|
+
schema: string;
|
|
573
|
+
name: string;
|
|
574
|
+
};
|
|
575
|
+
type InventoryView = {
|
|
576
|
+
schema: string;
|
|
577
|
+
name: string;
|
|
578
|
+
materialized: boolean;
|
|
579
|
+
columns: string[];
|
|
580
|
+
};
|
|
581
|
+
type InventoryIndex = {
|
|
582
|
+
schema: string;
|
|
583
|
+
table: string;
|
|
584
|
+
name: string;
|
|
585
|
+
};
|
|
586
|
+
type InventoryConstraint = {
|
|
587
|
+
schema: string;
|
|
588
|
+
table: string;
|
|
589
|
+
name: string;
|
|
590
|
+
};
|
|
591
|
+
type PartitionedTableSnapshot = {
|
|
592
|
+
id: string;
|
|
593
|
+
schema: string;
|
|
594
|
+
name: string;
|
|
595
|
+
method: 'range' | 'list' | 'hash';
|
|
596
|
+
columns: string[];
|
|
597
|
+
};
|
|
598
|
+
type PartitionSnapshot = {
|
|
599
|
+
id: string;
|
|
600
|
+
schema: string;
|
|
601
|
+
name: string;
|
|
602
|
+
parentSchema: string;
|
|
603
|
+
parentName: string;
|
|
604
|
+
mode: 'create' | 'attach';
|
|
605
|
+
onRemove: 'drop' | 'detach';
|
|
606
|
+
boundKind: 'range' | 'list' | 'hash' | 'default';
|
|
607
|
+
/** `DEFAULT` or a `FOR VALUES ...` clause, with literals already quoted. */
|
|
608
|
+
boundSql: string;
|
|
609
|
+
};
|
|
610
|
+
type DetachSnapshot = {
|
|
611
|
+
id: string;
|
|
612
|
+
schema: string;
|
|
613
|
+
name: string;
|
|
614
|
+
parentSchema: string;
|
|
615
|
+
parentName: string;
|
|
616
|
+
};
|
|
617
|
+
type HypertableOrderSnapshot = {
|
|
618
|
+
column: string;
|
|
619
|
+
direction: 'asc' | 'desc' | null;
|
|
620
|
+
nulls: 'first' | 'last' | null;
|
|
621
|
+
};
|
|
622
|
+
type HypertableCompressionSnapshot = {
|
|
623
|
+
segmentBy: string[];
|
|
624
|
+
orderBy: HypertableOrderSnapshot[];
|
|
625
|
+
};
|
|
626
|
+
type HypertableRetentionSnapshot = {
|
|
627
|
+
dropAfter: string;
|
|
628
|
+
scheduleInterval: string | null;
|
|
629
|
+
};
|
|
630
|
+
type HypertableCompressionPolicySnapshot = {
|
|
631
|
+
compressAfter: string;
|
|
632
|
+
scheduleInterval: string | null;
|
|
633
|
+
};
|
|
634
|
+
type HypertableSnapshot = {
|
|
635
|
+
id: string;
|
|
636
|
+
schema: string;
|
|
637
|
+
name: string;
|
|
638
|
+
timeColumn: string;
|
|
639
|
+
chunkTimeInterval: string | null;
|
|
640
|
+
partitioningColumn: string | null;
|
|
641
|
+
numberPartitions: number | null;
|
|
642
|
+
/** Used only by the create_hypertable statement. Changing it later does not write a migration. */
|
|
643
|
+
migrateData: boolean;
|
|
644
|
+
compression: HypertableCompressionSnapshot | null;
|
|
645
|
+
retention: HypertableRetentionSnapshot | null;
|
|
646
|
+
compressionPolicy: HypertableCompressionPolicySnapshot | null;
|
|
647
|
+
};
|
|
648
|
+
type Snapshot = {
|
|
649
|
+
version: 1;
|
|
650
|
+
functions: FunctionSnapshot[];
|
|
651
|
+
triggers: TriggerSnapshot[];
|
|
652
|
+
extensions: ExtensionSnapshot[];
|
|
653
|
+
comments: CommentSnapshot[];
|
|
654
|
+
partitionedTables: PartitionedTableSnapshot[];
|
|
655
|
+
partitions: PartitionSnapshot[];
|
|
656
|
+
detaches: DetachSnapshot[];
|
|
657
|
+
hypertables: HypertableSnapshot[];
|
|
658
|
+
inventory: {
|
|
659
|
+
scanned: boolean;
|
|
660
|
+
tables: InventoryTable[];
|
|
661
|
+
enums: InventoryName[];
|
|
662
|
+
views: InventoryView[];
|
|
663
|
+
indexes: InventoryIndex[];
|
|
664
|
+
constraints: InventoryConstraint[];
|
|
665
|
+
};
|
|
666
|
+
};
|
|
667
|
+
export declare function emptySnapshot(): Snapshot;
|
|
668
|
+
export declare function snapshotExtras(extras: PgExtras, options?: {
|
|
669
|
+
casing?: Casing;
|
|
670
|
+
}): Snapshot;
|
|
671
|
+
export declare function parseSnapshot(value: unknown): Snapshot;
|
|
672
|
+
type SqlDiff = {
|
|
673
|
+
up: string[];
|
|
674
|
+
down: string[];
|
|
675
|
+
};
|
|
676
|
+
export declare function diffSnapshots(from: Snapshot, to: Snapshot): SqlDiff;
|
|
677
|
+
/**
|
|
678
|
+
* Idempotent SQL for the whole snapshot. Useful after `drizzle-kit push`, which
|
|
679
|
+
* does not run migration files. It does not drop objects removed from the snapshot.
|
|
680
|
+
*/
|
|
681
|
+
export declare function idempotentStatements(snapshot: Snapshot): string[];
|
|
682
|
+
export declare class PgExtrasError extends Error {
|
|
683
|
+
constructor(message: string);
|
|
684
|
+
}
|
|
685
|
+
export declare const BREAKPOINT = "--> statement-breakpoint";
|
|
686
|
+
type MigrationPrefix = 'index' | 'timestamp' | 'supabase' | 'unix' | 'none';
|
|
687
|
+
type WrittenMigration = {
|
|
688
|
+
tag: string;
|
|
689
|
+
sqlPath: string;
|
|
690
|
+
downPath: string;
|
|
691
|
+
layout: 'journal' | 'v1';
|
|
692
|
+
};
|
|
693
|
+
export declare function joinStatements(statements: readonly string[], breakpoints: boolean, header: string): string;
|
|
694
|
+
export declare function splitMigrationSql(sql: string): string[];
|
|
695
|
+
type GenerateOptions = {
|
|
696
|
+
extras: PgExtras;
|
|
697
|
+
out: string;
|
|
698
|
+
name?: string;
|
|
699
|
+
casing?: Casing;
|
|
700
|
+
prefix?: MigrationPrefix;
|
|
701
|
+
breakpoints?: boolean;
|
|
702
|
+
};
|
|
703
|
+
type GenerateResult = {
|
|
704
|
+
written: false;
|
|
705
|
+
up: string[];
|
|
706
|
+
down: string[];
|
|
707
|
+
} | ({
|
|
708
|
+
written: true;
|
|
709
|
+
up: string[];
|
|
710
|
+
down: string[];
|
|
711
|
+
} & WrittenMigration);
|
|
712
|
+
export declare function loadStoredSnapshot(out: string): Snapshot;
|
|
713
|
+
export declare function planExtras(extras: PgExtras, previous: Snapshot, casing?: Casing): {
|
|
714
|
+
up: string[];
|
|
715
|
+
down: string[];
|
|
716
|
+
next: Snapshot;
|
|
717
|
+
};
|
|
718
|
+
export declare function generate(options: GenerateOptions): GenerateResult;
|
|
719
|
+
export declare function pendingStatements(extras: PgExtras, out: string, casing?: Casing): string[];
|
|
720
|
+
export declare function renderIdempotent(extras: PgExtras, options?: {
|
|
721
|
+
casing?: Casing;
|
|
722
|
+
breakpoints?: boolean;
|
|
723
|
+
}): string;
|
|
724
|
+
export declare function convertPartitionedTableSql(parent: PartitionedTableSnapshot, direction: 'partition' | 'unpartition'): string;
|
|
725
|
+
export declare function createPartitionSql(partition: PartitionSnapshot): string;
|
|
726
|
+
export declare function attachPartitionSql(partition: PartitionSnapshot): string;
|
|
727
|
+
export declare function detachPartitionSql(partition: Pick<PartitionSnapshot, 'schema' | 'name' | 'parentSchema' | 'parentName'>): string;
|
|
728
|
+
export declare function dropPartitionSql(partition: Pick<PartitionSnapshot, 'schema' | 'name' | 'parentSchema' | 'parentName'>): string;
|
|
729
|
+
export declare function createFunctionSql(fn: FunctionSnapshot): string;
|
|
730
|
+
export declare function dropFunctionSql(fn: FunctionSnapshot): string;
|
|
731
|
+
export declare function createTriggerSql(trigger: TriggerSnapshot): string;
|
|
732
|
+
export declare function dropTriggerSql(trigger: TriggerSnapshot): string;
|
|
733
|
+
export declare function alterTriggerEnabledSql(trigger: TriggerSnapshot): string;
|
|
734
|
+
export declare function createExtensionSql(ext: ExtensionSnapshot): string;
|
|
735
|
+
export declare function dropExtensionSql(ext: ExtensionSnapshot): string;
|
|
736
|
+
export declare function commentSql(comment: CommentSnapshot, text: string | null): string;
|
|
737
|
+
export declare function createHypertableStatements(ht: HypertableSnapshot): string[];
|
|
738
|
+
export declare function createHypertableSql(ht: HypertableSnapshot): string;
|
|
739
|
+
export declare function setChunkTimeIntervalSql(ht: HypertableSnapshot): string;
|
|
740
|
+
export declare function addHypertableDimensionSql(ht: HypertableSnapshot): string;
|
|
741
|
+
export declare function enableHypertableCompressionSql(ht: Pick<HypertableSnapshot, 'schema' | 'name'>, compression: HypertableCompressionSnapshot, previous: HypertableCompressionSnapshot | null): string;
|
|
742
|
+
export declare function disableHypertableCompressionSql(ht: Pick<HypertableSnapshot, 'schema' | 'name'>): string;
|
|
743
|
+
export declare function addRetentionPolicySql(ht: HypertableSnapshot): string;
|
|
744
|
+
export declare function removeRetentionPolicySql(ht: Pick<HypertableSnapshot, 'schema' | 'name'>): string;
|
|
745
|
+
export declare function addCompressionPolicySql(ht: HypertableSnapshot): string;
|
|
746
|
+
export declare function removeCompressionPolicySql(ht: Pick<HypertableSnapshot, 'schema' | 'name'>): string;
|
|
747
|
+
export declare function leaveHypertableDimensionSql(ht: HypertableSnapshot): string;
|
|
748
|
+
export declare function leaveChunkIntervalSql(ht: HypertableSnapshot): string;
|
|
749
|
+
export declare function leaveHypertableSql(ht: Pick<HypertableSnapshot, 'schema' | 'name'>): string;
|
|
750
|
+
export declare const VERSION: string;
|
|
751
|
+
export type { AnyPgEnum, CommentSnapshot, DetachSnapshot, ExtensionSnapshot, FunctionCall, FunctionSnapshot, GenerateOptions, GenerateResult, Hypertable, HypertableCompression, HypertableCompressionPolicy, HypertableCompressionPolicySnapshot, HypertableCompressionSnapshot, HypertableOrderSnapshot, HypertableOrderSpec, HypertableRetention, HypertableRetentionSnapshot, HypertableSnapshot, PartitionBound, PartitionBoundSpec, PartitionMethod, PartitionParent, PartitionSnapshot, PartitionedTable, PartitionedTableSnapshot, PgComment, PgCommentTarget, PgDetach, PgExtension, PgExtras, PgFunction, PgFunctionArg, PgFunctionConfig, PgLanguage, PgPartition, PgSecurity, PgTrigger, PgViewLike, PgVolatility, RowRefs, Snapshot, SqlDiff, TriggerArg, TriggerConstraint, TriggerEvent, TriggerForEach, TriggerInitially, TriggerReferencing, TriggerRelation, TriggerSnapshot, TriggerTiming };
|