Skip to content

Commit 44c0589

Browse files
committed
Renamed foreign keys into relationships
1 parent 727280e commit 44c0589

File tree

13 files changed

+356
-329
lines changed

13 files changed

+356
-329
lines changed

plan.md

Lines changed: 209 additions & 200 deletions
Large diffs are not rendered by default.

src/packages/dumbo/src/core/schema/MIGRATION_UNIFICATION_PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ export class MigrationOrchestrator {
10981098
await this.runMigrationGroup(dumbo, grouped.tables);
10991099
await this.runMigrationGroup(dumbo, grouped.columns);
11001100
await this.runMigrationGroup(dumbo, grouped.indexes);
1101-
// Future: grouped.foreignKeys, grouped.constraints
1101+
// Future: grouped.relationships, grouped.constraints
11021102

11031103
// Update snapshot after successful migration
11041104
await this.updateSnapshot();

src/packages/dumbo/src/core/schema/components/foreignKeys/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/packages/dumbo/src/core/schema/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { TableURN } from './tableSchemaComponent';
77
export * from './columnSchemaComponent';
88
export * from './databaseSchemaComponent';
99
export * from './databaseSchemaSchemaComponent';
10-
export * from './foreignKeys';
1110
export * from './indexSchemaComponent';
11+
export * from './relationships';
1212
export * from './tableSchemaComponent';
1313
export * from './tableTypesInference';
1414

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './relationshipTypes';
2+
3+
export * from './relationshipValidation';

src/packages/dumbo/src/core/schema/components/foreignKeys/foreignKeyTypes.ts renamed to src/packages/dumbo/src/core/schema/components/relationships/relationshipTypes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
TableColumnNames,
99
TableColumns,
1010
TableSchemaComponent,
11-
} from '../';
11+
} from '..';
1212

1313
export type ExtractSchemaNames<DB> =
1414
DB extends DatabaseSchemaComponent<infer Schemas extends DatabaseSchemas>
@@ -47,12 +47,12 @@ export type AllColumnReferences<DB> =
4747
}[keyof Schemas]
4848
: never;
4949

50-
export type ForeignKeyDefinition<Columns = string, References = string> = {
50+
export type RelationshipDefinition<Columns = string, References = string> = {
5151
readonly columns: readonly Columns[];
5252
readonly references: readonly References[];
5353
};
5454

55-
export const foreignKey = <
55+
export const relationship = <
5656
const Columns extends readonly string[],
5757
const References extends readonly string[],
5858
>(
@@ -65,4 +65,4 @@ export const foreignKey = <
6565
} as const;
6666
};
6767
// eslint-disable-next-line @typescript-eslint/no-explicit-any
68-
export type AnyForeignKeyDefinition = ForeignKeyDefinition<any, any>;
68+
export type AnyRelationshipDefinition = RelationshipDefinition<any, any>;

src/packages/dumbo/src/core/schema/components/foreignKeys/foreignKeyValidation.ts renamed to src/packages/dumbo/src/core/schema/components/relationships/relationshipValidation.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import type {
33
AnyDatabaseSchemaSchemaComponent,
44
DatabaseSchemaComponent,
55
DatabaseSchemaSchemaComponent,
6-
} from '../';
6+
} from '..';
77
import type {
88
AnyTableSchemaComponent,
99
TableSchemaComponent,
1010
} from '../tableSchemaComponent';
1111
import type { TableColumnNames } from '../tableTypesInference';
1212
import type {
1313
AllColumnReferences,
14-
AnyForeignKeyDefinition,
15-
} from './foreignKeyTypes';
14+
AnyRelationshipDefinition,
15+
} from './relationshipTypes';
1616

1717
export type ValidationResult<
1818
Valid extends boolean,
@@ -21,7 +21,7 @@ export type ValidationResult<
2121

2222
type GetArrayLength<T extends readonly unknown[]> = T['length'];
2323

24-
export type ValidateForeignKeyLength<
24+
export type ValidateRelationshipLength<
2525
FK extends { columns: readonly unknown[]; references: readonly unknown[] },
2626
> =
2727
GetArrayLength<FK['columns']> extends GetArrayLength<FK['references']>
@@ -56,7 +56,7 @@ type AllInTuple<
5656
: false
5757
: true;
5858

59-
export type ValidateForeignKeyColumns<
59+
export type ValidateRelationshipColumns<
6060
FK extends { columns: readonly string[] },
6161
ValidColumns extends string,
6262
> =
@@ -81,7 +81,7 @@ type FindInvalidReferences<
8181
: Invalid
8282
: Invalid;
8383

