Skip to content

Commit 6f69d64

Browse files
committed
update
1 parent e87ad18 commit 6f69d64

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/runtime/src/client/helpers/schema-db-pusher.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ export class SchemaDbPusher<Schema extends SchemaDef> {
4646
if (model.baseModel) {
4747
// base model should be created before concrete model
4848
const baseDef = requireModel(this.schema, model.baseModel);
49-
// edge: base model -> concrete model
50-
graph.push([baseDef, model]);
49+
// edge: concrete model -> base model
50+
graph.push([model, baseDef]);
5151
added = true;
5252
}
5353

5454
for (const field of Object.values(model.fields)) {
5555
// relation order
5656
if (field.relation && field.relation.fields && field.relation.references) {
5757
const targetModel = requireModel(this.schema, field.type);
58-
// edge: relation target model -> fk model
59-
graph.push([targetModel, model]);
58+
// edge: fk side -> target model
59+
graph.push([model, targetModel]);
6060
added = true;
6161
}
6262
}
@@ -67,7 +67,9 @@ export class SchemaDbPusher<Schema extends SchemaDef> {
6767
}
6868
}
6969

70-
return toposort(graph).filter((m) => !!m);
70+
return toposort(graph)
71+
.reverse()
72+
.filter((m) => !!m);
7173
}
7274

7375
private createModelTable(kysely: ToKysely<Schema>, modelDef: ModelDef) {

0 commit comments

Comments
 (0)