UR::Ma...Design(3pm)

πŸ“¦
version 0.470 Β· 2 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

✨ NAME ✨

UR::Manual::SchemaDesign β€” tips for designing an efficient schema for UR πŸ’…

Okay bestie, gather round, because we're about to make your database schema immaculate. These are the little traps that will absolutely eat you alive if you don't know about them, and I refuse to let that happen to you. 🫢


🌈 Relational Databases 🌈

🚫 Avoid creating a table called type or types

So here's the tea. When ur update classes does its thing and translates your table name into a class name, type becomes YourNamespace::Type. Sounds fine, right? It is not fine. 😭

Class names that end in ::Type are reserved for class metadata. So UR is gonna go "nope, can't have that," and rename your class to YourNamespace::TypeTable to dodge the conflict.

And before you panic β€” the table_name for that class still refers to the actual table name. Your data is fine. You're fine. 🌸

Also, ur update classes will print a warning when this happens, and it renames the class automatically. So it's handled, but like... just don't name your table type or types, okay? Save yourself the little jump-scare. πŸ’€


🚫 Avoid columns named id

UR expects an object to be uniquely identified by a property called id. That's the whole vibe. ✨

So here's the problem: classes cannot have multiple ID properties where one of them is called id, because then id wouldn't uniquely identify just one of them. It's giving "which one of you is the real one" and UR does not have the bandwidth for that. πŸ™ˆ

But bestie, you can still call the column id! You just have to be sneaky about it:

  • The property name in the class metadata must be something else β€” id_id, for example πŸŽ€
  • Do this in both the has and id_by sections
  • And set the column_name to id

There you go. Column named id, property named something else, everybody's happy. πŸ‘‘


⚑ Indexes for common queries

Create indexes in your database to cover common queries. That's it, that's the tip, and it's iconic. πŸ’–

More specifically: if you routinely make queries involving non-primary keys, creating an index that includes these other columns will improve query times. Your queries will go from "loading... loading..." to main character speed. πŸ¦‹πŸ”₯


And that's the whole manual, bestie β€” go forth and design a schema so clean it makes the other devs jealous. πŸ’œ

This lil gem was written by the Perl crew and documented in perl v5.32.1, dated 2022-01-17. No cap. ⭐

πŸ“¦ where this page comes from