SQL for noobs
I’ve been on a mission to migrate local MDX content to a Postgres, and I have basically zero SQL experience.
- Video from Syntax’s CJ - Complex Schema Design with Drizzle ORM | Common Patterns
- The accompanying github repo
Joins
Left join
Foreign keys & composite keys
JSON builder array
Behind the scenes: seeding goosebumps db
For context, goosebumps content has always been locally served MDX files. With the infra migration, I knew I needed to move content to the server. First task though, was to figure out how to render content sourced from the server, and not at build time.
So I moved the content to S3 and served it using lambda functions, and got the rendering bit sorted out.
Now it’s time for the content to actually live in a db, and not S3😄
Reset table
Everytime I seed, I’m resetting the table like so:
sql.raw(`TRUNCATE TABLE ${getTableName(table)} RESTART IDENTITY CASCADE`),
Dedicated seed script for each table
In some cases, seed order matters
Make sure to look at your relationships and see what the dependency tree is like 👀