r/Database • • 14h ago

Advent of SQL and NoSQL – 24 challenges leading up to Christmas

Post image
7 Upvotes

Happy Holidays, r/Database!

I've noticed that most Advent of SQL events are exclusively SQL-based, and NoSQL databases are usually left out.

This project was originally supposed to be SQL-only, but after roughly 2 years of working on VisuaLeaf, I managed to build an embeddable, MongoDB-compatible database that runs entirely on the frontend, allowing you to execute MongoDB queries and aggregation pipelines directly in your browser without a database server.

Somebody tampered with Santa's Nice List, and you're the North Pole's first-ever data elf.

That's the story behind Advent of SQL & NoSQL: 24 puzzles, one a day from December 1 to 24. Every day, you get a bit more of the story and a question to answer with a query: which toys to build first, which children flipped from nice to naughty overnight, whose badge was used on the night shift, who walked through which door and when. By Christmas Eve, you'll have worked out who did it and fixed the list.

You can solve the whole thing in one of four databases, following the same story and working with the same underlying data:

  • SQLite
  • DuckDB
  • PostgreSQL
  • MongoDB (mongosh, aggregation pipelines)

More details:

  • Everything runs entirely in your browser. There's nothing to install, no backend database server, and nothing to connect to.
  • Your answer gets checked instantly, against the data you see and against hidden datasets with different values. Reading the answer off the screen and hard-coding it won't pass.
  • It gets harder as it goes. Early days cover basic filtering, grouping and joins. Later ones require window functions, recursive CTEs, relational division, advanced MongoDB aggregation pipelines and running totals.
  • Database-specific data modeling. The MongoDB version isn't just SQL tables converted into collections. It uses embedded documents, arrays and aggregation patterns that you'd actually encounter when working with MongoDB.
  • Hints and traps for each day, if you get stuck, plus a short "did you know" tip about your chosen database.

A new puzzle unlocks every day until Christmas Eve!

Pick your database here: https://visualeaf.com/advent-of-sql-and-nosql/

Completely free. No account, no installation, no database server needed.

I hope you all enjoy it, and happy holidays!


r/Database • • 12h ago

Advice on dealing with similar column patterns in schema design

5 Upvotes

When there is a similar sets of columns to include in a schema design, I see two issues that come up often, and disagreement on how to handle them. The first I'll call the "sub-type issue" and the second the "nesting issue". I wonder how different shops deal with each.

A recent example I encountered for the sub-type issue is an event tracking system where participants and witnesses are logged. Let's say there's a scuffle at the local mall and the mall cops have to document it. (Not actual domain, but close.) What you might call "key people" have many more columns associated with them, but "incidental people" just need a name and optional phone number.

My feeling is to make one table, "Participants" with with a Participant Type column (FK). But the primary DB architect decided on two tables: "Key Participants" and "Incidental Participants". In practice a person won't need to be switched between categories often; the few times it happens app users just delete the old record and create a new one. The architect's reasoning was this allows the schema to enforce required columns (not null), whereas a single table has to enforce such algorithmically, based on the Participant Type column. To me that seems kind of a weak reason because it complicates the schema. Your view? (If participants did hop categories often, then a single table would clearly be better.)

The second type, the "nesting issue" is that there is a primary location and potential secondary locations. An Event record is to have one and only one primary location, but can have many secondary. There's about 10 columns associated with a location. My feeling was to put both types in a Location table with a location-type column, but the architect instead decided to include those 10 columns in the Event table, to record the primary location. The others go into the Secondary Locations table. The architect claims it makes application programming easier because writing an event would only have to write or change one record instead of two, at least for the general Event form. Agree or disagree? What factors drive you toward one approach versus another? Thanks!


r/Database • • 12h ago

I made a free tool for designing databases with friends in real time, would love some feedback

1 Upvotes

Hey everyone!

A few months ago my friends and I started building a project together, and the first thing we needed was the database. We wanted one diagram we could all edit at the same time, like a Google Doc, but everything we tried was either paid for collaboration or just annoying to use. I know there are already many similar tools. What I couldn't find was one where our whole group could edit the same diagram live, so I focused on that.

It's called Comodel → comodel.app

You draw your tables, keys and relationships on a canvas, and everyone you share it with can edit it live. You see each other's cursors and who's working on which table, so it actually feels like working on it together instead of passing screenshots around, which is also what we were looking for.

Some stuff it can do:

Share it like a Google Doc: send a link, or invite people as viewers or editors. Friends with the link don't even need an account

Leave comments on tables or columns ("should this be nullable?"), reply, and resolve them

All the usual database things: new tables, attribute defining, keys

Import an existing database from SQL (Postgres, MySQL, SQLite, SQL Server) or DBML, so you don't start from zero

Export to PostgreSQL, DBML, or a PNG/SVG image for docs and slides

Save versions and compare them, or see the migration SQL between two versions for you

A code view if you'd rather type than drag boxes around

You can also hook it up to an agent using MCP if you want an AI to read or edit your diagram

I'm building this pretty much on my own, so any feedback means a lot, whether something's confusing, missing or just broken. Thanks for checking it out! 🙂


r/Database • • 14h ago

Testing Row-Level Security and check-then-act race conditions under connection pooling in PostgreSQL 18

1 Upvotes

One limitation of standard per-test rolled-back transactions is that they can't catch concurrency bugs across separate pooled connections—uncommitted writes aren't visible to parallel workers, and session-level SET leaks across pooled checkouts.

In our multi-tenant Postgres 18 test suite, we separated sequential unit/CRUD tests from a dedicated set of 19 parallel integration checks that fire simultaneous queries across a constrained pool (max: 5) using Promise.allSettled:

  1. Interleaved tenant contexts: Firing parallel transactions with SELECT set_config('app.current_tenant_id', $1, true) across different tenants on a small pool to verify SET LOCAL resets cleanly on commit/rollback with zero cross-tenant leakage.
  2. Parent-row locking vs. check-then-act: Comparing unguarded SELECT count(*) checks against SELECT ... FROM organizations WHERE id = $1 FOR UPDATE when concurrent requests try to claim the final seat or quota slot.
  3. Webhook idempotency under duplicate delivery: Firing identical billing event IDs concurrently to confirm 23505 unique-constraint handling cleanly short-circuits duplicate state transitions.

For those running multi-tenant Postgres in production with PgBouncer or transaction pooling, are you relying strictly on set_config(..., true) + RLS policies, or pairing it with separate database roles per service tier?

Context: Built this into B2B SaaS OS 2.0.0 (Next.js 16 + Postgres 18 multi-tenant starter with 131 tests & 19 concurrency checks for solo founders and dev agencies). If you want to click through the live workspace without signing up, the demo is here:https://www.andrady.co/demo(architecture & source athttps://www.andrady.co).