11import fs from 'node:fs' ;
22import path from 'node:path' ;
33import { describe , expect , it } from 'vitest' ;
4- import { createFormattedProject , createProject , getDefaultPrelude , runCli } from '../utils' ;
4+ import { createProject , getDefaultPrelude , runCli } from '../utils' ;
55import { formatDocument } from '@zenstackhq/language' ;
66import { getTestDbProvider } from '@zenstackhq/testtools' ;
77
@@ -10,7 +10,7 @@ const getSchema = (workDir: string) => fs.readFileSync(path.join(workDir, 'zenst
1010describe ( 'DB pull - Common features (all providers)' , ( ) => {
1111 describe ( 'Pull from zero - restore complete schema from database' , ( ) => {
1212 it ( 'should restore basic schema with all supported types' , async ( ) => {
13- const { workDir, schema } = await createFormattedProject (
13+ const { workDir, schema } = await createProject (
1414 `model User {
1515 id Int @id @default(autoincrement())
1616 email String @unique
@@ -43,7 +43,7 @@ describe('DB pull - Common features (all providers)', () => {
4343 } ) ;
4444
4545 it ( 'should restore schema with relations' , async ( ) => {
46- const { workDir, schema } = await createFormattedProject (
46+ const { workDir, schema } = await createProject (
4747 `model Post {
4848 id Int @id @default(autoincrement())
4949 title String
@@ -69,7 +69,7 @@ model User {
6969 } ) ;
7070
7171 it ( 'should restore schema with many-to-many relations' , async ( ) => {
72- const { workDir, schema } = await createFormattedProject (
72+ const { workDir, schema } = await createProject (
7373 `model Post {
7474 id Int @id @default(autoincrement())
7575 title String
@@ -103,7 +103,7 @@ model Tag {
103103 } ) ;
104104
105105 it ( 'should restore one-to-one relation when FK is the single-column primary key' , async ( ) => {
106- const { workDir, schema } = await createFormattedProject (
106+ const { workDir, schema } = await createProject (
107107 `model Profile {
108108 user User @relation(fields: [id], references: [id], onDelete: Cascade)
109109 id Int @id @default(autoincrement())
@@ -128,7 +128,7 @@ model User {
128128 } ) ;
129129
130130 it ( 'should restore schema with indexes and unique constraints' , async ( ) => {
131- const { workDir, schema } = await createFormattedProject (
131+ const { workDir, schema } = await createProject (
132132 `model User {
133133 id Int @id @default(autoincrement())
134134 email String @unique
@@ -155,7 +155,7 @@ model User {
155155 } ) ;
156156
157157 it ( 'should restore schema with composite primary keys' , async ( ) => {
158- const { workDir, schema } = await createFormattedProject (
158+ const { workDir, schema } = await createProject (
159159 `model UserRole {
160160 userId String
161161 role String
@@ -176,7 +176,7 @@ model User {
176176 } ) ;
177177
178178 it ( 'should preserve Decimal and Float default value precision' , async ( ) => {
179- const { workDir, schema } = await createFormattedProject (
179+ const { workDir, schema } = await createProject (
180180 `model Product {
181181 id Int @id @default(autoincrement())
182182 price Decimal @default(99.99)
@@ -202,7 +202,7 @@ model User {
202202
203203 describe ( 'Pull with existing schema - preserve schema features' , ( ) => {
204204 it ( 'should preserve field and table mappings' , async ( ) => {
205- const { workDir, schema } = await createFormattedProject (
205+ const { workDir, schema } = await createProject (
206206 `model User {
207207 id Int @id @default(autoincrement())
208208 email String @unique @map('email_address')
@@ -220,7 +220,7 @@ model User {
220220 } ) ;
221221
222222 it ( 'should not modify a comprehensive schema with all features' , async ( ) => {
223- const { workDir, schema } = await createFormattedProject ( `model User {
223+ const { workDir, schema } = await createProject ( `model User {
224224 id Int @id @default(autoincrement())
225225 email String @unique @map('email_address')
226226 name String? @default('Anonymous')
@@ -308,7 +308,7 @@ enum users_role {
308308 } ) ;
309309
310310 it ( 'should preserve imports when pulling with multi-file schema' , async ( ) => {
311- const workDir = createProject ( '' , { customPrelude : true } ) ;
311+ const { workDir } = await createProject ( '' , { customPrelude : true } ) ;
312312 const schemaPath = path . join ( workDir , 'zenstack/schema.zmodel' ) ;
313313 const modelsDir = path . join ( workDir , 'zenstack/models' ) ;
314314
@@ -364,7 +364,7 @@ model Post {
364364 describe ( 'Pull should update existing field definitions when database changes' , ( ) => {
365365 it ( 'should update field type when database column type changes' , async ( ) => {
366366 // Step 1: Create initial schema with String field
367- const { workDir } = await createFormattedProject (
367+ const { workDir } = await createProject (
368368 `model User {
369369 id Int @id @default(autoincrement())
370370 email String @unique
@@ -405,7 +405,7 @@ model User {
405405
406406 it ( 'should update field optionality when database column nullability changes' , async ( ) => {
407407 // Step 1: Create initial schema with required field
408- const { workDir } = await createFormattedProject (
408+ const { workDir } = await createProject (
409409 `model User {
410410 id Int @id @default(autoincrement())
411411 email String @unique
@@ -446,7 +446,7 @@ model User {
446446
447447 it ( 'should update default value when database default changes' , async ( ) => {
448448 // Step 1: Create initial schema with default value
449- const { workDir } = await createFormattedProject (
449+ const { workDir } = await createProject (
450450 `model User {
451451 id Int @id @default(autoincrement())
452452 email String @unique
@@ -494,7 +494,7 @@ describe('DB pull - PostgreSQL specific features', () => {
494494 skip ( ) ;
495495 return ;
496496 }
497- const { workDir, schema } = await createFormattedProject (
497+ const { workDir, schema } = await createProject (
498498 `model User {
499499 id Int @id @default(autoincrement())
500500 email String @unique
@@ -511,13 +511,13 @@ model Post {
511511
512512 @@schema('content')
513513}` ,
514- { provider : 'postgresql' , extra :{ schemas : [ 'public' , 'content' , 'auth' ] } } ,
514+ { provider : 'postgresql' , datasourceFields :{ schemas : [ 'public' , 'content' , 'auth' ] } } ,
515515 ) ;
516516 runCli ( 'db push' , workDir ) ;
517517
518518 const schemaFile = path . join ( workDir , 'zenstack/schema.zmodel' ) ;
519519
520- fs . writeFileSync ( schemaFile , getDefaultPrelude ( { provider : 'postgresql' , extra :{ schemas : [ 'public' , 'content' , 'auth' ] } } ) ) ;
520+ fs . writeFileSync ( schemaFile , getDefaultPrelude ( { provider : 'postgresql' , datasourceFields :{ schemas : [ 'public' , 'content' , 'auth' ] } } ) ) ;
521521 runCli ( 'db pull --indent 4' , workDir ) ;
522522
523523 const restoredSchema = getSchema ( workDir ) ;
@@ -530,7 +530,7 @@ model Post {
530530 skip ( ) ;
531531 return ;
532532 }
533- const { workDir, schema } = await createFormattedProject (
533+ const { workDir, schema } = await createProject (
534534 `model User {
535535 id Int @id @default(autoincrement())
536536 email String @unique
@@ -565,7 +565,7 @@ enum UserRole {
565565 skip ( ) ;
566566 return ;
567567 }
568- const { workDir, schema } = await createFormattedProject (
568+ const { workDir, schema } = await createProject (
569569 `model User {
570570 id Int @id @default(autoincrement())
571571 email String @unique
@@ -593,7 +593,7 @@ enum UserStatus {
593593 INACTIVE
594594 SUSPENDED
595595}` ,
596- { provider : 'postgresql' , extra :{ schemas : [ 'public' , 'content' , 'auth' ] } } ,
596+ { provider : 'postgresql' , datasourceFields :{ schemas : [ 'public' , 'content' , 'auth' ] } } ,
597597 ) ;
598598 runCli ( 'db push' , workDir ) ;
599599
@@ -613,7 +613,7 @@ enum UserStatus {
613613 // This test verifies the mapping works correctly.
614614 // Note: Default native types (jsonb for Json, bytea for Bytes) are not added when pulling from zero
615615 // because they match the default database type for that field type.
616- const { workDir } = await createFormattedProject (
616+ const { workDir } = await createProject (
617617 `model TypeTest {
618618 id Int @id @default(autoincrement())
619619 smallNumber Int @db.SmallInt()
@@ -666,14 +666,14 @@ describe('DB pull - SQL specific features', () => {
666666 return ;
667667 }
668668
669- const { workDir, schema } = await createFormattedProject (
669+ const { workDir, schema } = await createProject (
670670 `model User {
671671 id Int @id @default(autoincrement())
672672 email String @unique
673- status User_status @default(ACTIVE)
673+ status UserStatus @default(ACTIVE)
674674}
675675
676- enum User_status {
676+ enum UserStatus {
677677 ACTIVE
678678 INACTIVE
679679 SUSPENDED
0 commit comments