Question: could you provide an example of using run to seed a database?
filipecatraia opened this issue · 1 comments
filipecatraia commented
Summary
I'm not quite sure how run works, i.e. how to create the “templates” or how to create the seed files.
Would you kindly give me a quick explanation?
I don't mind then submitting a PR so that it becomes part of the documentation.
Thanks a lot!
benjie commented
Create a SQL file that does your seeding:
# seed.sql
insert into users (username) values
('Alice'),
('Bob'),
('Caroline');
insert into posts (user_id, body)
select id, username || ' is the best!'
from users;
Run the SQL file:
graphile-migrate run seed.sql
If you are using placeholders
, e.g. you have something like this in your gmrc:
"placeholders": {
":DATABASE_AUTHENTICATOR": "!ENV",
":DATABASE_VISITOR": "!ENV"
},
Then these placeholders (:DATABASE_VISITOR
) will be automatically replaced if they exist in your file - this is the main reason (other than automatic connection string) that you'd use graphile-migrate run
over psql
directly - with psql
you'd have to explicitly configure the placeholders.