@sedrino/db-schema 0.1.1 → 0.1.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/README.md +62 -6
- package/dist/cli.js +1904 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +365 -85
- package/dist/index.js +1108 -187
- package/dist/index.js.map +1 -1
- package/docs/cli.md +93 -0
- package/docs/expressions-and-transforms.md +165 -0
- package/docs/index.md +5 -2
- package/docs/migrations.md +183 -3
- package/docs/planning-and-apply.md +200 -0
- package/docs/relations.md +130 -0
- package/docs/schema-document.md +62 -0
- package/package.json +3 -2
- package/src/apply.ts +67 -0
- package/src/cli.ts +105 -7
- package/src/drizzle.ts +348 -1
- package/src/index.ts +38 -1
- package/src/migration.ts +315 -3
- package/src/operations.ts +278 -0
- package/src/planner.ts +7 -190
- package/src/project.ts +157 -1
- package/src/sql-expression.ts +123 -0
- package/src/sqlite.ts +150 -9
- package/src/transforms.ts +94 -0
- package/src/utils.ts +54 -0
package/dist/index.d.ts
CHANGED
|
@@ -379,6 +379,19 @@ type MigrationMeta = {
|
|
|
379
379
|
name: string;
|
|
380
380
|
description?: string;
|
|
381
381
|
};
|
|
382
|
+
type MigrationSqlExpression = {
|
|
383
|
+
sql: string;
|
|
384
|
+
};
|
|
385
|
+
type AlterFieldPatch = {
|
|
386
|
+
logical?: LogicalTypeSpec;
|
|
387
|
+
storage?: StorageSpec;
|
|
388
|
+
column?: string;
|
|
389
|
+
nullable?: boolean;
|
|
390
|
+
default?: DefaultSpec | null;
|
|
391
|
+
unique?: boolean;
|
|
392
|
+
description?: string | null;
|
|
393
|
+
references?: FieldReferenceSpec | null;
|
|
394
|
+
};
|
|
382
395
|
type MigrationOperation = {
|
|
383
396
|
kind: "createTable";
|
|
384
397
|
table: TableSpec;
|
|
@@ -393,6 +406,7 @@ type MigrationOperation = {
|
|
|
393
406
|
kind: "addField";
|
|
394
407
|
tableName: string;
|
|
395
408
|
field: FieldSpec;
|
|
409
|
+
backfill?: MigrationSqlExpression;
|
|
396
410
|
} | {
|
|
397
411
|
kind: "dropField";
|
|
398
412
|
tableName: string;
|
|
@@ -402,6 +416,12 @@ type MigrationOperation = {
|
|
|
402
416
|
tableName: string;
|
|
403
417
|
from: string;
|
|
404
418
|
to: string;
|
|
419
|
+
} | {
|
|
420
|
+
kind: "alterField";
|
|
421
|
+
tableName: string;
|
|
422
|
+
fieldName: string;
|
|
423
|
+
patch: AlterFieldPatch;
|
|
424
|
+
transform?: MigrationSqlExpression;
|
|
405
425
|
} | {
|
|
406
426
|
kind: "addIndex";
|
|
407
427
|
tableName: string;
|
|
@@ -429,9 +449,39 @@ type FieldOptions = {
|
|
|
429
449
|
storage?: StorageSpec;
|
|
430
450
|
references?: FieldReferenceSpec;
|
|
431
451
|
};
|
|
452
|
+
type BelongsToOptions = Omit<FieldOptions, "references"> & {
|
|
453
|
+
fieldName?: string;
|
|
454
|
+
referencesField?: string;
|
|
455
|
+
required?: boolean;
|
|
456
|
+
unique?: boolean;
|
|
457
|
+
index?: boolean;
|
|
458
|
+
indexName?: string;
|
|
459
|
+
onDelete?: FieldReferenceSpec["onDelete"];
|
|
460
|
+
onUpdate?: FieldReferenceSpec["onUpdate"];
|
|
461
|
+
};
|
|
462
|
+
type JunctionSideOptions = {
|
|
463
|
+
table: string;
|
|
464
|
+
fieldName?: string;
|
|
465
|
+
referencesField?: string;
|
|
466
|
+
description?: string;
|
|
467
|
+
onDelete?: FieldReferenceSpec["onDelete"];
|
|
468
|
+
onUpdate?: FieldReferenceSpec["onUpdate"];
|
|
469
|
+
};
|
|
470
|
+
type CreateJunctionTableOptions = {
|
|
471
|
+
description?: string;
|
|
472
|
+
left: JunctionSideOptions;
|
|
473
|
+
right: JunctionSideOptions;
|
|
474
|
+
unique?: boolean;
|
|
475
|
+
uniqueName?: string;
|
|
476
|
+
indexes?: boolean;
|
|
477
|
+
};
|
|
478
|
+
type FieldBuilderHooks = {
|
|
479
|
+
setBackfillSql?: (sql: string) => void;
|
|
480
|
+
};
|
|
432
481
|
declare class MutableFieldBuilder {
|
|
433
482
|
private field;
|
|
434
|
-
|
|
483
|
+
private readonly hooks;
|
|
484
|
+
constructor(field: FieldSpec, hooks?: FieldBuilderHooks);
|
|
435
485
|
required(): this;
|
|
436
486
|
nullable(): this;
|
|
437
487
|
unique(): this;
|
|
@@ -440,6 +490,8 @@ declare class MutableFieldBuilder {
|
|
|
440
490
|
references(reference: FieldReferenceSpec): this;
|
|
441
491
|
description(description: string): this;
|
|
442
492
|
column(column: string): this;
|
|
493
|
+
backfillSql(expression: string | MigrationSqlExpression): this;
|
|
494
|
+
backfill(expression: string | MigrationSqlExpression): this;
|
|
443
495
|
build(): {
|
|
444
496
|
id: string;
|
|
445
497
|
name: string;
|
|
@@ -505,6 +557,44 @@ declare class MutableFieldBuilder {
|
|
|
505
557
|
} | undefined;
|
|
506
558
|
};
|
|
507
559
|
}
|
|
560
|
+
type AlterFieldOptions = {
|
|
561
|
+
column?: string;
|
|
562
|
+
storage?: StorageSpec;
|
|
563
|
+
};
|
|
564
|
+
declare class AlterFieldBuilder {
|
|
565
|
+
readonly patch: AlterFieldPatch;
|
|
566
|
+
transform?: MigrationSqlExpression;
|
|
567
|
+
required(): this;
|
|
568
|
+
nullable(): this;
|
|
569
|
+
unique(): this;
|
|
570
|
+
notUnique(): this;
|
|
571
|
+
default(value: string | number | boolean | null): this;
|
|
572
|
+
defaultNow(): this;
|
|
573
|
+
dropDefault(): this;
|
|
574
|
+
references(reference: FieldReferenceSpec): this;
|
|
575
|
+
dropReferences(): this;
|
|
576
|
+
description(description: string): this;
|
|
577
|
+
dropDescription(): this;
|
|
578
|
+
column(column: string): this;
|
|
579
|
+
storage(storage: StorageSpec): this;
|
|
580
|
+
usingSql(expression: string | MigrationSqlExpression): this;
|
|
581
|
+
using(expression: string | MigrationSqlExpression): this;
|
|
582
|
+
logical(logical: LogicalTypeSpec, options?: AlterFieldOptions): this;
|
|
583
|
+
string(options?: AlterFieldOptions & {
|
|
584
|
+
format?: "email" | "url" | "slug";
|
|
585
|
+
}): this;
|
|
586
|
+
text(options?: AlterFieldOptions): this;
|
|
587
|
+
boolean(options?: AlterFieldOptions): this;
|
|
588
|
+
integer(options?: AlterFieldOptions): this;
|
|
589
|
+
number(options?: AlterFieldOptions): this;
|
|
590
|
+
enum(values: string[], options?: AlterFieldOptions): this;
|
|
591
|
+
json(tsType: string, options?: AlterFieldOptions): this;
|
|
592
|
+
temporalInstant(options?: AlterFieldOptions): this;
|
|
593
|
+
temporalPlainDate(options?: AlterFieldOptions): this;
|
|
594
|
+
reference(options: AlterFieldOptions & {
|
|
595
|
+
references: FieldReferenceSpec;
|
|
596
|
+
}): this;
|
|
597
|
+
}
|
|
508
598
|
declare class TableCreateBuilder {
|
|
509
599
|
private readonly tableName;
|
|
510
600
|
private readonly fields;
|
|
@@ -531,6 +621,7 @@ declare class TableCreateBuilder {
|
|
|
531
621
|
reference(fieldName: string, options: Omit<FieldOptions, "references"> & {
|
|
532
622
|
references: FieldReferenceSpec;
|
|
533
623
|
}): MutableFieldBuilder;
|
|
624
|
+
belongsTo(targetTable: string, options?: BelongsToOptions): MutableFieldBuilder;
|
|
534
625
|
index(fields: string[], options?: {
|
|
535
626
|
name?: string;
|
|
536
627
|
}): this;
|
|
@@ -558,8 +649,10 @@ declare class TableAlterBuilder {
|
|
|
558
649
|
reference(fieldName: string, options: Omit<FieldOptions, "references"> & {
|
|
559
650
|
references: FieldReferenceSpec;
|
|
560
651
|
}): MutableFieldBuilder;
|
|
652
|
+
belongsTo(targetTable: string, options?: BelongsToOptions): MutableFieldBuilder;
|
|
561
653
|
dropField(fieldName: string): this;
|
|
562
654
|
renameField(from: string, to: string): this;
|
|
655
|
+
alterField(fieldName: string, callback: (field: AlterFieldBuilder) => void): this;
|
|
563
656
|
addIndex(fields: string[], options?: {
|
|
564
657
|
name?: string;
|
|
565
658
|
}): this;
|
|
@@ -572,12 +665,96 @@ declare class TableAlterBuilder {
|
|
|
572
665
|
declare class MigrationBuilderImpl {
|
|
573
666
|
readonly operations: MigrationOperation[];
|
|
574
667
|
createTable(name: string, callback: (table: TableCreateBuilder) => void): this;
|
|
668
|
+
createJunctionTable(name: string, options: CreateJunctionTableOptions): this;
|
|
575
669
|
dropTable(tableName: string): this;
|
|
576
670
|
renameTable(from: string, to: string): this;
|
|
577
671
|
alterTable(tableName: string, callback: (table: TableAlterBuilder) => void): this;
|
|
578
672
|
}
|
|
579
673
|
declare function createMigration(meta: MigrationMeta, callback: (migration: MigrationBuilderImpl) => void): MigrationDefinition;
|
|
580
674
|
|
|
675
|
+
declare function applyOperationsToSchema(schemaInput: DatabaseSchemaDocument, operations: MigrationOperation[]): {
|
|
676
|
+
version: 1;
|
|
677
|
+
dialect: "sqlite";
|
|
678
|
+
schemaId: string;
|
|
679
|
+
tables: {
|
|
680
|
+
id: string;
|
|
681
|
+
name: string;
|
|
682
|
+
fields: {
|
|
683
|
+
id: string;
|
|
684
|
+
name: string;
|
|
685
|
+
logical: {
|
|
686
|
+
kind: "id";
|
|
687
|
+
prefix: string;
|
|
688
|
+
} | {
|
|
689
|
+
kind: "string";
|
|
690
|
+
format?: "email" | "url" | "slug" | undefined;
|
|
691
|
+
} | {
|
|
692
|
+
kind: "text";
|
|
693
|
+
} | {
|
|
694
|
+
kind: "boolean";
|
|
695
|
+
} | {
|
|
696
|
+
kind: "integer";
|
|
697
|
+
} | {
|
|
698
|
+
kind: "number";
|
|
699
|
+
} | {
|
|
700
|
+
kind: "enum";
|
|
701
|
+
values: string[];
|
|
702
|
+
} | {
|
|
703
|
+
kind: "json";
|
|
704
|
+
tsType: string;
|
|
705
|
+
} | {
|
|
706
|
+
kind: "temporal.instant";
|
|
707
|
+
} | {
|
|
708
|
+
kind: "temporal.plainDate";
|
|
709
|
+
};
|
|
710
|
+
storage: {
|
|
711
|
+
strategy: "sqlite.text";
|
|
712
|
+
column: string;
|
|
713
|
+
} | {
|
|
714
|
+
strategy: "sqlite.integer";
|
|
715
|
+
column: string;
|
|
716
|
+
} | {
|
|
717
|
+
strategy: "sqlite.real";
|
|
718
|
+
column: string;
|
|
719
|
+
} | {
|
|
720
|
+
strategy: "sqlite.temporalInstantEpochMs";
|
|
721
|
+
column: string;
|
|
722
|
+
} | {
|
|
723
|
+
strategy: "sqlite.temporalPlainDateText";
|
|
724
|
+
column: string;
|
|
725
|
+
};
|
|
726
|
+
nullable: boolean;
|
|
727
|
+
primaryKey: boolean;
|
|
728
|
+
unique: boolean;
|
|
729
|
+
default?: {
|
|
730
|
+
kind: "literal";
|
|
731
|
+
value: string | number | boolean | null;
|
|
732
|
+
} | {
|
|
733
|
+
kind: "now";
|
|
734
|
+
} | {
|
|
735
|
+
kind: "generatedId";
|
|
736
|
+
prefix: string;
|
|
737
|
+
} | undefined;
|
|
738
|
+
description?: string | undefined;
|
|
739
|
+
references?: {
|
|
740
|
+
table: string;
|
|
741
|
+
field: string;
|
|
742
|
+
onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
743
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
744
|
+
} | undefined;
|
|
745
|
+
}[];
|
|
746
|
+
indexes: {
|
|
747
|
+
fields: string[];
|
|
748
|
+
name?: string | undefined;
|
|
749
|
+
}[];
|
|
750
|
+
uniques: {
|
|
751
|
+
fields: string[];
|
|
752
|
+
name?: string | undefined;
|
|
753
|
+
}[];
|
|
754
|
+
description?: string | undefined;
|
|
755
|
+
}[];
|
|
756
|
+
};
|
|
757
|
+
|
|
581
758
|
type PlannedMigration = {
|
|
582
759
|
migrationId: string;
|
|
583
760
|
migrationName: string;
|
|
@@ -682,97 +859,76 @@ declare function materializeSchema(args: {
|
|
|
682
859
|
};
|
|
683
860
|
plans: PlannedMigration[];
|
|
684
861
|
};
|
|
685
|
-
declare function applyOperationsToSchema(schemaInput: DatabaseSchemaDocument, operations: MigrationOperation[]): {
|
|
686
|
-
version: 1;
|
|
687
|
-
dialect: "sqlite";
|
|
688
|
-
schemaId: string;
|
|
689
|
-
tables: {
|
|
690
|
-
id: string;
|
|
691
|
-
name: string;
|
|
692
|
-
fields: {
|
|
693
|
-
id: string;
|
|
694
|
-
name: string;
|
|
695
|
-
logical: {
|
|
696
|
-
kind: "id";
|
|
697
|
-
prefix: string;
|
|
698
|
-
} | {
|
|
699
|
-
kind: "string";
|
|
700
|
-
format?: "email" | "url" | "slug" | undefined;
|
|
701
|
-
} | {
|
|
702
|
-
kind: "text";
|
|
703
|
-
} | {
|
|
704
|
-
kind: "boolean";
|
|
705
|
-
} | {
|
|
706
|
-
kind: "integer";
|
|
707
|
-
} | {
|
|
708
|
-
kind: "number";
|
|
709
|
-
} | {
|
|
710
|
-
kind: "enum";
|
|
711
|
-
values: string[];
|
|
712
|
-
} | {
|
|
713
|
-
kind: "json";
|
|
714
|
-
tsType: string;
|
|
715
|
-
} | {
|
|
716
|
-
kind: "temporal.instant";
|
|
717
|
-
} | {
|
|
718
|
-
kind: "temporal.plainDate";
|
|
719
|
-
};
|
|
720
|
-
storage: {
|
|
721
|
-
strategy: "sqlite.text";
|
|
722
|
-
column: string;
|
|
723
|
-
} | {
|
|
724
|
-
strategy: "sqlite.integer";
|
|
725
|
-
column: string;
|
|
726
|
-
} | {
|
|
727
|
-
strategy: "sqlite.real";
|
|
728
|
-
column: string;
|
|
729
|
-
} | {
|
|
730
|
-
strategy: "sqlite.temporalInstantEpochMs";
|
|
731
|
-
column: string;
|
|
732
|
-
} | {
|
|
733
|
-
strategy: "sqlite.temporalPlainDateText";
|
|
734
|
-
column: string;
|
|
735
|
-
};
|
|
736
|
-
nullable: boolean;
|
|
737
|
-
primaryKey: boolean;
|
|
738
|
-
unique: boolean;
|
|
739
|
-
default?: {
|
|
740
|
-
kind: "literal";
|
|
741
|
-
value: string | number | boolean | null;
|
|
742
|
-
} | {
|
|
743
|
-
kind: "now";
|
|
744
|
-
} | {
|
|
745
|
-
kind: "generatedId";
|
|
746
|
-
prefix: string;
|
|
747
|
-
} | undefined;
|
|
748
|
-
description?: string | undefined;
|
|
749
|
-
references?: {
|
|
750
|
-
table: string;
|
|
751
|
-
field: string;
|
|
752
|
-
onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
753
|
-
onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
754
|
-
} | undefined;
|
|
755
|
-
}[];
|
|
756
|
-
indexes: {
|
|
757
|
-
fields: string[];
|
|
758
|
-
name?: string | undefined;
|
|
759
|
-
}[];
|
|
760
|
-
uniques: {
|
|
761
|
-
fields: string[];
|
|
762
|
-
name?: string | undefined;
|
|
763
|
-
}[];
|
|
764
|
-
description?: string | undefined;
|
|
765
|
-
}[];
|
|
766
|
-
};
|
|
767
862
|
|
|
768
863
|
declare function compileSchemaToDrizzle(schema: DatabaseSchemaDocument): string;
|
|
864
|
+
declare function compileSchemaToDrizzleRelations(schema: DatabaseSchemaDocument): string;
|
|
769
865
|
|
|
770
866
|
declare function compileSchemaToSqlite(schema: DatabaseSchemaDocument): string;
|
|
771
|
-
declare function renderSqliteMigration(operations: MigrationOperation[]
|
|
867
|
+
declare function renderSqliteMigration(operations: MigrationOperation[], options?: {
|
|
868
|
+
currentSchema?: DatabaseSchemaDocument;
|
|
869
|
+
}): {
|
|
772
870
|
statements: string[];
|
|
773
871
|
warnings: string[];
|
|
774
872
|
};
|
|
775
873
|
|
|
874
|
+
declare function sqlExpression(sql: string): MigrationSqlExpression;
|
|
875
|
+
declare function column(fieldName: string): MigrationSqlExpression;
|
|
876
|
+
declare function raw(sql: string): MigrationSqlExpression;
|
|
877
|
+
declare function literal(value: string | number | boolean | null): MigrationSqlExpression;
|
|
878
|
+
declare function lower(expression: MigrationSqlExpression | string): MigrationSqlExpression;
|
|
879
|
+
declare function trim(expression: MigrationSqlExpression | string): MigrationSqlExpression;
|
|
880
|
+
declare function replace(expression: MigrationSqlExpression | string, search: string, replacement: string): MigrationSqlExpression;
|
|
881
|
+
declare function cast(expression: MigrationSqlExpression | string, sqlType: "INTEGER" | "REAL" | "TEXT"): MigrationSqlExpression;
|
|
882
|
+
declare function unixepoch(expression: MigrationSqlExpression | string): MigrationSqlExpression;
|
|
883
|
+
declare function date(expression: MigrationSqlExpression | string): MigrationSqlExpression;
|
|
884
|
+
declare function multiply(expression: MigrationSqlExpression | string, factor: number): MigrationSqlExpression;
|
|
885
|
+
declare function coalesce(...expressions: Array<MigrationSqlExpression | string>): MigrationSqlExpression;
|
|
886
|
+
declare function concat(...expressions: Array<MigrationSqlExpression | string>): MigrationSqlExpression;
|
|
887
|
+
declare const sqlExpr: {
|
|
888
|
+
raw: typeof raw;
|
|
889
|
+
column: typeof column;
|
|
890
|
+
literal: typeof literal;
|
|
891
|
+
lower: typeof lower;
|
|
892
|
+
trim: typeof trim;
|
|
893
|
+
replace: typeof replace;
|
|
894
|
+
cast: typeof cast;
|
|
895
|
+
unixepoch: typeof unixepoch;
|
|
896
|
+
date: typeof date;
|
|
897
|
+
multiply: typeof multiply;
|
|
898
|
+
coalesce: typeof coalesce;
|
|
899
|
+
concat: typeof concat;
|
|
900
|
+
build(sql: string): MigrationSqlExpression;
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
type Source = string | MigrationSqlExpression;
|
|
904
|
+
type Fallback = string | number | boolean | null | MigrationSqlExpression;
|
|
905
|
+
declare function copy(fieldName: string): MigrationSqlExpression;
|
|
906
|
+
declare function lowercase(source: Source): MigrationSqlExpression;
|
|
907
|
+
declare function trimmed(source: Source): MigrationSqlExpression;
|
|
908
|
+
declare function slugFrom(source: Source, options?: {
|
|
909
|
+
separator?: string;
|
|
910
|
+
}): MigrationSqlExpression;
|
|
911
|
+
declare function concatFields(fieldNames: string[], options?: {
|
|
912
|
+
separator?: string;
|
|
913
|
+
}): MigrationSqlExpression;
|
|
914
|
+
declare function coalesceFields(fieldNames: string[], fallback?: Fallback): MigrationSqlExpression;
|
|
915
|
+
declare function epochMsFromIsoString(source: Source): MigrationSqlExpression;
|
|
916
|
+
declare function plainDateFromIsoString(source: Source): MigrationSqlExpression;
|
|
917
|
+
declare function integerFromText(source: Source): MigrationSqlExpression;
|
|
918
|
+
declare function realFromText(source: Source): MigrationSqlExpression;
|
|
919
|
+
declare const transforms: {
|
|
920
|
+
copy: typeof copy;
|
|
921
|
+
lowercase: typeof lowercase;
|
|
922
|
+
trimmed: typeof trimmed;
|
|
923
|
+
slugFrom: typeof slugFrom;
|
|
924
|
+
concatFields: typeof concatFields;
|
|
925
|
+
coalesceFields: typeof coalesceFields;
|
|
926
|
+
epochMsFromIsoString: typeof epochMsFromIsoString;
|
|
927
|
+
plainDateFromIsoString: typeof plainDateFromIsoString;
|
|
928
|
+
integerFromText: typeof integerFromText;
|
|
929
|
+
realFromText: typeof realFromText;
|
|
930
|
+
};
|
|
931
|
+
|
|
776
932
|
type SchemaStateRow = {
|
|
777
933
|
schemaHash: string;
|
|
778
934
|
schemaJson: string;
|
|
@@ -783,6 +939,18 @@ type ApplyMigrationsResult = {
|
|
|
783
939
|
currentSchema: DatabaseSchemaDocument;
|
|
784
940
|
currentSchemaHash: string;
|
|
785
941
|
};
|
|
942
|
+
type MigrationStatusResult = {
|
|
943
|
+
localMigrationIds: string[];
|
|
944
|
+
appliedMigrationIds: string[];
|
|
945
|
+
pendingMigrationIds: string[];
|
|
946
|
+
unexpectedDatabaseMigrationIds: string[];
|
|
947
|
+
schemaHash: {
|
|
948
|
+
local: string;
|
|
949
|
+
database: string | null;
|
|
950
|
+
driftDetected: boolean;
|
|
951
|
+
};
|
|
952
|
+
metadataTablesPresent: boolean;
|
|
953
|
+
};
|
|
786
954
|
type LibsqlConnectionOptions = {
|
|
787
955
|
url: string;
|
|
788
956
|
authToken?: string;
|
|
@@ -886,6 +1054,23 @@ declare function listAppliedMigrations(client: Client): Promise<{
|
|
|
886
1054
|
schemaHash: string;
|
|
887
1055
|
appliedAt: number;
|
|
888
1056
|
}[]>;
|
|
1057
|
+
declare function inspectMigrationStatus(args: {
|
|
1058
|
+
client?: Client;
|
|
1059
|
+
connection?: LibsqlConnectionOptions;
|
|
1060
|
+
migrations: MigrationDefinition[];
|
|
1061
|
+
baseSchema?: DatabaseSchemaDocument;
|
|
1062
|
+
}): Promise<{
|
|
1063
|
+
localMigrationIds: string[];
|
|
1064
|
+
appliedMigrationIds: string[];
|
|
1065
|
+
pendingMigrationIds: string[];
|
|
1066
|
+
unexpectedDatabaseMigrationIds: string[];
|
|
1067
|
+
schemaHash: {
|
|
1068
|
+
local: string;
|
|
1069
|
+
database: string | null;
|
|
1070
|
+
driftDetected: boolean;
|
|
1071
|
+
};
|
|
1072
|
+
metadataTablesPresent: boolean;
|
|
1073
|
+
}>;
|
|
889
1074
|
declare function getSchemaState(client: Client): Promise<SchemaStateRow | null>;
|
|
890
1075
|
|
|
891
1076
|
type DbProjectLayout = {
|
|
@@ -983,6 +1168,101 @@ declare function materializeProjectMigrations(layout: DbProjectLayout): Promise<
|
|
|
983
1168
|
};
|
|
984
1169
|
plans: PlannedMigration[];
|
|
985
1170
|
}>;
|
|
1171
|
+
declare function validateDbProject(layout: DbProjectLayout): Promise<{
|
|
1172
|
+
warnings: string[];
|
|
1173
|
+
expectedSnapshot: string;
|
|
1174
|
+
expectedDrizzle: string;
|
|
1175
|
+
artifacts: {
|
|
1176
|
+
snapshotExists: boolean;
|
|
1177
|
+
drizzleExists: boolean;
|
|
1178
|
+
snapshotUpToDate: boolean;
|
|
1179
|
+
drizzleUpToDate: boolean;
|
|
1180
|
+
};
|
|
1181
|
+
migrations: MigrationDefinition[];
|
|
1182
|
+
schema: {
|
|
1183
|
+
version: 1;
|
|
1184
|
+
dialect: "sqlite";
|
|
1185
|
+
schemaId: string;
|
|
1186
|
+
tables: {
|
|
1187
|
+
id: string;
|
|
1188
|
+
name: string;
|
|
1189
|
+
fields: {
|
|
1190
|
+
id: string;
|
|
1191
|
+
name: string;
|
|
1192
|
+
logical: {
|
|
1193
|
+
kind: "id";
|
|
1194
|
+
prefix: string;
|
|
1195
|
+
} | {
|
|
1196
|
+
kind: "string";
|
|
1197
|
+
format?: "email" | "url" | "slug" | undefined;
|
|
1198
|
+
} | {
|
|
1199
|
+
kind: "text";
|
|
1200
|
+
} | {
|
|
1201
|
+
kind: "boolean";
|
|
1202
|
+
} | {
|
|
1203
|
+
kind: "integer";
|
|
1204
|
+
} | {
|
|
1205
|
+
kind: "number";
|
|
1206
|
+
} | {
|
|
1207
|
+
kind: "enum";
|
|
1208
|
+
values: string[];
|
|
1209
|
+
} | {
|
|
1210
|
+
kind: "json";
|
|
1211
|
+
tsType: string;
|
|
1212
|
+
} | {
|
|
1213
|
+
kind: "temporal.instant";
|
|
1214
|
+
} | {
|
|
1215
|
+
kind: "temporal.plainDate";
|
|
1216
|
+
};
|
|
1217
|
+
storage: {
|
|
1218
|
+
strategy: "sqlite.text";
|
|
1219
|
+
column: string;
|
|
1220
|
+
} | {
|
|
1221
|
+
strategy: "sqlite.integer";
|
|
1222
|
+
column: string;
|
|
1223
|
+
} | {
|
|
1224
|
+
strategy: "sqlite.real";
|
|
1225
|
+
column: string;
|
|
1226
|
+
} | {
|
|
1227
|
+
strategy: "sqlite.temporalInstantEpochMs";
|
|
1228
|
+
column: string;
|
|
1229
|
+
} | {
|
|
1230
|
+
strategy: "sqlite.temporalPlainDateText";
|
|
1231
|
+
column: string;
|
|
1232
|
+
};
|
|
1233
|
+
nullable: boolean;
|
|
1234
|
+
primaryKey: boolean;
|
|
1235
|
+
unique: boolean;
|
|
1236
|
+
default?: {
|
|
1237
|
+
kind: "literal";
|
|
1238
|
+
value: string | number | boolean | null;
|
|
1239
|
+
} | {
|
|
1240
|
+
kind: "now";
|
|
1241
|
+
} | {
|
|
1242
|
+
kind: "generatedId";
|
|
1243
|
+
prefix: string;
|
|
1244
|
+
} | undefined;
|
|
1245
|
+
description?: string | undefined;
|
|
1246
|
+
references?: {
|
|
1247
|
+
table: string;
|
|
1248
|
+
field: string;
|
|
1249
|
+
onDelete?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
1250
|
+
onUpdate?: "cascade" | "restrict" | "set null" | "set default" | "no action" | undefined;
|
|
1251
|
+
} | undefined;
|
|
1252
|
+
}[];
|
|
1253
|
+
indexes: {
|
|
1254
|
+
fields: string[];
|
|
1255
|
+
name?: string | undefined;
|
|
1256
|
+
}[];
|
|
1257
|
+
uniques: {
|
|
1258
|
+
fields: string[];
|
|
1259
|
+
name?: string | undefined;
|
|
1260
|
+
}[];
|
|
1261
|
+
description?: string | undefined;
|
|
1262
|
+
}[];
|
|
1263
|
+
};
|
|
1264
|
+
plans: PlannedMigration[];
|
|
1265
|
+
}>;
|
|
986
1266
|
declare function writeSchemaSnapshot(schema: DatabaseSchemaDocument, snapshotPath: string): Promise<void>;
|
|
987
1267
|
declare function writeDrizzleSchema(schema: DatabaseSchemaDocument, drizzlePath: string): Promise<void>;
|
|
988
1268
|
|
|
@@ -1219,4 +1499,4 @@ declare function findField(table: {
|
|
|
1219
1499
|
} | undefined;
|
|
1220
1500
|
} | null;
|
|
1221
1501
|
|
|
1222
|
-
export { type ApplyMigrationsResult, type DatabaseSchemaDocument, type DbProjectLayout, type DefaultSpec, type FieldReferenceSpec, type FieldSpec, type ForeignKeyAction, type IndexSpec, type LibsqlConnectionOptions, type LogicalTypeSpec, type MigrationDefinition, type MigrationMeta, type MigrationOperation, type PlannedMigration, type SchemaValidationIssue, type StorageSpec, type TableSpec, type UniqueSpec, applyMigrations, applyOperationsToSchema, assertValidSchemaDocument, compileSchemaToDrizzle, compileSchemaToSqlite, createEmptySchema, createLibsqlClient, createMigration, defaultSpecSchema, fieldReferenceSpecSchema, fieldSpecSchema, findField, findTable, foreignKeyActionSchema, getSchemaState, indexSpecSchema, listAppliedMigrations, loadMigrationDefinitionsFromDirectory, logicalTypeSpecSchema, materializeProjectMigrations, materializeSchema, parseSchemaDocument, planMigration, renderSqliteMigration, resolveDbProjectLayout, schemaDocumentSchema, schemaHash, storageSpecSchema, tableSpecSchema, uniqueSpecSchema, validateSchemaDocument, writeDrizzleSchema, writeSchemaSnapshot };
|
|
1502
|
+
export { type AlterFieldPatch, type ApplyMigrationsResult, type BelongsToOptions, type CreateJunctionTableOptions, type DatabaseSchemaDocument, type DbProjectLayout, type DefaultSpec, type FieldReferenceSpec, type FieldSpec, type ForeignKeyAction, type IndexSpec, type JunctionSideOptions, type LibsqlConnectionOptions, type LogicalTypeSpec, type MigrationDefinition, type MigrationMeta, type MigrationOperation, type MigrationSqlExpression, type MigrationStatusResult, type PlannedMigration, type SchemaValidationIssue, type StorageSpec, type TableSpec, type UniqueSpec, applyMigrations, applyOperationsToSchema, assertValidSchemaDocument, cast, coalesce, coalesceFields, column, compileSchemaToDrizzle, compileSchemaToDrizzleRelations, compileSchemaToSqlite, concat, concatFields, copy, createEmptySchema, createLibsqlClient, createMigration, date, defaultSpecSchema, epochMsFromIsoString, fieldReferenceSpecSchema, fieldSpecSchema, findField, findTable, foreignKeyActionSchema, getSchemaState, indexSpecSchema, inspectMigrationStatus, integerFromText, listAppliedMigrations, literal, loadMigrationDefinitionsFromDirectory, logicalTypeSpecSchema, lower, lowercase, materializeProjectMigrations, materializeSchema, multiply, parseSchemaDocument, plainDateFromIsoString, planMigration, raw, realFromText, renderSqliteMigration, replace, resolveDbProjectLayout, schemaDocumentSchema, schemaHash, slugFrom, sqlExpr, sqlExpression, storageSpecSchema, tableSpecSchema, transforms, trim, trimmed, uniqueSpecSchema, unixepoch, validateDbProject, validateSchemaDocument, writeDrizzleSchema, writeSchemaSnapshot };
|