mysql - Database: mark entity (record) as deleted for certain users -
given database table records multiple users in application can see, efficient way mark record deleted multiple users without deleting record (soft delete)?
requirements:
- multiple users should able mark record deleted
- when user marks record deleted, user b, c, d... should still able see until mark deleted themselves
- an administrative user should able mark record deleted record no longer visible others.
i've thought following example curious see other programmers do.
table: entity
+----------------+---------------+--------+ | id | data | active | | (int, primary) | (varchar) | (int) | +----------------+---------------+--------+ | 1 | foo | 1 | <-- record active (visible) | 2 | bar | 0 | <-- no user can see record +----------------+---------------+--------+
an administrative user set active
flag 0 remove record scope of users.
table: entity_deleted_user
+----------------+----------------+ | entity_id | user_id | | (int, primary) | (int, primary) | +----------------+----------------+ | 1 | 100 | <-- | 1 | 150 | <-- users 100, 150 , 37 can not see entity 1 | 1 | 37 | <-- +----------------+----------------+
is there more efficient way this?
what you've described how in relational manner. it's one-to-many mapping: attempting map state of 1 item (the entity) many (the users). ability of admin override status applies entity, should in entity table.
an alternative -and non-relational- method use single integer field bit set in entity table, each bit representing deleted entity status of individual user. remove need entity_deleted_user table (and admin set bits hide everyone) scheme has many disadvantages (limited user count, no referential integrity, etc).
Comments
Post a Comment