# Update your database

To add new tables or columns to your database we use Prisma.\
\
Prisma is a TypeScript ORM, and it helps you apply changes to your database, and interact with it in a type-safe way., and without using SQL.

## Add a new table

To add a new table, open the file `prisma/schema.prisma` and add a new model.

For instance, to add a new table called `Orders`, add this

<pre class="language-prisma" data-title="prisma/schema.prisma"><code class="lang-prisma"><strong>model Order {
</strong>  id                  Int       @id @default(autoincrement())
  email               String
  orderId             String
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
}
</code></pre>

## Add column

To add a column to a table, simply add a new property to a model.

To add a new column, called `validUntil` to the previous `Orders` table, simply add line 5:

<pre class="language-prisma" data-title="prisma/schema.prisma" data-line-numbers><code class="lang-prisma"><strong>model Order {
</strong>  id                  Int       @id @default(autoincrement())
  email               String
  orderId             String
  validUntil          DateTime?
  createdAt           DateTime  @default(now())
  updatedAt           DateTime  @updatedAt
}
</code></pre>

{% hint style="info" %}
It's a good idea to add a new column to existing tables, with a nullable value.\
You do it by appending a question mark (`?)`at the end of the column type.

It means that, as soon as the new column is created, it's value will be `NULL`.

Alternatively, assign a default value, using the `@default()` decorator.
{% endhint %}

## Apply the schema to your database

To do that, run this command:

{% code title="Terminal" %}

```bash
npx prisma db push
```

{% endcode %}

With this command, prisma will apply the schema defined into `prisma/schema.prisma` to the database defined in the .env file, using the connection string defined in the environment variable `DATABASE_URL`.

For more details about Prisma, check the [official documentation of Prisma.](https://www.prisma.io/docs/orm)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shipped.club/features/database/update-your-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