84-
export type ValidateForeignKeyReferences<
84+
export type ValidateRelationshipReferences<
8585
FK extends { references: readonly string[] },
8686
ValidReferences extends string,
8787
> =
@@ -92,32 +92,32 @@ export type ValidateForeignKeyReferences<
9292
`Invalid foreign key references: ${FindInvalidReferences<FK['references'], ValidReferences> extends infer Invalid ? (Invalid extends string[] ? Invalid[number] : never) : never}. Available references: ${ValidReferences}`
9393
>;
9494

95-
export type ValidateSingleForeignKey<
95+
export type ValidateSingleRelationship<
9696
FK extends { columns: readonly string[]; references: readonly string[] },
9797
TableColumns extends string,
9898
ValidReferences extends string,
9999
> =
100-
ValidateForeignKeyLength<FK> extends { valid: false; error: infer E }
100+
ValidateRelationshipLength<FK> extends { valid: false; error: infer E }
101101
? ValidationResult<false, E>
102-
: ValidateForeignKeyColumns<FK, TableColumns> extends {
102+
: ValidateRelationshipColumns<FK, TableColumns> extends {
103103
valid: false;
104104
error: infer E;
105105
}
106106
? ValidationResult<false, E>
107-
: ValidateForeignKeyReferences<FK, ValidReferences> extends {
107+
: ValidateRelationshipReferences<FK, ValidReferences> extends {
108108
valid: false;
109109
error: infer E;
110110
}
111111
? ValidationResult<false, E>
112112
: ValidationResult<true>;
113113

114-
export type ValidateForeignKeyArray<
115-
FKs extends readonly AnyForeignKeyDefinition[],
114+
export type ValidateRelationshipArray<
115+
FKs extends readonly AnyRelationshipDefinition[],
116116
TableColumns extends string,
117117
ValidReferences extends string,
118118
> = FKs extends readonly []
119119
? ValidationResult<true>
120-
: ValidateSingleForeignKey<
120+
: ValidateSingleRelationship<
121121
FKs[number],
122122
TableColumns,
123123
ValidReferences
@@ -128,12 +128,12 @@ export type ValidateForeignKeyArray<
128128
? ValidationResult<false, E>
129129
: ValidationResult<true>;
130130

131-
export type ValidateTableForeignKeys<
131+
export type ValidateTableRelationships<
132132
Table extends AnyTableSchemaComponent,
133133
ValidReferences extends string,
134134
> =
135135
Table extends TableSchemaComponent<infer _Columns, infer FKs>
136-
? ValidateForeignKeyArray<
136+
? ValidateRelationshipArray<
137137
FKs,
138138
TableColumnNames<Table> & string,
139139
ValidReferences
@@ -144,7 +144,7 @@ export type ValidateTablesInSchema<
144144
Tables extends Record<string, AnyTableSchemaComponent>,
145145
ValidReferences extends string,
146146
> = {
147-
[TableName in keyof Tables]: ValidateTableForeignKeys<
147+
[TableName in keyof Tables]: ValidateTableRelationships<
148148
Tables[TableName],
149149
ValidReferences
150150
>;
@@ -156,7 +156,7 @@ export type ValidateTablesInSchema<
156156
: ValidationResult<true>
157157
: ValidationResult<true>;
158158

159-
export type ValidateSchemaForeignKeys<
159+
export type ValidateSchemaRelationships<
160160
Schema extends AnyDatabaseSchemaSchemaComponent,
161161
ValidReferences extends string,
162162
> =
@@ -168,7 +168,7 @@ export type ValidateSchemasInDatabase<
168168
Schemas extends Record<string, AnyDatabaseSchemaSchemaComponent>,
169169
ValidReferences extends string,
170170
> = {
171-
[SchemaName in keyof Schemas]: ValidateSchemaForeignKeys<
171+
[SchemaName in keyof Schemas]: ValidateSchemaRelationships<
172172
Schemas[SchemaName],
173173
ValidReferences
174174
>;
@@ -180,7 +180,9 @@ export type ValidateSchemasInDatabase<
180180
: ValidationResult<true>
181181
: ValidationResult<true>;
182182

183-
export type ValidateDatabaseForeignKeys<DB extends AnyDatabaseSchemaComponent> =
183+
export type ValidateDatabaseRelationships<
184+
DB extends AnyDatabaseSchemaComponent,
185+
> =
184186
DB extends DatabaseSchemaComponent<infer Schemas>
185187
? ValidateSchemasInDatabase<Schemas, AllColumnReferences<DB>>
186188
: ValidationResult<true>;

0 commit comments

Comments
 (0)