Skip to content

Commit 1ddf43f

Browse files
p-alikweiznich
authored and
Alexei Pastuchov
committed
Update wundergraph_cli/src/print_schema/snapshots/[email protected]
Co-authored-by: Georg Semmler <[email protected]>
1 parent 52397a2 commit 1ddf43f

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

wundergraph_cli/src/print_schema/mod.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,28 @@ mod tests {
121121

122122
#[cfg(feature = "mysql")]
123123
const MIGRATION: &[&str] = &[
124-
"CREATE TABLE users(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL);",
124+
r#"CREATE TABLE users(
125+
id INTEGER NOT NULL AUTO_INCREMENT,
126+
name TEXT NOT NULL,
127+
PRIMARY KEY (`id`)
128+
);"#,
125129
r#"CREATE TABLE posts(
126-
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
127-
author INTEGER REFERENCES users(id),
130+
id INTEGER NOT NULL AUTO_INCREMENT,
131+
author INTEGER DEFAULT NULL,
128132
title TEXT NOT NULL,
129-
datetime TIMESTAMP,
130-
content TEXT
133+
datetime TIMESTAMP NULL DEFAULT NULL,
134+
content TEXT,
135+
PRIMARY KEY (`id`),
136+
FOREIGN KEY (`author`) REFERENCES `users` (`id`)
131137
);"#,
132138
r#"CREATE TABLE comments(
133-
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
134-
post INTEGER REFERENCES posts(id),
135-
commenter INTEGER REFERENCES users(id),
136-
content TEXT NOT NULL
139+
id INTEGER NOT NULL AUTO_INCREMENT,
140+
post INTEGER DEFAULT NULL,
141+
commenter INTEGER DEFAULT NULL,
142+
content TEXT NOT NULL,
143+
PRIMARY KEY (`id`),
144+
FOREIGN KEY (`post`) REFERENCES `posts` (`id`),
145+
FOREIGN KEY (`commenter`) REFERENCES `users` (`id`)
137146
);"#,
138147
];
139148

wundergraph_cli/src/print_schema/snapshots/[email protected]

+10-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ table! {
2020
id -> Integer,
2121
author -> Nullable<Integer>,
2222
title -> Text,
23-
datetime -> Timestamp,
23+
datetime -> Nullable<Timestamp>,
2424
content -> Nullable<Text>,
2525
}
2626
}
@@ -44,8 +44,8 @@ allow_tables_to_appear_in_same_query!(
4444
#[primary_key(id)]
4545
pub struct Comment {
4646
id: i32,
47-
post: Option<i32>,
48-
commenter: Option<i32>,
47+
post: Option<HasOne<i32, Post>>,
48+
commenter: Option<HasOne<i32, User>>,
4949
content: String,
5050
}
5151

@@ -54,10 +54,11 @@ pub struct Comment {
5454
#[primary_key(id)]
5555
pub struct Post {
5656
id: i32,
57-
author: Option<i32>,
57+
author: Option<HasOne<i32, User>>,
5858
title: String,
59-
datetime: chrono::naive::NaiveDateTime,
59+
datetime: Option<chrono::naive::NaiveDateTime>,
6060
content: Option<String>,
61+
comments: HasMany<Comment, comments::post>,
6162
}
6263

6364
#[derive(Clone, Debug, Identifiable, WundergraphEntity)]
@@ -66,6 +67,8 @@ pub struct Post {
6667
pub struct User {
6768
id: i32,
6869
name: String,
70+
comments: HasMany<Comment, comments::commenter>,
71+
posts: HasMany<Post, posts::author>,
6972
}
7073

7174

@@ -107,6 +110,7 @@ pub struct NewPost {
107110
id: i32,
108111
author: Option<i32>,
109112
title: String,
113+
datetime: Option<chrono::naive::NaiveDateTime>,
110114
content: Option<String>,
111115
}
112116

@@ -118,7 +122,7 @@ pub struct PostChangeset {
118122
id: i32,
119123
author: Option<i32>,
120124
title: String,
121-
datetime: chrono::naive::NaiveDateTime,
125+
datetime: Option<chrono::naive::NaiveDateTime>,
122126
content: Option<String>,
123127
}
124128

@@ -147,4 +151,3 @@ wundergraph::mutation_object!{
147151
}
148152
}
149153

150-

0 commit comments

Comments
 (0)