Airbnb clone, add postgres

Join the 2022 Full-Stack Web Dev Bootcamp!


This post is part of a new series where we build a clone of Airbnb with Next.js. See the first post here.

In this lesson we’re going to set up the database. We’re going to use Postgres.

See my introduction to Postgres.

You can install it locally on the computer, but I’m going the simplest route and use Railway https://railway.app.

See how to install PostgreSQL on macOS

Railway provides a super easy setup and a nice free plan.

Once you’re logged in, click provision PostgreSQL:

Then click PostgreSQL in the sidebar and the Connect tab to show the connection credentials:

We’re also going to create the first table, to host our users data.

Now in the Query tab you can enter any SQL query.

See my introduction to SQL

Now we’re going to create a new table using SQL.

Use this syntax:

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  password VARCHAR(255) NOT NULL,
  session_token VARCHAR(255),
  session_expiration TIMESTAMP
);

Now you will have the table in the system:

Next part: Implement model and DB connection

Want to become a better Web Developer? Join the 2022 Web Development Bootcamp!

⭐️⭐️⭐️ Join the 2022 Web Development Bootcamp ⭐️⭐️⭐️