Back

[Solved] Need help with creating database model

  • 0
  • Databases
  • Web
D5
29 Aug, 2023, 12:50

You mean to save other people's name and birthday?

TL;DR
The user needs help with creating a database model. They have a question about the maximum table size and if there is a limit to the number of documents in a collection. They also ask about programmatically setting permissions and whether they should use method 1 or method 2 for their database design. Solution: The user can use either method 1 or method 2 for their database design, depending on their specific requirements. They can programmatically set permissions when creating a document. The maximum table size is determined by the database system being used.
Dave
29 Aug, 2023, 12:50

Exactly 💯

D5
29 Aug, 2023, 12:50

Will such users be registered in the app or you add others that don't have an account associated?

Dave
29 Aug, 2023, 12:52

Only the user that is adding the names and birthdays will have an account.

D5
29 Aug, 2023, 12:54

Okay, then you can use both methods. There's not any major difference, maybe if you're going t have the ability to share in a future all birthdays an user has or other users will search other users saved birthdays it could be more convenient having everything in one collection, but if everything will remain as is, there's not a "better" approach. As said, personally I prefer just having a collection for everything, but it's just a personal choice

Dave
29 Aug, 2023, 12:56

I don't think there will not be a usecase where other users can search another users birthday list.

It's only that user that should/will be able to view their birthday lists.

Dave
29 Aug, 2023, 12:57

The model looks feasible but I don't know how to go about it in appwrite

D5
29 Aug, 2023, 13:05

Method 1:

Create a collection for each user: collection ID = user ID

Method 2 (what I do most times):

Collection named birthdays Attribute called User ID: here you store creator ID

Then you fetch all documents with the User ID = current user ID

Dave
29 Aug, 2023, 13:12

For method 1: Can I programmically create a collection?

Dave
29 Aug, 2023, 13:14

For method 2. Does this mean that all users will be using the same birthday collections which will have an attribute for user_id which I will use to query/filter with to get all the birthdays that belong to that user?

D5
29 Aug, 2023, 13:25

Only with functions

D5
29 Aug, 2023, 13:28

But in method 2 you will need too functions

Farg0
29 Aug, 2023, 16:29

I think it's still possible to use Relationships, but it's still beta

Drake
29 Aug, 2023, 16:53

I would go with method 2. That's what the article suggests. Using document level permissions, a user would only get their documents

Dave
29 Aug, 2023, 17:14

Okay, thank you

Dave
29 Aug, 2023, 17:15

So by setting permissions to access that doc to the user that created it, I am able to have numerous documents in the birthday collection but they can only be accessed by their creators.

This then leads me to another question, Can I programmatically set permissions when creating a doc?

Drake
29 Aug, 2023, 17:19

Yes you can. By default, the creator will be given read, update, and delete, but you can pass whatever permissions you want. See https://appwrite.io/docs/permissions

Dave
29 Aug, 2023, 17:21

Alright, thank you Steven. I will get back to you when I create the model and test it out.

Another question, is there a limit to the number of documents a collection can have?

Drake
29 Aug, 2023, 17:26

I think it's 74TB of data

D5
29 Aug, 2023, 17:42

I've thought there was not any hard limits. What's happens if I reach 74TB (okay, better not to dream 😆)

Drake
29 Aug, 2023, 17:43

It's mariadb max table size

D5
29 Aug, 2023, 17:44

I think that's enough for my projects and most 😅

Dave
29 Aug, 2023, 22:00

Alright, thank you.

Dave
4 Sep, 2023, 09:16

[Solved] Need help with creating database model

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more