𝗕𝘂𝗶𝗹𝗱𝗶𝗻𝗴 𝗮 𝗣𝗿𝗼𝗷𝗲𝗰𝘁 𝗠𝗮𝗻𝗮𝗴𝗲𝗺𝗲𝗻𝘁 𝗧𝗼𝗼𝗹 𝘄𝗶𝘁𝗵 𝗣𝗿𝗶𝘀𝗺𝗮
I am building a collaborative project management tool like Trello.
I am using React, Express.js, PostgreSQL, and Socket.io. Before I write any backend routes, I must design the database schema.
The schema is the foundation. If the schema is wrong, the whole app fails. Here is my breakdown of the Prisma schema design.
𝗧𝗵𝗲 𝗠𝗼𝗱𝗲𝗹𝘀
• User: Stores names, emails, and passwords. I use cuid() for IDs. This creates long, unique strings. It is better than numbers because it does not leak your user count in the URL.
• Project: Holds the project name and description. I made the description optional using a question mark.
• ProjectMember: This is a junction table. It links Users to Projects. Since one user can join many projects, and one project has many users, you need this middle table to manage the many-to-many relationship. I added a unique constraint to prevent the same user from joining a project twice.
• Board: Tasks live inside boards. Boards live inside projects. This hierarchy makes drag-and-drop easy. Moving a task between columns is just a single field update.
• Task: This is the core model. It has two different relations to the User model:
- An assigned user (this is optional).
- A creator (this is required). I had to name these relations explicitly so Prisma knows which is which.
• Comment: Users can leave comments on tasks. I named the relation "author" instead of "user" to keep the code readable.
• Notification: A simple model to track messages for users.
𝗧𝗲𝗰𝗵𝗻𝗶𝗰𝗮𝗹 𝗟𝗲𝘀𝘀𝗼𝗻𝘀 𝗟𝗲𝗮𝗿𝗻𝘁
I ran into several errors while building this. Watch out for these:
- Relation Names: If two fields point to the same model, you must name the relations. If you do not, Prisma will throw an error.
- Nullable Fields: If a relation is optional, you must put a question mark on both the relation field and the foreign key field.
- Syntax Errors: Prisma requires double quotes for string defaults. Single quotes will fail.
- Relation Syntax: Always use the correct syntax: @relation(fields: [localField], references: [remoteField]).
The schema is now migrated. Next, I will build the Express backend and Socket.io setup for real-time updates.
பூஜ்ஜியத்திலிருந்து ஒரு திட்ட மேலாண்மை கருவியை உருவாக்குதல்: Prisma Schema-வுடன் தொடங்குதல்
பூஜ்ஜியத்திலிருந்து ஒரு திட்ட மேலாண்மை கருவியை (Project Management Tool) உருவாக்குவது, full-stack மேம்பாட்டில் (development) நிபுணத்துவம் பெற ஒரு சிறந்த வழியாகும். எங்களது இந்தத் தொடரின் முதல் பகுதியில், Prisma பயன்படுத்தி நமது பயன்பாட்டின் அடித்தளமான தரவுத்தளத் திட்டத்தை (database schema) வடிவமைப்பதில் கவனம் செலுத்துவோம்.
ஏன் Prisma?
Prisma என்பது Node.js மற்றும் TypeScript ஆகியவற்றிற்கான ஒரு நவீன ORM (Object-Relational Mapper) ஆகும். இது தரவுத்தளத்துடன் (database) தொடர்புகொள்வதை எளிமையாக்குகிறது மற்றும் தரவுத் தன்மையை (type safety) உறுதி செய்கிறது. இது தரவுத்தளத் திட்டங்களை (schemas) வரையறுப்பதற்கும், தரவுகளைக் கையாளுவதற்கும் மிகவும் சக்திவாய்ந்த மற்றும் பயனர் நட்பு இடைமுகத்தை வழங்குகிறது.
தரவுத்தளத் திட்டத்தை வடிவமைத்தல் (Designing the Schema)
நமது பயன்பாட்டிற்குத் தேவையான முக்கிய மாதிரிகளை (models) முதலில் வரையறுக்க வேண்டும். அவையாவன:
- User: பயனர்களைக் குறிக்க.
- **