|
1 | 1 | # # Example schema for simple movie review app
|
2 | 2 |
|
3 |
| -# # Users |
4 |
| -# # Suppose a user can leave reviews for movies |
5 |
| -# # user -> reviews is a one to many relationship, |
6 |
| -# # movie -> reviews is a one to many relationship |
7 |
| -# # movie <-> user is a many to many relationship |
| 3 | +# # User table is keyed by Firebase Auth UID. |
8 | 4 | # type User @table {
|
9 |
| -# id: String! @col(name: "user_auth") |
10 |
| -# username: String! @col(name: "username", dataType: "varchar(50)") |
11 |
| -# # The following are generated by the user: User! field in the Review table |
12 |
| -# # reviews_on_user |
13 |
| -# # movies_via_Review |
| 5 | +# # `@default(expr: "auth.uid")` sets it to Firebase Auth UID during insert and upsert. |
| 6 | +# id: String! @default(expr: "auth.uid") |
| 7 | +# username: String! @col(dataType: "varchar(50)") |
| 8 | +# # The `user: User!` field in the Review table generates the following one-to-many query field. |
| 9 | +# # reviews_on_user: [Review!]! |
| 10 | +# # The `Review` join table the following many-to-many query field. |
| 11 | +# # movies_via_Review: [Movie!]! |
14 | 12 | # }
|
15 | 13 |
|
16 |
| -# # Movies |
| 14 | +# # Movie is keyed by a randomly generated UUID. |
17 | 15 | # type Movie @table {
|
18 |
| -# # The below parameter values are generated by default with @table, and can be edited manually. |
19 |
| -# # implies directive `@col(name: "movie_id")`, generating a column name |
20 |
| -# id: UUID! @default(expr: "uuidV4()") |
| 16 | +# # If you do not pass a 'key' to `@table`, Data Connect automatically adds the following 'id' column. |
| 17 | +# # Feel free to uncomment and customize it. |
| 18 | +# # id: UUID! @default(expr: "uuidV4()") |
21 | 19 | # title: String!
|
22 | 20 | # imageUrl: String!
|
23 | 21 | # genre: String
|
24 | 22 | # }
|
25 | 23 |
|
26 |
| -# # Movie Metadata |
27 |
| -# # Movie - MovieMetadata is a one-to-one relationship |
| 24 | +# # MovieMetadata is a metadata attached to a Movie. |
| 25 | +# # Movie <-> MovieMetadata is a one-to-one relationship |
28 | 26 | # type MovieMetadata @table {
|
29 |
| -# # @unique indicates a 1-1 relationship |
30 |
| -# movie: Movie! @unique |
31 |
| -# # movieId: UUID <- this is created by the above reference |
| 27 | +# # @unique ensures each Movie can only one MovieMetadata. |
| 28 | +# movie: Movie! @unique |
| 29 | +# # The movie field adds the following foreign key field. Feel free to uncomment and customize it. |
| 30 | +# # movieId: UUID! |
32 | 31 | # rating: Float
|
33 | 32 | # releaseYear: Int
|
34 | 33 | # description: String
|
35 | 34 | # }
|
36 | 35 |
|
37 |
| -# # Reviews |
| 36 | +# # Reviews is a join table between User and Movie. |
| 37 | +# # It has a composite primary keys `userUid` and `movieId`. |
| 38 | +# # A user can leave reviews for many movies. A movie can have reviews from many users. |
| 39 | +# # User <-> Review is a one-to-many relationship |
| 40 | +# # Movie <-> Review is a one-to-many relationship |
| 41 | +# # Movie <-> User is a many-to-many relationship |
38 | 42 | # type Review @table(name: "Reviews", key: ["movie", "user"]) {
|
39 |
| -# id: UUID! @default(expr: "uuidV4()") |
40 | 43 | # user: User!
|
| 44 | +# # The user field adds the following foreign key field. Feel free to uncomment and customize it. |
| 45 | +# # userUid: String! |
41 | 46 | # movie: Movie!
|
| 47 | +# # The movie field adds the following foreign key field. Feel free to uncomment and customize it. |
| 48 | +# # movieId: UUID! |
42 | 49 | # rating: Int
|
43 | 50 | # reviewText: String
|
44 | 51 | # reviewDate: Date! @default(expr: "request.time")
|
|
0 commit comments