Create a Seed Data Migration (config v2)
It can be convenient to add some seed data into tables as part of the DB init process.
Step 1: Run the Console via the Hasura CLI
In order to make sure that the Migrations get created, the Console needs to be run via the Hasura CLI.
Step 2: Navigate to the SQL section
On the Hasura Console, click on the
Data tab and then on the
link on the left hand side.
Step 3: Write an insert statement
The next step is to write an insert statement that populates the database with seed data like the following:
INSERT INTO addresses (id, location) VALUES
(2, 'Tel Aviv'),
INSERT INTO authors (id, name, address_id) VALUES
(1, 'Sarah', 3),
(2, 'Joey', 1),
(3, 'Rachel', 2);
INSERT INTO articles (id, title, content, author_id) VALUES
(1, 'How to make fajitas', 'Recipe on making the best fajitas in the world', 1),
(2, 'How to climb mount everest', 'Guide on successfully climbing the hightest mountain in the world', 3),
(3, 'How to be successful on broadway', 'What it takes for you to be a successful performer at broadway', 2);
Step 4: Mark the insert as a migration
Check the box
This is a migration and give the migration a name, e.g.
Step 5: Run the statement
Step 6: Verify data & migration
If the insert statement was successful, the data is now added to the DB.
Navigate to the
migrations directory in your Hasura Project. The
latest Migration will be the the insert statement that was just run.