Tag Schema: Tag tables and attributes:
Tables:
tags (each row only keeps information about a particular tag)
taggings (each row keeps information about trigger and who will receive the trigger )
products_tags (each row keeps information about tag with particular product)
tag_status (each row keeps track of a tag status)
Table: tags Attributes of tags table:
id(PK)
userId(FK users)(not null)(A tag only belongs to one user, but a user can create multiple tags. So it is one to many relationships.)
genreId(FK products_geners)(not null)
name (string) (not null)
description (string)
status (int) (0=inactive, 1=pending, 2=active, there could be more flag)
rank(int) (rank is the popularity of a particular tag), this field can be use for sorting among similar tags.)
type (int) (0=type1, 1=type2, 2=type3)
photo(string)
visibility (int) (0=public, 2=protected, 3 = private)(private means the tag only visible to assigned users of a product, protected means a tag only visible to all friends and followers of the creator of the tag, public means search by public, such as all admin created tag)
createdAt(timestamp for the tag was created at)
updatedAt (timestamp for the tag last time updated)
deletedAt (default value null) (timestamp when tag was deleted, we need this field because we will delete tag permanently from audit table).
Note: Keeping field no 10 will come handy later.
Table: taggings :
This table will be used for triggering such as broadcasting other users' feed or sending them notification. After a row inserted in this table, there will be a service who will read a row take associated action to remove the row.
Attributes of taggings table:
Id(PK)
tagId(a tagging row only belongs to a tag, but a tag can have multiple row).
taggableId (id of a user who will receive notification)
taggableType(int) (0=notification, 1=feed message)
taggerId(the person who triggered the broadcast)
taggerType(ad, product, news)
createdAt(timestamp for the tag was created at)
Table: products_tags
From user perspective a user able to create a tag after instantiating an product, so bellow table will keep information about which products has which tags.
Attributes of Attributes of taggings table:
Id (PK)
productId(FK)
tagId(FK)
Table: tag_status
When user will create a tag, a row will be created in this table with tagId and default status inactive/pending, admin will pull all tags from tags table where status=pending/inactive, after reviewing a tag if admin approved the tag then value of status in tag table will be approved and the row of tag_status will be removed. If admin is rejected then the value of the status field of tag_status table will be rejected and a trigger will be broadcasted and the receiver will send a notification to the associated user of that tag with a message that his tag is rejected .
id(PK)
senderId(Id of the user)
receiverId(Id of admin user)
createdAt(timestamp of created at)
updatedAt(timestamp of updated at)
deletedAt(timestamp of deletedAt) default value null
expiredAt (if a tag never gets approved it will expire after a certain time for removing its information from the database. If a rejected tag gets updated by user then expiredAt will reset to new future time)
status
Message (string varchar(256)) (message for user)