Skip to content

Shared Database

You'll run a database that two or more other people put rows into for a season, with a schema drawn from what they told you, nightly backups, and one migration done while they're using it.

About

Everything so far was yours alone. A database other people enter data into is a different thing: the schema has to survive their assumptions, the permissions have to stop them hurting each other's rows, the backups have to be real, and when the schema has to change it changes under them. A club's roster and dues, a community garden's plots and harvests, a band's gigs and payouts, a family's shared inventory, a small shop's stock. This badge is designing it from interviews, setting it up on Postgres, giving two or more people a way to enter rows (DBeaver, pgAdmin, a NocoDB or Metabase front end, a form that feeds a script, or a simple page all work), and keeping it running and backed up for three months. Hosting is a Raspberry Pi or old laptop at home with the port kept off the internet, a small VPS at 4 to 6 dollars a month, or the free tier of a hosted Postgres, which covers this size. Building the web app around it belongs to Web Building; here the badge is the database. What counts is three months of other people's rows, with backups restored and a migration done live.

At a glance

Per requirement
50 XP
Completion bonus
600 XP
Requirements
7
Takes
A season
Skill level
Advanced (years of practice)
Cost
Free
Supplies
Nothing special
Where
At home
Other people
With other people
Locked for now
Earn two more Rare badges in SQL & Databases to open this one. Log in to see how far along you are.

Requirements

  1. 1
    Interview the people who'll use it and draw the schema from what they said, not from what you assumed. Half an hour each with two or more people. Write down the five questions they most want answered and the things they currently keep on paper or in a group chat. Draw the tables from that, and show them the drawing before you type a line. Take a photo of the drawing and the question list. Photo
  2. 2
    Set it up on Postgres with one role per person and permissions that match what each one should be able to do. The people entering data get INSERT and UPDATE on their tables, the treasurer alone gets the money table, everyone gets SELECT on the views, and nobody gets the superuser. If it lives anywhere but your own home network, connections go over SSL or an SSH tunnel and the Postgres port is closed to the world. Take a screenshot of \du and the grants. Photo
  3. 3
    Give them a way in and watch the first person enter a row without your help. Whatever front end you chose, sit beside them for the first row and then step back for the second. Film the moment, or take a photo of them at it with the row appearing in your psql. Photo or video
  4. 4
    Run nightly backups with a restore drilled once a month, on a schedule you wrote down. The Restore Drill script pointed at this database, with the monthly restore done into a scratch database and the row counts compared to live. Take a screenshot of three dated restore logs. Photo
  5. 5
    Change the schema once while people are using it, without losing a row or stopping them. Someone will ask for a column you didn't draw. Write the migration, run it against last night's backup first, then run it in a transaction on the live database. Postgres can add a column with a default without rewriting the table; a rename or a split takes more care and a view that keeps the old shape working for whoever hasn't updated. Take a screenshot of the migration file and the counts before and after. Photo
  6. 6
    Find the slowest thing they do, measure it, and fix it with an index you can explain. Set log_min_duration_statement = 500 and read the log after a week of their use. Take the top offender through EXPLAIN and an index, and show the time drop. Take a screenshot of the log line before and the plan and timing after. Photo
  7. 7
    After three months, show them a report only the database could have made, and ask what they'd change. Post a photo of the people looking at it, the report with any private detail removed, and the three things they asked for next. Photo