I’m writing an web application for users who need to be able to receive notices from administrators when they login. These notices should be displayed on their dashboard.
Once a user has read a message, they can dismiss it. New users should obviously not be shown messages before they were created.
I’m having two problems with designing the schema:
- How do I identify that a user has “dismissed” a message?
- How do new users only see messages after they’ve been created?
Here’s the table for notifications:
CREATE TABLE [dbo].[Notification]
(
[Id] [int] IDENTITY(1,1) NOT NULL,
[Message] [varchar](max) NOT NULL,
[DateCreated] [datetime] NOT NULL,
[CreatedById] [int] NOT NULL
)
For #1, I was thinking of creating a table (DismissedNotification_User) that would map between a Notification.Id and a User.Id. If a pair exists, then the user dismissed that notification. However, I’m not sure if this is the best approach (not in vs a left join)?
For #2, the easiest approach that I see is by adding a DateCreated column to users and when adding a condition onto #1 (where [DateCreated] >= [User].DateCreated).
I don’t want cookies involved because that really adds unnecessary weight to the application.
I would say that your own solutions for #1 and #2 here seem fine.
The link table to represent a ‘dismissed’ notification makes sense otherwise you end up having to create one row per user up front, to represent a notification as opposed to one notification record.
I think also for #2, having a created date for the notification and user would be a sensible option too. The other suggestions to use a ‘dismissed’ column would not enable you to only display notification AFTER a user was created if you’re reliant on the option of a linked table as you would end up with all notifications, not just those since the user existed.