Setting Up an New Prisma project
1
Create a new project (or clone our example project)
2
Configure your environment
Using Prisma with Nile in development
Nile has built-in tables that can be useful in your project. Especially thetenants
table, which is used to store tenant information.
Therefore, we recommend first pulling in the built-in tables to your project, and
then starting to build your own tables.
1
Pull in the built-in tables
schema.prisma
file with the built-in tenants
table.2
Generate Prisma client
3
Add your own tables
To add your own tables, you can edit the
schema.prisma
file and add your own models. For example:4
Push changes to the database
Using Prisma with Nile in production
db pull
and db push
work well in development, where you can evolve the schema without tracking every change.
However, in production, we recommend using tracked migrations to ensure that the schema is always
in sync with the code.
Because Nile has a built-in tenants
table, we first create a baseline migration that will include the built-in tables,
and then create additional migrations for our own tables.
1
Create a baseline migration
If you don’t yet have a schema.prisma file with the built-in tables, start by creating one:Then, create a baseline migration:
2
Apply the baseline migration
3
Create a migration for your own tables
Now, lets modify the schema to include our own tables.
For example, we’ll add a Now, we’ll create a migration for this change by comparing the existing schema in the
DB (the
posts
table to schema.prisma
.
If you already have this table in your schema, you can add a column instead.datasource
) with the new schema in schema.prisma
(the datamodel
).While both the datasource
and datamodel
are in the same file, the first will refer to the
datasource
definition in the schema.prisma
file while the second will refer to the model itself.Prisma docs recommend generating migrations with
npx prisma migrate dev
. However, this will not work
for Nile because the npx prisma migrate dev
command starts by attempting to “reset” a shadow database by dropping all tables.
This is not possible in Nile because the built-in tables are required for core functionality.4
Apply the migration
Last but not least, we can apply the migration to the database: