Rancang Rantang — Database

Move Mbak Nuning's catering order book into a real Postgres and MongoDB: ERDs, relations, documents. 14 levels, right in the browser.

What you learn in this game

Database design is deciding, before writing code, what data is kept, which tables it is split into, what their columns are, and how the tables connect. In this game a real PostgreSQL 18 runs in your browser, and in the document chapter you read the record of a real MongoDB server. What is graded is what the database answers and stores, not how your code is written.

A tidy design gives each thing its own table: customers, dishes, orders. An order keeps only the identifiers (pelanggan_id, menu_id) that point at the other tables. Once every fact lives in one place, changing it takes one row. The design in the book is written as a Mermaid erDiagram, diagram text that many work tools read. The kitchen chalkboard draws it.

A database design usually goes through three stages. Conceptual: which things there are and how they relate, usually drawn as an ER diagram. Logical: tables and their columns, not yet caring which DBMS. Physical: written for one DBMS, with its data types, automatic numbers and indexes. A DBMS (Database Management System) is the software that keeps a database: SQLite, MySQL, PostgreSQL. Each DBMS has its own SQL dialect.

In crow's foot each end of a line gives a number: || exactly one, o| zero or one, |{ one or many, o{ zero or many. A circle means there may be none, a bar means at least one, a crow’s foot means many. In Mermaid the left end is written mirrored: |o, }|, }o. A line is read from the end touching the thing being counted.

A foreign key is a column whose values must exist in another table’s key. REFERENCES makes Postgres refuse a row that points at something that does not exist. When a diagram becomes tables, things become tables, attributes become columns, and each one-to-many line becomes one foreign key.

Two things can be many to many: one student joins many clubs, one club has many students. A table cannot keep a list in one cell, so the relationship is split through a junction table: one row for each pair, with two foreign keys.