Skip to content

Commit 7d74d69

Browse files
authored
chore: update readme for employees example (supabase#30964)
* chore: update readme for employees example * chore: update readme title * chore: wrap code example in admonition * chore: revamp schema diff guide
1 parent f5b9989 commit 7d74d69

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

apps/docs/content/guides/deployment/database-migrations.mdx

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ supabase migration up
135135

136136
Finally, you should see the `department` column added to your `employees` table in the local Dashboard.
137137

138-
View the [complete code](https://github.com/supabase/supabase/tree/master/examples/database/employees) for this example.
138+
<Admonition type="info">
139+
140+
View the [complete code](https://github.com/supabase/supabase/tree/master/examples/database/employees) for this example on GitHub.
141+
142+
</Admonition>
139143

140144
### Seeding data
141145

@@ -175,7 +179,7 @@ values
175179

176180
<StepHikeCompact.Code>
177181

178-
```bash
182+
```bash Terminal
179183
supabase db reset
180184
```
181185

@@ -190,25 +194,67 @@ You should now see the `employees` table, along with your seed data in the Dashb
190194

191195
This workflow is great if you know SQL and are comfortable creating tables and columns. If not, you can still use the Dashboard to create tables and columns, and then use the CLI to diff your changes and create migrations.
192196

193-
Create a new table called `cities`, with columns `id`, `name` and `population`. To see the corresponding SQL for this, you can use the `supabase db diff --schema public` command. This will show you the SQL that will be run to create the table and columns. The output of `supabase db diff` will look something like this:
197+
<StepHikeCompact>
198+
199+
<StepHikeCompact.Step step={1}>
200+
<StepHikeCompact.Details title="Create your table from the Dashboard">
201+
Create a new table called `cities`, with columns `id`, `name` and `population`.
194202

203+
Then generate a [schema diff](/docs/reference/cli/supabase-db-diff).
204+
</StepHikeCompact.Details>
205+
206+
<StepHikeCompact.Code>
207+
208+
```bash Terminal
209+
supabase db diff -f create_cities_table
195210
```
196-
Diffing schemas: public
197-
Finished supabase db diff on branch main.
198211

212+
</StepHikeCompact.Code>
213+
214+
</StepHikeCompact.Step>
215+
</StepHikeCompact>
216+
217+
<StepHikeCompact>
218+
219+
<StepHikeCompact.Step step={2}>
220+
<StepHikeCompact.Details title="Add schema diff as a migration">
221+
A new migration file is created for you.
222+
223+
Alternately, you can copy the table definitions directly from the Table Editor.
224+
</StepHikeCompact.Details>
225+
226+
<StepHikeCompact.Code>
227+
228+
```sql supabase/migrations/<timestamp>_create_cities_table.sql
199229
create table "public"."cities" (
200230
"id" bigint primary key generated always as identity,
201231
"name" text,
202232
"population" bigint
203233
);
204-
205234
```
206235

207-
Alternately, you can view your table definitions directly from the Table Editor:
236+
</StepHikeCompact.Code>
208237

209-
![SQL Definition](/docs/img/guides/cli/sql-definitions.png)
238+
</StepHikeCompact.Step>
239+
</StepHikeCompact>
240+
241+
<StepHikeCompact>
242+
243+
<StepHikeCompact.Step step={3}>
244+
<StepHikeCompact.Details title="Test your migration">
245+
Test your new migration file by resetting your local database.
246+
</StepHikeCompact.Details>
210247

211-
You can then copy this SQL into a new migration file, and run `supabase db reset` to apply the changes.
248+
<StepHikeCompact.Code>
249+
250+
```bash Terminal
251+
supabase db reset
252+
```
253+
254+
</StepHikeCompact.Code>
255+
256+
</StepHikeCompact.Step>
257+
</StepHikeCompact>
212258

213259
The last step is deploying these changes to a live Supabase project.
214260

@@ -222,7 +268,7 @@ Head over to [Supabase](https://supabase.com/dashboard) and create a new project
222268

223269
<StepHikeCompact.Step step={1}>
224270
<StepHikeCompact.Details title="Log in to the Supabase CLI">
225-
[Login](/docs/reference/cli/usage#supabase-login) to the Supabase CLI using an auto-generated Personal Access Token.
271+
[Login](/docs/reference/cli/supabase-login) to the Supabase CLI using an auto-generated Personal Access Token.
226272
</StepHikeCompact.Details>
227273

228274
<StepHikeCompact.Code>
@@ -240,7 +286,7 @@ supabase login
240286

241287
<StepHikeCompact.Step step={2}>
242288
<StepHikeCompact.Details title="Link your project">
243-
[Link](/docs/reference/cli/usage#supabase-link) to your remote project by selecting from the on-screen prompt.
289+
[Link](/docs/reference/cli/supabase-link) to your remote project by selecting from the on-screen prompt.
244290
</StepHikeCompact.Details>
245291

246292
<StepHikeCompact.Code>
@@ -258,7 +304,7 @@ supabase link
258304

259305
<StepHikeCompact.Step step={3}>
260306
<StepHikeCompact.Details title="Deploy database changes">
261-
[Push](/docs/reference/cli/usage#supabase-db-push) your migrations to the remote database.
307+
[Push](/docs/reference/cli/supabase-db-push) your migrations to the remote database.
262308
</StepHikeCompact.Details>
263309

264310
<StepHikeCompact.Code>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Database Migrations
2+
3+
This example uses Supabase CLI as a migration tool to manage your database schema changes.
4+
5+
## Local development
6+
7+
```bash
8+
npx supabase db start
9+
```
10+
11+
## Push to remote project
12+
13+
```bash
14+
npx supabase login
15+
npx supabase link
16+
npx supabase db push
17+
```

0 commit comments

Comments
 (0)