Skip to content

PRJ2: Database Guide

Your Database

You will run your own database on your own computer while developing. But your deployed app will have its own database.


How init.sql Works

Every time you push code, your database:

  1. Gets deleted (clean slate)
  2. Gets recreated
  3. Runs your db/init.sql

Your db/init.sql should create all tables and test data:

CREATE TABLE customers (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(255)
);

CREATE TABLE orders (
    id SERIAL PRIMARY KEY,
    customer_id INTEGER REFERENCES customers(id),
    total DECIMAL(10,2)
);

INSERT INTO customers (name, email) VALUES ('Test User', 'test@example.com');

Tip

Test your SQL locally before pushing. Syntax errors will break deployment.


Using pgAdmin

pgAdmin lets you browse your deployed database in a web browser — useful for checking tables, viewing data, and debugging.

See the pgAdmin Setup guide for login and connection instructions.


FAQ

Why did my data disappear? Database resets on every deploy. This is intentional—your db/init.sql is always the source of truth.

Can I keep data between deploys? In a real life situation, it would be disastrous if production data gets lost every a deployment. Instead of resetting the database, developers do 'migrations'. However, this is not in scope of PRJ2.

My init.sql has an error? Check pgAdmin or fix your SQL and push again.