Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit d616524

Browse files
committed
fix: address PR comments
1 parent a1a4fdc commit d616524

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/cli/src/actions/db.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from './action-utils';
1515
import { consolidateEnums, syncEnums, syncRelation, syncTable, type Relation } from './pull';
1616
import { providers as pullProviders } from './pull/provider';
17-
import { getDatasource, getDbName, getRelationFieldsKey, getRelationFkName } from './pull/utils';
17+
import { getDatasource, getDbName, getRelationFieldsKey, getRelationFkName, isDatabaseManagedAttribute } from './pull/utils';
1818
import type { DataSourceProviderType } from '@zenstackhq/schema';
1919
import { CliError } from '../cli-error';
2020

@@ -461,12 +461,13 @@ async function runPull(options: PullOptions) {
461461
}
462462
return;
463463
}
464+
464465
// Track deleted attributes (in original but not in new)
465466
originalField.attributes
466467
.filter(
467468
(attr) =>
468-
!f.attributes.find((d) => d.decl.$refText === attr.decl.$refText) &&
469-
(['@relation'].includes(attr.decl.$refText) || attr.decl.$refText.startsWith('@db.')),
469+
!f.attributes.find((d) => d.decl.$refText === attr.decl.$refText) &&
470+
isDatabaseManagedAttribute(attr.decl.$refText),
470471
)
471472
.forEach((attr) => {
472473
const field = attr.$container;
@@ -482,7 +483,7 @@ async function runPull(options: PullOptions) {
482483
.filter(
483484
(attr) =>
484485
!originalField.attributes.find((d) => d.decl.$refText === attr.decl.$refText) &&
485-
(['@relation'].includes(attr.decl.$refText) || attr.decl.$refText.startsWith('@db.')),
486+
isDatabaseManagedAttribute(attr.decl.$refText),
486487
)
487488
.forEach((attr) => {
488489
// attach the new attribute to the original field

packages/cli/src/actions/pull/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export function getAttribute(model: Model, attrName: string) {
2828
| undefined;
2929
}
3030

31+
export function isDatabaseManagedAttribute(name: string) {
32+
return ['@relation', '@id', '@unique'].includes(name) || name.startsWith('@db.');
33+
}
34+
3135
export function getDatasource(model: Model) {
3236
const datasource = model.declarations.find((d) => d.$type === 'DataSource');
3337
if (!datasource) {

packages/cli/test/db/pull.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,8 @@ enum Status {
12631263

12641264
const restoredSchema = getSchema(workDir);
12651265
expect(restoredSchema).contains(`model User {
1266-
id Int @id @default(autoincrement())
1267-
email String @unique
1266+
id Int @id @default(autoincrement())
1267+
email String @unique
12681268
status Status @default(ACTIVE)
12691269
}`);
12701270

0 commit comments

Comments
 (0)