views:

36

answers:

1

Best way to store comments flags in a sql db? The comments are posted on a page (mediaId), each comment can have children, comments can be hidden by the person who owns the page or by a moderator. Anyone can flag a comment, but only one category and once.

Once a comment has X amount of flags it comes to the moderator attention. If the moderator finds it fine he should not be able to clear the flags but do something so it takes amount X amount to come to his attention.

    enum FlagComment { none, offensive, spam, other, };

    command.CommandText =
         "CREATE TABLE if not media_comment( " +
         "id INTEGER PRIMARY KEY, " +
         "mediaId  INTEGER, " +
         "parentId INTEGER, " +
         "author   INTEGER, " +
         "date     DATE, " +
         "text     TEXT, " +
         "hidden   INTEGER);";
    command.ExecuteNonQuery();

    command.CommandText =
         "CREATE TABLE if not media_comment( " +
         "commentId INTEGER, " +
         "userId INTEGER, " +
         "flagType   INTEGER); ";
    command.ExecuteNonQuery();

    command.CommandText =
         "CREATE TABLE if not media_comment_mod_clear( " +
         "commentId INTEGER, " +
         "modId  INTEGER, " +
         "action INTEGER, " + //action is delete or ignore
         "flagAmount INTEGER); "; //amount of ppl who flagged before mod took action
    command.ExecuteNonQuery();
+1  A: 

I'm not sure flagAmount is the right way to go at it.

It might be better to have a flags table in which every row has a flag ID, comment ID, flag type, etc. Then, counting how many flags a comment has can be done with SQL, but you also maintain the per-flag information (e.g. type).

Assaf Lavie
Right, you need to store the user_id of person who put the flag preventing multiple flags by the same person.
Bogdan Gusiev