Today's task was to design a db schema for the following requirements:
- user should be able to register
- user should be able to record a voice note for reminder
- user should be able to type a note
- user should be able to schedule the reminder
- system should be configured for configurable frequency of reminder
- user can configure reminders for others
First I created this flowchart:
Database Design:
I choose postgresSql for this task:
Database Schema: Users table:
CREATE TABLE Users (
user_id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL, -- Hash the password
email VARCHAR(100) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Notes table:
CREATE TABLE Notes (
note_id SERIAL PRIMARY KEY,
user_id INT REFERENCES Users(user_id) ON DELETE CASCADE,
note_type ENUM('text', 'voice') NOT NULL,
note_content TEXT, -- For typed notes or voice notes metadata
voice_url VARCHAR(255), -- URL or path for voice note file
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Reminder table:
CREATE TABLE Reminders (
reminder_id SERIAL PRIMARY KEY,
user_id INT REFERENCES Users(user_id) ON DELETE CASCADE,
note_id INT REFERENCES Notes(note_id) ON DELETE CASCADE,
scheduled_time TIMESTAMP NOT NULL,
frequency VARCHAR(50) DEFAULT 'once', -- e.g., daily, weekly
recipient_user_id INT REFERENCES Users(user_id), -- To set reminders for others
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Reminder settings table:
CREATE TABLE ReminderSettings (
setting_id SERIAL PRIMARY KEY,
user_id INT REFERENCES Users(user_id) ON DELETE CASCADE,
reminder_id INT REFERENCES Reminders(reminder_id) ON DELETE CASCADE,
frequency VARCHAR(50) NOT NULL, -- Custom frequency configuration
last_notified TIMESTAMP -- Tracks last reminder sent
);
More changes/ updates to be made as the project scales!!
Test cases:
- User Registration and Login:
-Successful registration with valid credentials
-Failed registration with invalid credentials (e.g., weak password, duplicate email)
-Successful login with valid credentials
-Failed login with invalid credentials
- Note Creation and Management:
-Create a new note with title and content
-Edit an existing note
-Delete an existing note
-Search for notes by title, content, or tags
- Reminder Creation and Management:
-Create a one-time reminder
-Create a recurring reminder with different frequencies (daily, weekly, monthly, yearly)
-Set reminders for notes and independent reminders
-Edit and delete reminders
-Mark reminders as completed
-Snooze reminders
- Reminder Notifications:
-Receive timely notifications for reminders
-Configure notification preferences (e.g., sound, vibration, email)
-User Profile and Settings:
-Update user profile information (e.g., username, email, password)
-Configure notification settings
-Manage privacy settings
Specific Test Cases as per today's google meet Question:
To test the retrieval and sorting of past reminders:
- Create Multiple Past Reminders:
-Create a mix of one-time and recurring reminders with various dates and times.
- Retrieve Past Reminders:
-Use the app's functionality to view past reminders.
- Sort Past Reminders:
-Sort the reminders by date, time, or frequency.
-Verify that the sorting is correct and consistent.
- Filter Past Reminders:
-Filter the reminders by specific criteria (e.g., date range, frequency).
-Verify that the filtering is accurate.
latest work
classDiagram
class User {
- userId: String <<PRIMARY_KEY>>
- name: String
- email: String
- password: String
}
class Reminder {
- reminderId: String <<PRIMARY_KEY>>
- userId: String
- title: String
- description: String
- dueDate: DateTime
- recurrence: String
- isCompleted: Boolean
- triggeredAt: DateTime[]
}
class Notification {
- notificationId: String <<PRIMARY_KEY>>
- userId: String
- title: String
- message: String
- createdAt: DateTime
- isRead: Boolean
}
User "1" -- "*" Reminder : creates >
Reminder "1" -- "*" Notification : generates >
Explanation:
- A User can create many Reminders.
- A Reminder can generate multiple Notifications, which are sent to the user.
- The Reminder entity now includes a triggeredAt array to store timestamps of when the reminder was triggered.
- The Notification entity is simplified to represent a generic notification sent to a user.
new schema daigram:
Complex Schema daigram:
understanding the above fig:
Overall, the diagram represents a reminder system where:
- Users can create notes and reminders.
- Reminders can be assigned to specific users.
- Reminders have a due date and a frequency.
- Reminders can generate notifications.
- Users can configure their reminder preferences.
Additional Observations:
- The ReminderConfigurations entity seems to be for storing user-specific preferences for 2. reminders, such as preferred notification channels or default frequencies.
- The Frequencies entity defines different types of frequencies (e.g., daily, weekly, monthly) and their respective intervals.
Relationships:
Relationships:
- User and Notes: One-to-many relationship: A user can create multiple notes.
- User and Reminders: One-to-many relationship: A user can create multiple reminders. 3 Reminders and Notes: One-to-one relationship: A reminder is associated with one note.
- Reminders and Frequencies: Many-to-one relationship: Multiple reminders can have the same frequency.
- Reminders and Notifications: One-to-many relationship: A reminder can generate multiple notifications.
- User and ReminderConfigurations: One-to-many relationship: A user can have multiple reminder configurations.
- ReminderConfigurations and Frequencies: Many-to-one relationship: Multiple configurations can reference the same frequency.