Agent Wranglers

Schema design Required

Give every row a stable key

Give every table a primary key that never changes. Never use a value people can edit, such as an email or a name, as the key.

How to do it

Use a generated number or a UUID as the primary key. Keep natural identifiers as separate UNIQUE columns, so a customer can change their email without breaking references. Prefer UUID version 7 over random version 4 when keys are created in many places, because time-ordered keys keep indexes compact.

How to check

Every table has a primary key, and no primary key column is updated anywhere in the code.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/schema-design/stable-keys.