Comment

Comment by Spivak

Natural keys are great when they're someone else's synthetic keys. My Discord bots make liberal use of this.

   model: DiscordMessage
     key = discord_message_id
     key = discord_user_id
     key = discord_channel_id
     key = message_type

   model: UserData
     key = discord_user_id
     key = field_name

   model: GuildFeature
     key = discord_guild_id
     key = well_known_feature_name

   model: DiscordEvent
     key = discord_event_id
     key = discord_guild_id
This is how I was always taught to use them so I'm kinda confused what the author is getting at. If the thing you're using as a key can change and that doesn't define the row then you don't have a key. If you're at a conference where everyone has a badge number then that's a great natural key when scanning people into your workshop. If you're at Disney and everyone has a magicband with ids then you can use that as a natural key all over the place when to you that's a visitor.
parent Spivak 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton