@@ -136,6 +136,46 @@ you can utilize Fly's `ssh` and `proxy` commands.
136
136
To work with Prisma Studio and your deployed app's database, simply open
137
137
` http://localhost:5556 ` in your browser.
138
138
139
+ ## Seeding Production
140
+
141
+ Let's say you're building an application that allows users to lookup the nearest
142
+ city with a certain population threshold from their geographic location, you'll
143
+ need to have a database of cities with their population and geographic
144
+ coordinates. You could manually enter this data into your database, but that
145
+ would be tedious and error prone. Instead, you can write a script that will
146
+ populate your database with the data you need.
147
+
148
+ The easiest way to seed production data is to use the ` sqlite3 ` command line
149
+ tool. You can use raw SQL, or write a script which can be committed to the repo,
150
+ generate the database file you like (all while working locally), and then copy
151
+ it to your production environment.
152
+
153
+ It's surprisingly straightforward to do production DB seeding with SQLite 😅
154
+
155
+ If you have existing data in your production database and you'd like to seed it
156
+ with more data, then it's a tiny bit more involved.
157
+
158
+ 1 . Backup your production database (lol).
159
+ 1 . Create a new database file (locally) with the data you want to seed.
160
+ 1 . Create a "dump" of the seed database using the ` sqlite3 ` command line tool.
161
+ ``` sh nonumber
162
+ sqlite3 seed.db .dump > seed.sql
163
+ ```
164
+ 1 . Copy the ` seed.sql ` file to your production volume next to your database (via
165
+ ` fly sftp ` )
166
+ 1 . SSH into your production server and run the following command:
167
+ ``` sh nonumber
168
+ sqlite3 data.db < seed.sql
169
+ ```
170
+ 1 . Verify that your production database has been seeded correctly. If it hasn't,
171
+ then restore your backup (asap).
172
+
173
+ > ** Warning** : You may need to adjust some of the SQL generated by the ` .dump `
174
+ > command to allow you to update the database without issue. It will have
175
+ > ` CREATE TABLE ` commands which should include ` IF NOT EXISTS ` , but the
176
+ > ` CREATE UNIQUE INDEX ` commands will not. You'll need to add ` IF NOT EXISTS ` to
177
+ > those commands manually, or remove them entirely.
178
+
139
179
## Deploying locally
140
180
141
181
If you'd like to deploy locally you definitely can. You need to (temporarily)
0 commit comments