@@ -11,51 +11,18 @@ const generator = new ZModelCodeGenerator({
1111 indent : 4 ,
1212} ) ;
1313
14- describe ( 'DB pull' , ( ) => {
14+ describe ( 'DB pull - Sqlite specific ' , ( ) => {
1515 it ( "simple schema - pull shouldn't modify the schema" , ( ) => {
16- const workDir = createProject (
17- `model User {
18- id String @id @default(cuid())
19- email String @unique @map("email_address")
20- name String? @default("Anonymous")
21- role Role @default(USER)
22- profile Profile?
23- shared_profile Profile? @relation("shared")
24- posts Post[]
25- createdAt DateTime @default(now())
26- updatedAt DateTime @updatedAt
27- jsonData Json?
28- balance Decimal @default(0.00)
29- isActive Boolean @default(true)
30- bigCounter BigInt @default(0)
31- bytes Bytes?
32-
33- @@index([role])
34- @@map("users")
35- }
36-
37- model Profile {
38- id Int @id @default(autoincrement())
39- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
40- userId String @unique
41- user_shared User @relation("shared", fields: [shared_userId], references: [id], onDelete: Cascade)
42- shared_userId String @unique
43- bio String?
44- avatarUrl String?
45-
46- @@map("profiles")
47- }
48-
16+ const workDir = createProject ( `
4917model Post {
50- id Int @id @default(autoincrement() )
18+ id Int @id @default(1 )
5119 author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
5220 authorId String
5321 title String
5422 content String?
5523 published Boolean @default(false)
5624 tags PostTag[]
5725 createdAt DateTime @default(now())
58- updatedAt DateTime @updatedAt
5926 slug String
6027 score Float @default(0.0)
6128 metadata Json?
@@ -65,16 +32,6 @@ model Post {
6532 @@map("posts")
6633}
6734
68- model Tag {
69- id Int @id @default(autoincrement())
70- name String @unique
71- posts PostTag[]
72- createdAt DateTime @default(now())
73-
74- @@index([name], name: "tag_name_idx")
75- @@map("tags")
76- }
77-
7835model PostTag {
7936 post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
8037 postId Int
@@ -87,10 +44,45 @@ model PostTag {
8744 @@map("post_tags")
8845}
8946
90- enum Role {
91- USER
92- ADMIN
93- MODERATOR
47+ model Profile {
48+ id Int @id @default(1)
49+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
50+ userId String @unique
51+ user_shared User @relation("shared", fields: [shared_userId], references: [id], onDelete: Cascade)
52+ shared_userId String @unique
53+ bio String?
54+ avatarUrl String?
55+
56+ @@map("profiles")
57+ }
58+
59+ model Tag {
60+ id Int @id @default(1)
61+ name String @unique
62+ posts PostTag[]
63+ createdAt DateTime @default(now())
64+
65+ @@index([name], name: "tag_name_idx")
66+ @@map("tags")
67+ }
68+
69+ model User {
70+ id String @id @default(cuid())
71+ email String @unique @map("email_address")
72+ name String? @default("Anonymous")
73+ role String @default("USER")
74+ profile Profile?
75+ shared_profile Profile? @relation("shared")
76+ posts Post[]
77+ createdAt DateTime @default(now())
78+ jsonData Json?
79+ balance Decimal @default(0.00)
80+ isActive Boolean @default(true)
81+ bigCounter BigInt @default(0)
82+ bytes Bytes?
83+
84+ @@index([role])
85+ @@map("users")
9486}` ,
9587 ) ;
9688 runCli ( 'format' , workDir ) ;
@@ -104,74 +96,69 @@ enum Role {
10496 it ( 'simple schema - pull shouldn recreate the schema.zmodel' , async ( ) => {
10597 const workDir = createProject (
10698 `model Post {
107- id Int @id @default(autoincrement() )
99+ id Int @id @default(1 )
108100 authorId String
109101 title String
110102 content String?
111103 published Boolean @default(false)
112104 createdAt DateTime @default(now())
113- updatedAt DateTime @updatedAt
114105 slug String
115106 score Float @default(0.0)
116107 metadata Json?
117- author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
118- PostTag PostTag[]
108+ user User @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate : Cascade)
109+ postTag PostTag[]
119110
120111 @@unique([authorId, slug])
121112 @@index([authorId, published])
122113}
123114model PostTag {
124- post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
125115 postId Int
126- tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
127116 tagId Int
128117 assignedAt DateTime @default(now())
129118 note String? @default("initial")
119+ post Post @relation(fields: [postId], references: [id], onDelete: Cascade, onUpdate: Cascade)
120+ tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade, onUpdate: Cascade)
130121
131122 @@id([postId, tagId])
132123}
124+
125+ model Profile {
126+ id Int @id @default(1)
127+ userId String @unique
128+ sharedUserId String @unique @map("shared_userId")
129+ bio String?
130+ avatarUrl String?
131+
132+ profileUserId User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
133+ profileSharedUserId User @relation("shared", fields: [sharedUserId], references: [id], onDelete: Cascade, onUpdate: Cascade)
134+ }
135+
136+ model Tag {
137+ id Int @id @default(1)
138+ name String @unique
139+ createdAt DateTime @default(now())
140+ postTag PostTag[]
141+
142+ @@index([name], map: "tag_name_idx")
143+ }
144+
133145model User {
134- id String @id @default(cuid())
146+ id String @id
135147 email String @unique
136148 name String? @default("Anonymous")
137- role Role @default(USER)
138- profile Profile?
139- shared_profile Profile? @relation("shared")
140- posts Post[]
149+ role String @default("USER")
141150 createdAt DateTime @default(now())
142- updatedAt DateTime @updatedAt
143151 jsonData Json?
152+
144153 balance Decimal @default(0.00)
145154 isActive Boolean @default(true)
146155 bigCounter BigInt @default(0)
147156 bytes Bytes?
157+ post Post[]
158+ profileUserId Profile?
159+ profileSharedUserId Profile? @relation("shared")
148160
149161 @@index([role])
150- }
151-
152- model Profile {
153- id Int @id @default(autoincrement())
154- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
155- userId String @unique
156- user_shared User @relation("shared", fields: [shared_userId], references: [id], onDelete: Cascade)
157- shared_userId String @unique
158- bio String?
159- avatarUrl String?
160- }
161-
162- model Tag {
163- id Int @id @default(autoincrement())
164- name String @unique
165- posts PostTag[]
166- createdAt DateTime @default(now())
167-
168- @@index([name], name: "tag_name_idx")
169- }
170-
171- enum Role {
172- USER
173- ADMIN
174- MODERATOR
175162}` ,
176163 ) ;
177164 console . log ( workDir )
0 commit comments