# Your app's database

Add a Postgres database to your app. Browse its tables, export a table as CSV and see every change WebDIY makes to it.

Store information that your app collects, such as inquiries, bookings and sign-ups, in a Postgres database. WebDIY sets it up, runs it and adds the keys your app needs. It comes with sign-up and login for your app's users, and every plan includes it.

## Before you start

To add or delete the database, you'll need Admin access to the project. You're the Admin of any project you create. Builders can browse the database and export tables.

A project has one database, and your preview and your published site both use it. That matters while you're testing (see [One database for the preview and the live site](https://web.diy/docs/database/overview#one-database-for-the-preview-and-the-live-site)).

## Add a database

When your app needs to keep data, WebDIY offers a database in the chat, on a card titled **Add a database**. A project Admin selects **Set it up**. Everyone else sees "A project admin sets this up."

You can also add one yourself:

1. Open **Tools**, then select **Database** under Data.
2. Select **Add database**.

> **What you should see:** After about a minute the chat says "Database ready: Your app now has a Postgres database with built-in auth." Your new database appears on the Database screen, and **Keys & secrets** lists the keys it set under **From Database**.

It's a Postgres 17 database that holds the tables WebDIY creates as you build, and it comes with sign-up and login for the people who use your app (see [Add sign-in for your app's users](https://web.diy/docs/database/app-sign-in)). Six keys your app reads, like `DATABASE_URL`, are added for you too, so there's nothing to paste.

## Changing your tables

Ask WebDIY in the chat, in your own words:

> Add a table for bookings with the class, the person's name and email, and when they booked.

WebDIY writes each change as a migration file in your project and applies it, and the **Changes** tab lists every change in order. When it checks your data, it uses read-only queries.

## Looking at your data

Open **Tools**, then **Database**. There are three tabs:

| Tab      | What it shows                               |
| -------- | ------------------------------------------- |
| Overview | The database's status and use.              |
| Tables   | Your tables and their rows.                 |
| Changes  | Every change WebDIY has made to the tables. |

In **Tables**, pick a table to see its rows. You can filter by a column (contains, is, is empty, isn't empty) or select a column's heading to sort by it. Select a row to see all of it, and **Copy as JSON** to copy it. Rows are read when you open the table, so they don't update live.

### Email addresses start out masked

Email addresses stay masked until you select **Show emails**. Then they're visible for ten minutes, or until you select **Hide emails**, and each time you show them it's recorded in the project's audit log. You can't sort or filter by email until emails are shown.

### Export a table as CSV

Builders and Admins can download a table as a CSV file of up to 50,000 rows. Emails stay masked in the file unless you choose **Include emails**, and choosing it is recorded in the project's audit log.

## One database for the preview and the live site

> **Warning:** Your preview and your published site share one database, so any change to data shows up in both at once. A test booking you make in the Preview is a real booking on your live site.

## Deleting the database

1. Open **Tools**, then **Database**.
2. Open the menu (**⋯**) and select **Delete database…**.
3. Type the project's name and select **Delete database**.

> **Warning:** Deleting removes your tables and the accounts people use to sign in to your app, and the six keys it set disappear from **Keys & secrets**. Your published site won't be able to save anything or sign anyone in. Neon, the company that runs the database, keeps a deleted database for 7 days, so it may be possible to get it back. After that, it's gone for good.

## Where to go next

- [Add sign-in for your app's users](https://web.diy/docs/database/app-sign-in)
- [Keys & secrets](https://web.diy/docs/database/keys-and-secrets)
- [Publish your app](https://web.diy/docs/publish/publish-your-app)
