Skip to content

Commit 430947a

Browse files
committed
improve production seeding docs
1 parent 0c0637a commit 430947a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docs/database.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,26 @@ if what you need to seed is a lot of data), so here's an easy way to help out:
158158

159159
1. Create a script very similar to our `prisma/seed.ts` file which creates all
160160
the data you want to seed.
161-
1. Run the script locally to generate the data you want to seed.
161+
```sh nonumber
162+
cp prisma/seed.ts ./prod-seed.local.ts
163+
```
164+
Then modify that file to create the data you want to seed.
165+
1. Create a temporary database file to seed the data into.
166+
```sh
167+
DATABASE_URL=file:./seed.local.db npx prisma migrate reset --skip-seed --force
168+
```
169+
1. Run the custom seed script locally to generate the data you want to seed.
170+
```sh
171+
DATABASE_URL=file:./seed.local.db npx tsx ./prod-seed.local.ts
172+
```
162173
1. Create a "dump" of the seed database using the `sqlite3` command line tool.
163174
```sh nonumber
164-
sqlite3 seed.db .dump > seed.sql
175+
sqlite3 ./prisma/seed.local.db .dump > seed.local.sql
165176
```
166-
1. Copy the relevant bits from the `seed.sql` file into your `migration.sql`
167-
file. The `seed.sql` will include create table/index lines etc. which should
168-
already be in your `migration.sql`. You probably just want `INSERT` commands.
177+
1. Copy the relevant bits from the `seed.local.sql` file into your
178+
`migration.sql` file. The `seed.local.sql` will include create table/index
179+
lines etc. which should already be in your `migration.sql`. You probably just
180+
want `INSERT` commands.
169181
1. Deploy your app and verify that the data was seeded correctly.
170182

171183
If your app has already applied all migrations, then the changes to the

0 commit comments

Comments
 (0)