Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upcommand to populate db with test data in diesel-cli #420
Comments
This comment has been minimized.
|
While I think this could be a nice CLI feature as it uses the same DB interface as diesel, you should note that all databases I know come with simple tools to do load data from a file. E.g., Another idea might be seeding with Rust code instead of a static SQL file. Just create an (additional) binary like |
This comment has been minimized.
azerupi
commented
Aug 27, 2016
|
Yeah I figured there would an easy way to load sql files in the db. Maybe that wouldn't add enough to be worth implementing.. What about the csv idea? Would that make any sense? In my head it seems easier to maintain a csv file with a couple of entries than a sql file when your database evolves often. But then again, I have very little experience |
This comment has been minimized.
|
IMHO, CSV is nice when you first look at it, but then you try to import a text/date/foreign key/enum/decimal field and everything explodes… ;) |
This comment has been minimized.
|
I'm definitely against something like CSV for this. |
This comment has been minimized.
azerupi
commented
Aug 28, 2016
|
@sgrif would there be another format more suitable for this task or is it just not worth the effort in general? |
This comment has been minimized.
|
A lot of other ORM CLIs have Usually supporting CSV and JSON as formats. It's a very nice feature to have during development. It allows even non-devs to create realistic data, and other devs can just load it up without having to worry /know about database specific dump / restore tooling (like pg_dump). diesel dump -f json --all --out-dir=./data
diesel database reset
diesel load dataWhen dumping all tables, a file for each table would be created. The load command must figure out a foreign key dependency graph to load the tables in a correct order. |
This comment has been minimized.
|
Closing this since I don't think there's anything actionable right now. If we were to do this, I think it should be a thin wrapper around the dumping tools that various databases provide. I'm happy to consider the feature, but we need a new issue with a more concrete proposal on what the API would look like, and what specifically it would do. I'd be fine with the proposal focusing on one backend as an example, we can figure out how to make that work with the tools for other backends from there. |
sgrif
closed this
Dec 16, 2017
This comment has been minimized.
mjanda
commented
Apr 13, 2018
|
What about just adding support for having Having it together with migrations would mean less time keeping seeding data up to date with current db structure, help test migrations when altering db etc. |
azerupi commentedAug 27, 2016
It's often useful to fill the database with some test data while you are developing. Could the cli make this easier? I don't work often with databases, so I don't know how it is done normally. But if the cli could make this an easy process that would be great!
It could be as easy as
diesel fill test-data.sql. Or more elaborate by for example have a folder with csv files for each table.