joelanman,
@joelanman@hachyderm.io avatar

I have a database question - say you have an items table and a messages table, and messages can refer to items. If someone needs to delete an item, you can't because of the foreign reference in messages.

I know you could 'soft delete' - set a status column to deleted, but what if you really need to delete, for example because the content is illegal or the user has a legal right to delete it?

jonty,
@jonty@chaos.social avatar

@joelanman Do messages need to refer to items, or is it that you just need to get all the items attached to a message?

If not, the item should be foreign keyed to the message ID and the message has no reference to the item. That means items can be deleted but messages cannot unless they CASCADE or you delete all items first.

joelanman,
@joelanman@hachyderm.io avatar

@jonty I want to have an image of the item and a link to it in the message thread, and I also want to avoid that just disappearing. I think soft delete with replacing the contents might work

jonty,
@jonty@chaos.social avatar

@joelanman Are you saying you don't want the item to disappear if it's deleted?

joelanman,
@joelanman@hachyderm.io avatar

@jonty No just to avoid messages that refer to it disappearing in a thread, I probably haven't explained it very well

jonty,
@jonty@chaos.social avatar

@joelanman Right, then yes as I said earlier you want a foreign key from item -> message ID only. That'll do what you want!

joelanman,
@joelanman@hachyderm.io avatar

@jonty That would mean it can only be in one message though? Different users can discuss the same item

jonty,
@jonty@chaos.social avatar

@joelanman ...that was not a clear constraint ;)

If the item is deleted should it be deleted from all messages, or just one?

joelanman,
@joelanman@hachyderm.io avatar

@jonty From all, I think the soft delete and replacing the content should work, otherwise the message just disappears with no explanation

kornel,
@kornel@mastodon.social avatar

@joelanman you can change owner of the messages to a null or dummy user.

joelanman,
@joelanman@hachyderm.io avatar

@kornel yeh, I'm concerned about the ux though - that the other person would have messages just disappear. I'm leaning to soft delete, and replace contents with 'deleted' or similar

jonodrew,
@jonodrew@mastodon.social avatar

@joelanman is it important to keep the messages?

joelanman,
@joelanman@hachyderm.io avatar

@jonodrew I think it would be poor ux if your messages disappeared because the other person deleted an item... I'm thinking soft delete but replace the content with 'This was deleted' or similar

truls46,
@truls46@mastodon.social avatar

@joelanman You can define the constraint as ON DELETE CASCADE.

joelanman,
@joelanman@hachyderm.io avatar

@truls46 yeh.. but I think it would be weird ux for the other person to suddenly have messages disappear

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • ngwrru68w68
  • cubers
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • tester
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • anitta
  • Leos
  • provamag3
  • modclub
  • megavids
  • lostlight
  • All magazines