Menu

The biggest delete in our app is one line of raw SQL against a table our ORM does not manage
📰

The biggest delete in our app is one line of raw SQL against a table our ORM does not manage

DEV Community: typescript·Daniel Pertu·17 days ago
#muJ0Ba42
#devtotypescript#devto#dev#null#delete
Reading 0:00
15s threshold

Nakodo deletes an account like this:

await db . execute ( sql `delete from auth.users where id = ${ user . id } ` );

Enter fullscreen mode

Exit fullscreen mode

One statement, written as raw SQL because the table it names is not in our schema file and not in any of our 32 migrations. It belongs to Supabase Auth. Everything the account owns goes with it, and what goes and what stays is decided entirely by 24 foreign keys declared elsewhere.

I pulled all 24 out of the latest migration snapshot to see whether the rules were consistent. They are, more than I expected, so this is a census rather than a confession.

Twenty-four keys, two rules, no third rule

cascade 14 set null 10 restrict 0 no action 0 ( on delete ) no action 24 ( on update )

Enter fullscreen mode

Exit fullscreen mode

Every delete rule in the schema is one of two choices, and no primary key in this app is ever updated, so the update rule is uniform by default rather than by decision.

The split is not arbitrary.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.