docs: add admonition for creating seed data

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10017
GitOrigin-RevId: b414a4603ff65f9eaa499f4c4fbf43a522af0cc0
This commit is contained in:
Rob Dominguez 2023-08-01 10:21:23 -05:00 committed by hasura-bot
parent 8129868c32
commit 69396a8f64

View File

@ -12,14 +12,14 @@ keywords:
## Use case
It's often useful to add some initial Seed data into your database as part of the initialization process, with
Hasura Seeds you can do that. This is particularly useful for adding a testing user or to pre-populate values if you
have set a table in Hasura as an enum table to expose it as GraphQL enums in the GraphQL API.
It's often useful to add some initial Seed data into your database as part of the initialization process, with Hasura
Seeds you can do that. This is particularly useful for adding a testing user or to pre-populate values if you have set a
table in Hasura as an enum table to expose it as GraphQL enums in the GraphQL API.
## Create a Hasura Seed file
You can use the Hasura CLI to automatically create Seed files for you based on the data which is already in a table
in a database.
You can use the Hasura CLI to automatically create Seed files for you based on the data which is already in a table in a
database.
```bash
hasura seed create myAuthorsSeed --from-table author
@ -48,6 +48,14 @@ INSERT INTO public.author (id, name) VALUES ('3', 'Austen');
INSERT INTO public.author (id, name) VALUES ('4', 'Orwell');
```
:::info Want to generate seed data for a table that doesn't exist yet?
You can still use the `hasura seed create` command! Simply leave off the `--from-table` flag and accompanying argument,
and Hasura will launch an editor in which you can write your own SQL statements. Upon saving and quitting the editor,
Hasura will create a seed file for you in the `/seeds/default` directory.
:::
## Apply a Hasura Seed file
To apply a seeds file to your Hasura instance you can use the `apply` Hasura CLI command. Eg:
@ -56,13 +64,12 @@ To apply a seeds file to your Hasura instance you can use the `apply` Hasura CLI
hasura seed apply --file 1656499378904_myNewAuthorsSeed.sql
```
If you do not specify a database with the `--database-name` flag then the CLI will prompt you to choose the database
to apply the seeds to and as long as there are no conflicts and the SQL executes successfully to input the data then
the CLI will log:
If you do not specify a database with the `--database-name` flag then the CLI will prompt you to choose the database to
apply the seeds to and as long as there are no conflicts and the SQL executes successfully to input the data then the
CLI will log:
```text
INFO Seeds planted
```
Success!