@immich/sql-tools 0.0.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.
@@ -0,0 +1,946 @@
1
+ import { ColumnType as ColumnType_2 } from 'kysely';
2
+ import { Kysely } from 'kysely';
3
+ import { Sql } from 'postgres';
4
+
5
+ export declare enum ActionType {
6
+ NO_ACTION = "NO ACTION",
7
+ RESTRICT = "RESTRICT",
8
+ CASCADE = "CASCADE",
9
+ SET_NULL = "SET NULL",
10
+ SET_DEFAULT = "SET DEFAULT"
11
+ }
12
+
13
+ export declare const AfterDeleteTrigger: (options: Omit<TriggerFunctionOptions, "timing" | "actions">) => ClassDecorator;
14
+
15
+ export declare const AfterInsertTrigger: (options: Omit<TriggerFunctionOptions, "timing" | "actions">) => ClassDecorator;
16
+
17
+ declare class BaseContext {
18
+ databaseName: string;
19
+ schemaName: string;
20
+ overrideTableName: string;
21
+ tables: DatabaseTable[];
22
+ functions: DatabaseFunction[];
23
+ enums: DatabaseEnum[];
24
+ extensions: DatabaseExtension[];
25
+ parameters: DatabaseParameter[];
26
+ overrides: DatabaseOverride[];
27
+ warnings: string[];
28
+ private namingStrategy;
29
+ constructor(options: BaseContextOptions);
30
+ getNameFor(item: NamingItem): string;
31
+ getTableByName(name: string): DatabaseTable | undefined;
32
+ warn(context: string, message: string): void;
33
+ build(): DatabaseSchema;
34
+ }
35
+
36
+ export declare type BaseContextOptions = {
37
+ databaseName?: string;
38
+ schemaName?: string;
39
+ overrideTableName?: string;
40
+ namingStrategy?: 'default' | 'hash' | NamingInterface;
41
+ };
42
+
43
+ export declare const BeforeUpdateTrigger: (options: Omit<TriggerFunctionOptions, "timing" | "actions">) => ClassDecorator;
44
+
45
+ export declare const Check: (options: CheckOptions) => ClassDecorator;
46
+
47
+ export declare type CheckOptions = {
48
+ name?: string;
49
+ expression: string;
50
+ synchronize?: boolean;
51
+ };
52
+
53
+ declare type ClassBased<T> = {
54
+ object: Function;
55
+ } & T;
56
+
57
+ declare type ColumBasedConstraint = {
58
+ name: string;
59
+ tableName: string;
60
+ columnNames: string[];
61
+ };
62
+
63
+ export declare const Column: (options?: string | ColumnOptions) => PropertyDecorator;
64
+
65
+ export declare type ColumnBaseOptions = {
66
+ name?: string;
67
+ primary?: boolean;
68
+ type?: ColumnType;
69
+ nullable?: boolean;
70
+ length?: number;
71
+ default?: ColumnValue;
72
+ comment?: string;
73
+ synchronize?: boolean;
74
+ storage?: ColumnStorage;
75
+ identity?: boolean;
76
+ index?: boolean;
77
+ indexName?: string;
78
+ unique?: boolean;
79
+ uniqueConstraintName?: string;
80
+ };
81
+
82
+ export declare type ColumnChanges = {
83
+ nullable?: boolean;
84
+ default?: string;
85
+ comment?: string;
86
+ storage?: ColumnStorage;
87
+ };
88
+
89
+ export declare type ColumnOptions = ColumnBaseOptions & {
90
+ enum?: DatabaseEnum;
91
+ array?: boolean;
92
+ };
93
+
94
+ export declare type ColumnStorage = 'default' | 'external' | 'extended' | 'main';
95
+
96
+ export declare type ColumnType = 'bigint' | 'boolean' | 'bytea' | 'character' | 'character varying' | 'date' | 'double precision' | 'integer' | 'jsonb' | 'polygon' | 'text' | 'time' | 'time with time zone' | 'time without time zone' | 'timestamp' | 'timestamp with time zone' | 'timestamp without time zone' | 'uuid' | 'vector' | 'enum' | 'serial' | 'real';
97
+
98
+ export declare type ColumnValue = null | boolean | string | number | Array<unknown> | object | Date | (() => string);
99
+
100
+ export declare type CompareFunction<T> = (source: T, target: T) => SchemaDiff[];
101
+
102
+ export declare type Comparer<T> = {
103
+ onMissing: (source: T) => SchemaDiff[];
104
+ onExtra: (target: T) => SchemaDiff[];
105
+ onCompare: CompareFunction<T>;
106
+ /** if two items have the same key, they are considered identical and can be renamed via `onRename` */
107
+ getRenameKey?: (item: T) => string;
108
+ onRename?: (source: T, target: T) => SchemaDiff[];
109
+ };
110
+
111
+ export declare const ConfigurationParameter: (options: ConfigurationParameterOptions) => ClassDecorator;
112
+
113
+ export declare type ConfigurationParameterOptions = {
114
+ name: string;
115
+ value: ColumnValue;
116
+ scope: ParameterScope;
117
+ synchronize?: boolean;
118
+ };
119
+
120
+ export declare enum ConstraintType {
121
+ PRIMARY_KEY = "primary-key",
122
+ FOREIGN_KEY = "foreign-key",
123
+ UNIQUE = "unique",
124
+ CHECK = "check"
125
+ }
126
+
127
+ export declare const CreateDateColumn: (options?: ColumnOptions) => PropertyDecorator;
128
+
129
+ export declare const Database: (options: DatabaseOptions) => ClassDecorator;
130
+
131
+ export declare type DatabaseCheckConstraint = {
132
+ type: ConstraintType.CHECK;
133
+ name: string;
134
+ tableName: string;
135
+ expression: string;
136
+ synchronize: boolean;
137
+ };
138
+
139
+ export declare type DatabaseClient = Kysely<PostgresDB>;
140
+
141
+ export declare type DatabaseColumn = {
142
+ primary: boolean;
143
+ name: string;
144
+ tableName: string;
145
+ comment?: string;
146
+ type: ColumnType;
147
+ nullable: boolean;
148
+ isArray: boolean;
149
+ synchronize: boolean;
150
+ default?: string;
151
+ length?: number;
152
+ storage?: ColumnStorage;
153
+ identity?: boolean;
154
+ enumName?: string;
155
+ numericPrecision?: number;
156
+ numericScale?: number;
157
+ };
158
+
159
+ export declare type DatabaseConstraint = DatabasePrimaryKeyConstraint | DatabaseForeignKeyConstraint | DatabaseUniqueConstraint | DatabaseCheckConstraint;
160
+
161
+ export declare type DatabaseEnum = {
162
+ name: string;
163
+ values: string[];
164
+ synchronize: boolean;
165
+ };
166
+
167
+ export declare type DatabaseExtension = {
168
+ name: string;
169
+ synchronize: boolean;
170
+ };
171
+
172
+ export declare type DatabaseForeignKeyConstraint = ColumBasedConstraint & {
173
+ type: ConstraintType.FOREIGN_KEY;
174
+ referenceTableName: string;
175
+ referenceColumnNames: string[];
176
+ onUpdate?: ActionType;
177
+ onDelete?: ActionType;
178
+ synchronize: boolean;
179
+ };
180
+
181
+ export declare type DatabaseFunction = {
182
+ name: string;
183
+ expression: string;
184
+ synchronize: boolean;
185
+ override?: DatabaseOverride;
186
+ };
187
+
188
+ export declare type DatabaseIndex = {
189
+ name: string;
190
+ tableName: string;
191
+ columnNames?: string[];
192
+ expression?: string;
193
+ unique: boolean;
194
+ using?: string;
195
+ with?: string;
196
+ where?: string;
197
+ override?: DatabaseOverride;
198
+ synchronize: boolean;
199
+ };
200
+
201
+ declare type DatabaseLike = Sql | Kysely<any>;
202
+
203
+ export declare type DatabaseOptions = {
204
+ name?: string;
205
+ synchronize?: boolean;
206
+ };
207
+
208
+ export declare type DatabaseOverride = {
209
+ name: string;
210
+ value: {
211
+ name: string;
212
+ type: OverrideType;
213
+ sql: string;
214
+ };
215
+ synchronize: boolean;
216
+ };
217
+
218
+ export declare type DatabaseParameter = {
219
+ name: string;
220
+ databaseName: string;
221
+ value: string | number | null | undefined;
222
+ scope: ParameterScope;
223
+ synchronize: boolean;
224
+ };
225
+
226
+ export declare type DatabasePrimaryKeyConstraint = ColumBasedConstraint & {
227
+ type: ConstraintType.PRIMARY_KEY;
228
+ synchronize: boolean;
229
+ };
230
+
231
+ export declare type DatabaseSchema = {
232
+ databaseName: string;
233
+ schemaName: string;
234
+ functions: DatabaseFunction[];
235
+ enums: DatabaseEnum[];
236
+ tables: DatabaseTable[];
237
+ extensions: DatabaseExtension[];
238
+ parameters: DatabaseParameter[];
239
+ overrides: DatabaseOverride[];
240
+ warnings: string[];
241
+ };
242
+
243
+ export declare type DatabaseTable = {
244
+ name: string;
245
+ columns: DatabaseColumn[];
246
+ indexes: DatabaseIndex[];
247
+ constraints: DatabaseConstraint[];
248
+ triggers: DatabaseTrigger[];
249
+ synchronize: boolean;
250
+ };
251
+
252
+ export declare type DatabaseTrigger = {
253
+ name: string;
254
+ tableName: string;
255
+ timing: TriggerTiming;
256
+ actions: TriggerAction[];
257
+ scope: TriggerScope;
258
+ referencingNewTableAs?: string;
259
+ referencingOldTableAs?: string;
260
+ when?: string;
261
+ functionName: string;
262
+ override?: DatabaseOverride;
263
+ synchronize: boolean;
264
+ };
265
+
266
+ export declare type DatabaseUniqueConstraint = ColumBasedConstraint & {
267
+ type: ConstraintType.UNIQUE;
268
+ synchronize: boolean;
269
+ };
270
+
271
+ export declare class DefaultNamingStrategy {
272
+ getName(item: NamingItem): string;
273
+ }
274
+
275
+ export declare const DeleteDateColumn: (options?: ColumnOptions) => PropertyDecorator;
276
+
277
+ export declare type EnumOptions = {
278
+ name: string;
279
+ values: string[];
280
+ synchronize?: boolean;
281
+ };
282
+
283
+ export declare const Extension: (options: string | ExtensionOptions) => ClassDecorator;
284
+
285
+ export declare type ExtensionOptions = {
286
+ name: string;
287
+ synchronize?: boolean;
288
+ };
289
+
290
+ export declare const Extensions: (options: Array<string | ExtensionsOptions>) => ClassDecorator;
291
+
292
+ export declare type ExtensionsOptions = {
293
+ name: string;
294
+ synchronize?: boolean;
295
+ };
296
+
297
+ export declare type ForeignKeyAction = 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION';
298
+
299
+ export declare const ForeignKeyColumn: (target: () => Function, options: ForeignKeyColumnOptions) => PropertyDecorator;
300
+
301
+ export declare type ForeignKeyColumnOptions = ColumnBaseOptions & {
302
+ onUpdate?: ForeignKeyAction;
303
+ onDelete?: ForeignKeyAction;
304
+ constraintName?: string;
305
+ };
306
+
307
+ export declare const ForeignKeyConstraint: (options: ForeignKeyConstraintOptions) => ClassDecorator;
308
+
309
+ export declare type ForeignKeyConstraintOptions = {
310
+ name?: string;
311
+ index?: boolean;
312
+ indexName?: string;
313
+ columns: string[];
314
+ referenceTable: () => Function;
315
+ referenceColumns?: string[];
316
+ onUpdate?: ForeignKeyAction;
317
+ onDelete?: ForeignKeyAction;
318
+ synchronize?: boolean;
319
+ };
320
+
321
+ export declare type FunctionOptions = {
322
+ name: string;
323
+ arguments?: string[];
324
+ returnType: ColumnType | string;
325
+ language?: 'SQL' | 'PLPGSQL';
326
+ behavior?: 'immutable' | 'stable' | 'volatile';
327
+ parallel?: 'safe' | 'unsafe' | 'restricted';
328
+ strict?: boolean;
329
+ synchronize?: boolean;
330
+ } & ({
331
+ body: string;
332
+ } | {
333
+ return: string;
334
+ });
335
+
336
+ export declare type GenerateColumnOptions = Omit<ColumnOptions, 'type'> & {
337
+ strategy?: GeneratedColumnStrategy;
338
+ };
339
+
340
+ export declare type Generated<T> = T extends ColumnType_2<infer S, infer I, infer U> ? ColumnType_2<S, I | undefined, U> : ColumnType_2<T, T | undefined, T>;
341
+
342
+ export declare const GeneratedColumn: ({ strategy, ...options }: GenerateColumnOptions) => PropertyDecorator;
343
+
344
+ export declare type GeneratedColumnStrategy = 'uuid' | 'identity';
345
+
346
+ export declare class HashNamingStrategy implements NamingInterface {
347
+ getName(item: NamingItem): string;
348
+ }
349
+
350
+ export declare type IgnoreOptions = boolean | {
351
+ ignoreExtra?: boolean;
352
+ ignoreMissing?: boolean;
353
+ };
354
+
355
+ export declare const Index: (options?: string | IndexOptions) => ClassDecorator;
356
+
357
+ export declare type IndexOptions = {
358
+ name?: string;
359
+ unique?: boolean;
360
+ expression?: string;
361
+ using?: string;
362
+ with?: string;
363
+ where?: string;
364
+ columns?: string[];
365
+ synchronize?: boolean;
366
+ };
367
+
368
+ export declare type Int8 = ColumnType_2<number>;
369
+
370
+ export declare interface NamingInterface {
371
+ getName(item: NamingItem): string;
372
+ }
373
+
374
+ export declare type NamingItem = {
375
+ type: 'database';
376
+ name: string;
377
+ } | {
378
+ type: 'table';
379
+ name: string;
380
+ } | {
381
+ type: 'column';
382
+ name: string;
383
+ } | {
384
+ type: 'primaryKey';
385
+ tableName: string;
386
+ columnNames: string[];
387
+ } | {
388
+ type: 'foreignKey';
389
+ tableName: string;
390
+ columnNames: string[];
391
+ referenceTableName: string;
392
+ referenceColumnNames: string[];
393
+ } | {
394
+ type: 'check';
395
+ tableName: string;
396
+ expression: string;
397
+ } | {
398
+ type: 'unique';
399
+ tableName: string;
400
+ columnNames: string[];
401
+ } | {
402
+ type: 'index';
403
+ tableName: string;
404
+ columnNames?: string[];
405
+ expression?: string;
406
+ where?: string;
407
+ } | {
408
+ type: 'trigger';
409
+ tableName: string;
410
+ functionName: string;
411
+ actions: TriggerAction[];
412
+ scope: TriggerScope;
413
+ timing: TriggerTiming;
414
+ columnNames?: string[];
415
+ expression?: string;
416
+ where?: string;
417
+ };
418
+
419
+ export declare type OverrideType = 'function' | 'index' | 'trigger';
420
+
421
+ export declare type ParameterScope = 'database' | 'user';
422
+
423
+ export declare type PostgresDB = {
424
+ pg_am: {
425
+ oid: number;
426
+ amname: string;
427
+ amhandler: string;
428
+ amtype: string;
429
+ };
430
+ pg_attribute: {
431
+ attrelid: number;
432
+ attname: string;
433
+ attnum: number;
434
+ atttypeid: number;
435
+ attstattarget: number;
436
+ attstatarget: number;
437
+ aanum: number;
438
+ };
439
+ pg_class: {
440
+ oid: number;
441
+ relname: string;
442
+ relkind: string;
443
+ relnamespace: string;
444
+ reltype: string;
445
+ relowner: string;
446
+ relam: string;
447
+ relfilenode: string;
448
+ reltablespace: string;
449
+ relpages: number;
450
+ reltuples: number;
451
+ relallvisible: number;
452
+ reltoastrelid: string;
453
+ relhasindex: PostgresYesOrNo;
454
+ relisshared: PostgresYesOrNo;
455
+ relpersistence: string;
456
+ };
457
+ pg_constraint: {
458
+ oid: number;
459
+ conname: string;
460
+ conrelid: string;
461
+ contype: string;
462
+ connamespace: string;
463
+ conkey: number[];
464
+ confkey: number[];
465
+ confrelid: string;
466
+ confupdtype: string;
467
+ confdeltype: string;
468
+ confmatchtype: number;
469
+ condeferrable: PostgresYesOrNo;
470
+ condeferred: PostgresYesOrNo;
471
+ convalidated: PostgresYesOrNo;
472
+ conindid: number;
473
+ };
474
+ pg_description: {
475
+ objoid: string;
476
+ classoid: string;
477
+ objsubid: number;
478
+ description: string;
479
+ };
480
+ pg_trigger: {
481
+ oid: string;
482
+ tgisinternal: boolean;
483
+ tginitdeferred: boolean;
484
+ tgdeferrable: boolean;
485
+ tgrelid: string;
486
+ tgfoid: string;
487
+ tgname: string;
488
+ tgenabled: string;
489
+ tgtype: number;
490
+ tgconstraint: string;
491
+ tgdeferred: boolean;
492
+ tgargs: Buffer;
493
+ tgoldtable: string;
494
+ tgnewtable: string;
495
+ tgqual: string;
496
+ };
497
+ 'pg_catalog.pg_extension': {
498
+ oid: string;
499
+ extname: string;
500
+ extowner: string;
501
+ extnamespace: string;
502
+ extrelocatable: boolean;
503
+ extversion: string;
504
+ extconfig: string[];
505
+ extcondition: string[];
506
+ };
507
+ pg_enum: {
508
+ oid: string;
509
+ enumtypid: string;
510
+ enumsortorder: number;
511
+ enumlabel: string;
512
+ };
513
+ pg_index: {
514
+ indexrelid: string;
515
+ indrelid: string;
516
+ indisready: boolean;
517
+ indexprs: string | null;
518
+ indpred: string | null;
519
+ indkey: number[];
520
+ indisprimary: boolean;
521
+ indisunique: boolean;
522
+ };
523
+ pg_indexes: {
524
+ schemaname: string;
525
+ tablename: string;
526
+ indexname: string;
527
+ tablespace: string | null;
528
+ indexrelid: string;
529
+ indexdef: string;
530
+ };
531
+ pg_namespace: {
532
+ oid: number;
533
+ nspname: string;
534
+ nspowner: number;
535
+ nspacl: string[];
536
+ };
537
+ pg_type: {
538
+ oid: string;
539
+ typname: string;
540
+ typnamespace: string;
541
+ typowner: string;
542
+ typtype: string;
543
+ typcategory: string;
544
+ typarray: string;
545
+ };
546
+ pg_depend: {
547
+ objid: string;
548
+ deptype: string;
549
+ };
550
+ pg_proc: {
551
+ oid: string;
552
+ proname: string;
553
+ pronamespace: string;
554
+ prokind: string;
555
+ };
556
+ pg_settings: {
557
+ name: string;
558
+ setting: string;
559
+ unit: string | null;
560
+ category: string;
561
+ short_desc: string | null;
562
+ extra_desc: string | null;
563
+ context: string;
564
+ vartype: string;
565
+ source: string;
566
+ min_val: string | null;
567
+ max_val: string | null;
568
+ enumvals: string[] | null;
569
+ boot_val: string | null;
570
+ reset_val: string | null;
571
+ sourcefile: string | null;
572
+ sourceline: number | null;
573
+ pending_restart: PostgresYesOrNo;
574
+ };
575
+ 'information_schema.tables': {
576
+ table_catalog: string;
577
+ table_schema: string;
578
+ table_name: string;
579
+ table_type: 'VIEW' | 'BASE TABLE' | string;
580
+ is_insertable_info: PostgresYesOrNo;
581
+ is_typed: PostgresYesOrNo;
582
+ commit_action: string | null;
583
+ };
584
+ 'information_schema.columns': {
585
+ table_catalog: string;
586
+ table_schema: string;
587
+ table_name: string;
588
+ column_name: string;
589
+ ordinal_position: number;
590
+ column_default: string | null;
591
+ is_nullable: PostgresYesOrNo;
592
+ data_type: string;
593
+ dtd_identifier: string;
594
+ character_maximum_length: number | null;
595
+ character_octet_length: number | null;
596
+ numeric_precision: number | null;
597
+ numeric_precision_radix: number | null;
598
+ numeric_scale: number | null;
599
+ datetime_precision: number | null;
600
+ interval_type: string | null;
601
+ interval_precision: number | null;
602
+ udt_catalog: string;
603
+ udt_schema: string;
604
+ udt_name: string;
605
+ maximum_cardinality: number | null;
606
+ is_updatable: PostgresYesOrNo;
607
+ };
608
+ 'information_schema.element_types': {
609
+ object_catalog: string;
610
+ object_schema: string;
611
+ object_name: string;
612
+ object_type: string;
613
+ collection_type_identifier: string;
614
+ data_type: string;
615
+ };
616
+ 'information_schema.routines': {
617
+ specific_catalog: string;
618
+ specific_schema: string;
619
+ specific_name: string;
620
+ routine_catalog: string;
621
+ routine_schema: string;
622
+ routine_name: string;
623
+ routine_type: string;
624
+ data_type: string;
625
+ type_udt_catalog: string;
626
+ type_udt_schema: string;
627
+ type_udt_name: string;
628
+ dtd_identifier: string;
629
+ routine_body: string;
630
+ routine_definition: string;
631
+ external_name: string;
632
+ external_language: string;
633
+ is_deterministic: PostgresYesOrNo;
634
+ security_type: string;
635
+ };
636
+ };
637
+
638
+ declare type PostgresYesOrNo = 'YES' | 'NO';
639
+
640
+ export declare const PrimaryColumn: (options?: Omit<ColumnOptions, "primary">) => PropertyDecorator;
641
+
642
+ export declare const PrimaryGeneratedColumn: (options?: Omit<GenerateColumnOptions, "primary">) => PropertyDecorator;
643
+
644
+ export declare type Processor = (ctx: ProcessorContext, items: RegisterItem[]) => void;
645
+
646
+ declare class ProcessorContext extends BaseContext {
647
+ options: SchemaFromCodeOptions;
648
+ constructor(options: SchemaFromCodeOptions);
649
+ classToTable: WeakMap<Function, DatabaseTable>;
650
+ tableToMetadata: WeakMap<DatabaseTable, TableMetadata>;
651
+ getTableByObject(object: Function): DatabaseTable | undefined;
652
+ getTableMetadata(table: DatabaseTable): TableMetadata;
653
+ addTable(table: DatabaseTable, options: TableOptions, object: Function): void;
654
+ getColumnByObjectAndPropertyName(object: object, propertyName: string | symbol): {
655
+ table?: DatabaseTable;
656
+ column?: DatabaseColumn;
657
+ };
658
+ addColumn(table: DatabaseTable, column: DatabaseColumn, options: ColumnOptions, propertyName: string | symbol): void;
659
+ warnMissingTable(context: string, object: object, propertyName?: symbol | string): void;
660
+ warnMissingColumn(context: string, object: object, propertyName?: symbol | string): void;
661
+ }
662
+
663
+ declare type PropertyBased<T> = {
664
+ object: object;
665
+ propertyName: string | symbol;
666
+ } & T;
667
+
668
+ export declare type Reader = (ctx: ReaderContext, db: DatabaseClient) => Promise<void>;
669
+
670
+ declare class ReaderContext extends BaseContext {
671
+ options: SchemaFromDatabaseOptions;
672
+ constructor(options: SchemaFromDatabaseOptions);
673
+ }
674
+
675
+ export declare enum Reason {
676
+ MissingInSource = "missing in source",
677
+ MissingInTarget = "missing in target",
678
+ Rename = "name has changed"
679
+ }
680
+
681
+ export declare const registerEnum: (options: EnumOptions) => DatabaseEnum;
682
+
683
+ export declare const registerFunction: (options: FunctionOptions) => DatabaseFunction;
684
+
685
+ declare type RegisterItem = {
686
+ type: 'database';
687
+ item: ClassBased<{
688
+ options: DatabaseOptions;
689
+ }>;
690
+ } | {
691
+ type: 'table';
692
+ item: ClassBased<{
693
+ options: TableOptions;
694
+ }>;
695
+ } | {
696
+ type: 'index';
697
+ item: ClassBased<{
698
+ options: IndexOptions;
699
+ }>;
700
+ } | {
701
+ type: 'uniqueConstraint';
702
+ item: ClassBased<{
703
+ options: UniqueOptions;
704
+ }>;
705
+ } | {
706
+ type: 'checkConstraint';
707
+ item: ClassBased<{
708
+ options: CheckOptions;
709
+ }>;
710
+ } | {
711
+ type: 'column';
712
+ item: PropertyBased<{
713
+ options: ColumnOptions;
714
+ }>;
715
+ } | {
716
+ type: 'function';
717
+ item: DatabaseFunction;
718
+ } | {
719
+ type: 'enum';
720
+ item: DatabaseEnum;
721
+ } | {
722
+ type: 'trigger';
723
+ item: ClassBased<{
724
+ options: TriggerOptions;
725
+ }>;
726
+ } | {
727
+ type: 'extension';
728
+ item: ClassBased<{
729
+ options: ExtensionOptions;
730
+ }>;
731
+ } | {
732
+ type: 'configurationParameter';
733
+ item: ClassBased<{
734
+ options: ConfigurationParameterOptions;
735
+ }>;
736
+ } | {
737
+ type: 'foreignKeyColumn';
738
+ item: PropertyBased<{
739
+ options: ForeignKeyColumnOptions;
740
+ target: () => Function;
741
+ }>;
742
+ } | {
743
+ type: 'foreignKeyConstraint';
744
+ item: ClassBased<{
745
+ options: ForeignKeyConstraintOptions;
746
+ }>;
747
+ };
748
+
749
+ export declare type SchemaDiff = {
750
+ reason: string;
751
+ } & ({
752
+ type: 'ExtensionCreate';
753
+ extension: DatabaseExtension;
754
+ } | {
755
+ type: 'ExtensionDrop';
756
+ extensionName: string;
757
+ } | {
758
+ type: 'FunctionCreate';
759
+ function: DatabaseFunction;
760
+ } | {
761
+ type: 'FunctionDrop';
762
+ functionName: string;
763
+ } | {
764
+ type: 'TableCreate';
765
+ table: DatabaseTable;
766
+ } | {
767
+ type: 'TableDrop';
768
+ tableName: string;
769
+ } | {
770
+ type: 'ColumnAdd';
771
+ column: DatabaseColumn;
772
+ } | {
773
+ type: 'ColumnRename';
774
+ tableName: string;
775
+ oldName: string;
776
+ newName: string;
777
+ } | {
778
+ type: 'ColumnAlter';
779
+ tableName: string;
780
+ columnName: string;
781
+ changes: ColumnChanges;
782
+ } | {
783
+ type: 'ColumnDrop';
784
+ tableName: string;
785
+ columnName: string;
786
+ } | {
787
+ type: 'ConstraintAdd';
788
+ constraint: DatabaseConstraint;
789
+ } | {
790
+ type: 'ConstraintRename';
791
+ tableName: string;
792
+ oldName: string;
793
+ newName: string;
794
+ } | {
795
+ type: 'ConstraintDrop';
796
+ tableName: string;
797
+ constraintName: string;
798
+ } | {
799
+ type: 'IndexCreate';
800
+ index: DatabaseIndex;
801
+ } | {
802
+ type: 'IndexRename';
803
+ tableName: string;
804
+ oldName: string;
805
+ newName: string;
806
+ } | {
807
+ type: 'IndexDrop';
808
+ indexName: string;
809
+ } | {
810
+ type: 'TriggerCreate';
811
+ trigger: DatabaseTrigger;
812
+ } | {
813
+ type: 'TriggerDrop';
814
+ tableName: string;
815
+ triggerName: string;
816
+ } | {
817
+ type: 'ParameterSet';
818
+ parameter: DatabaseParameter;
819
+ } | {
820
+ type: 'ParameterReset';
821
+ databaseName: string;
822
+ parameterName: string;
823
+ } | {
824
+ type: 'EnumCreate';
825
+ enum: DatabaseEnum;
826
+ } | {
827
+ type: 'EnumDrop';
828
+ enumName: string;
829
+ } | {
830
+ type: 'OverrideCreate';
831
+ override: DatabaseOverride;
832
+ } | {
833
+ type: 'OverrideUpdate';
834
+ override: DatabaseOverride;
835
+ } | {
836
+ type: 'OverrideDrop';
837
+ overrideName: string;
838
+ });
839
+
840
+ /**
841
+ * Compute the difference between two database schemas
842
+ */
843
+ export declare const schemaDiff: (source: DatabaseSchema, target: DatabaseSchema, options?: SchemaDiffOptions) => {
844
+ items: SchemaDiff[];
845
+ asSql: (options?: SchemaDiffToSqlOptions) => string[];
846
+ asHuman: () => string[];
847
+ };
848
+
849
+ export declare type SchemaDiffOptions = BaseContextOptions & {
850
+ tables?: IgnoreOptions;
851
+ columns?: IgnoreOptions;
852
+ indexes?: IgnoreOptions;
853
+ triggers?: IgnoreOptions;
854
+ constraints?: IgnoreOptions;
855
+ functions?: IgnoreOptions;
856
+ enums?: IgnoreOptions;
857
+ extensions?: IgnoreOptions;
858
+ parameters?: IgnoreOptions;
859
+ overrides?: IgnoreOptions;
860
+ };
861
+
862
+ /**
863
+ * Convert schema diffs into SQL statements
864
+ */
865
+ export declare const schemaDiffToSql: (items: SchemaDiff[], options?: SchemaDiffToSqlOptions) => string[];
866
+
867
+ export declare type SchemaDiffToSqlOptions = BaseContextOptions & {
868
+ comments?: boolean;
869
+ };
870
+
871
+ /**
872
+ * Load schema from code (decorators, etc)
873
+ */
874
+ export declare const schemaFromCode: (options?: SchemaFromCodeOptions) => DatabaseSchema;
875
+
876
+ export declare type SchemaFromCodeOptions = BaseContextOptions & {
877
+ /** automatically create indexes on foreign key columns */
878
+ createForeignKeyIndexes?: boolean;
879
+ reset?: boolean;
880
+ functions?: boolean;
881
+ extensions?: boolean;
882
+ parameters?: boolean;
883
+ overrides?: boolean;
884
+ };
885
+
886
+ /**
887
+ * Load schema from a database url
888
+ */
889
+ export declare const schemaFromDatabase: (database: DatabaseLike, options?: SchemaFromDatabaseOptions) => Promise<DatabaseSchema>;
890
+
891
+ export declare type SchemaFromDatabaseOptions = BaseContextOptions;
892
+
893
+ /** Table comments here */
894
+ export declare const Table: (options?: string | TableOptions) => ClassDecorator;
895
+
896
+ declare type TableMetadata = {
897
+ options: TableOptions;
898
+ object: Function;
899
+ methodToColumn: Map<string | symbol, DatabaseColumn>;
900
+ };
901
+
902
+ export declare type TableOptions = {
903
+ name?: string;
904
+ primaryConstraintName?: string;
905
+ synchronize?: boolean;
906
+ };
907
+
908
+ export declare type Timestamp = ColumnType_2<Date, Date | string, Date | string>;
909
+
910
+ export declare const Trigger: (options: TriggerOptions) => ClassDecorator;
911
+
912
+ export declare type TriggerAction = 'insert' | 'update' | 'delete' | 'truncate';
913
+
914
+ export declare const TriggerFunction: (options: TriggerFunctionOptions) => ClassDecorator;
915
+
916
+ export declare type TriggerFunctionOptions = Omit<TriggerOptions, 'functionName'> & {
917
+ function: DatabaseFunction;
918
+ };
919
+
920
+ export declare type TriggerOptions = {
921
+ name?: string;
922
+ timing: TriggerTiming;
923
+ actions: TriggerAction[];
924
+ scope: TriggerScope;
925
+ functionName: string;
926
+ referencingNewTableAs?: string;
927
+ referencingOldTableAs?: string;
928
+ when?: string;
929
+ synchronize?: boolean;
930
+ };
931
+
932
+ export declare type TriggerScope = 'row' | 'statement';
933
+
934
+ export declare type TriggerTiming = 'before' | 'after' | 'instead of';
935
+
936
+ export declare const Unique: (options: UniqueOptions) => ClassDecorator;
937
+
938
+ export declare type UniqueOptions = {
939
+ name?: string;
940
+ columns: string[];
941
+ synchronize?: boolean;
942
+ };
943
+
944
+ export declare const UpdateDateColumn: (options?: ColumnOptions) => PropertyDecorator;
945
+
946
+ export { }