An Interest In:
Web News this Week
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
30DaysofAppwrite : Database Design
Intro
#30DaysOfAppwrite is a month long event focused at giving developers a walk through of all of Appwrite's features, starting from the basics to more advanced features like Cloud Functions! Alongside we will also be building a fully featured Medium Clone to demonstrate how these concepts can be applied when building a real world app. We also have some exciting prizes for developers who follow along with us!
Database Design
Welcome back to another session on the Appwrite Database . We hope you have gone through the Day 15 article. It is important as we build upon the knowledge gained in Day 15 and plan and prepare the database for our demo application.
Planning Data Structure
We will use the Collection and Rules feature provided by Appwrite Database to plan the data structures needed for our application. First, let's put down the requirements of our application.
Post
A post refers to content that can be posted by any authenticated user. Anyone can signup and create a post. Our post will have title, cover image, text, published ( to signify whether the post is a draft or published) , tags, created date and id of the creator. Now we will plan this using the Rules provided by Appwrite database.
First we will create a collection as described in Day 15 and name it Posts. Then we will add following rules from console and update the collection.
- Title
- label: Title
- Key: title
- Rule Type: Text
- Required: true
- Array: false
- Cover image
- label: Cover image
- Key: cover
- Rule Type: Text
- Required: false
- Array: false
- Text
- label: Text
- Key: text
- Rule Type: Markdown
- Required: true
- Array: false
- Published
- label: Published
- Key: published
- Rule Type: Boolean
- Required: true
- Array: false
- Tags
- label: Tags
- Key: tags
- Rule Type: Text
- Required: false
- Array: true
- Created Date
- label: Created At
- Key: created_at
- Rule Type: Numeric
- Required: true
- Array: false
- User Id
- label: User Id
- Key: user_id
- Rule Type: Text
- Required: true
- Array: false
For the permissions, the read permission should be [*
] as anyone should be able to read the posts, while the write permission for this collection should be [role:member
] so that only logged in users can create a post.
Profile
We want to let our users have their profile with a public name so that we can display the author information in each post. We will also want to add a user's post as an embedded document in the collection so that we can fetch it easily with the user's profile.
Let's create another collection named Users with following rules
- User Id
- label: User
- Key: user
- Rule Type: Text
- Required: true
- Array: false
- Name
- label: Name
- Key: name
- Rule Type: Text
- Required: true
- Array: false
- Posts
- label: Posts
- Key: posts
- Rule Type: Document (Embedded)
- Required: false
- Array: true
Once you create a posts rule, you will see a section with Allowed Collections. Here, you need to select Posts.
As for the permissions, read permission should be [*
] as anyone should be able to read, and write permission can be [role:member
] so that anyone signed in can create a profile.
So, this is how easy it is to plan data structures for any application using Collections and Rules - it is very similar to traditional Relational Databases where we plan using tables and columns.
We have now planned the database required for our application, on Day 17, we will continue to use these collections in our Application.
Credits
We hope you liked this write up. You can follow #30DaysOfAppwrite on Social Media to keep up with all of our posts. The complete event timeline can be found here
Feel free to reach out to us on Discord if you would like to learn more about Appwrite, Aliens or Unicorns . Stay tuned for tomorrow's article! Until then
Original Link: https://dev.to/appwrite/30daysofappwrite-database-design-140a
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To