New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diesel-cli requires empty Cargo.toml file before setup can be run #1300

Closed
SamWhited opened this Issue Nov 11, 2017 · 6 comments

Comments

Projects
None yet
3 participants
@SamWhited

SamWhited commented Nov 11, 2017

Setup

Versions

  • Diesel: 0.16.0

Feature Flags

  • diesel: no-default-features, postgres

Problem Description

Diesel setup looks for Cargo.toml file unnecessarily.

What are you trying to accomplish?

Setup a database for the first time in a non-Rust project.

$ diesel setup
Unable to find Cargo.toml in this directory or any parent directories.
$ touch Cargo.toml
$ diesel setup
Creating database: demodb

I would not expect diesel to require or care about having an empty Cargo.toml file in the project directory. My database migrations may be stored in a separate repo from my project or my project might not be in Rust at all and merely using diesel-cli for migrations.

Checklist

  • I have already looked over the issue tracker for similar issues.
@killercup

This comment has been minimized.

Member

killercup commented Nov 11, 2017

@SamWhited

This comment has been minimized.

SamWhited commented Nov 11, 2017

That makes sense, and documentation would make this less confusing.

Maybe it could also search for a .git or .hg directory? Or if it doesn't find something just use the working directory? I'd still like to not have to create an empty Cargo.toml which I'm just going to remove after initializing the database for new projects.

@SamWhited

This comment has been minimized.

SamWhited commented Nov 12, 2017

It just occured to me that there might be an easy fix for this: if you don't have a Cargo.toml and are in the root of the project you can tell you're in the root because the migrations directory exists. If you're not in the root you can't tell where the root is, so for non rust projects it could just only work if you're in the root already instead of complaining about missing Cargo.toml every time I delete my development database and want to run migrations over again.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 8, 2018

if you don't have a Cargo.toml and are in the root of the project you can tell you're in the root because the migrations directory exists.

Except the command you're complaining about is diesel setup, which is responsible for creating the migrations directory.

If you're not in the root you can't tell where the root is

You can always specify the directory with the MIGRATION_DIRECTORY environment variable, or the --migration-dir command line argument. Unless I'm mistaken, the only time we look for Cargo.toml is to decide where to create the migration directory if you haven't specified explicitly.

I delete my development database and want to run migrations over again.

You probably just want diesel database setup in that case.

@sgrif sgrif closed this Jan 8, 2018

@SamWhited

This comment has been minimized.

SamWhited commented Jan 8, 2018

Except the command you're complaining about is diesel setup, which is responsible for creating the migrations directory.

It's also used to create the database initially, so if we're spinning up the database for the first time (eg. on a new devvm) and the migrations are already created it will currently complain that cargo.toml doesn't exist even though it has a way to detect the root directory and the project doesn't need a cargo.toml.

Maybe it could look for the migrations directory and cargo.toml? Then it could still be used to create the database and wouldn't panic every time with a confusing error message.

diesel database setup is a good workaround though, I can live with that, but when you look in the help "setup" appears the obvious command to run, and having that panic and spit out a confusing error message still doesn't feel ideal.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 8, 2018

As I said, if you just want to create the database and not setup the whole project (which involves creating the migrations directory, generating default migrations, etc), you should run diesel database setup instead.

and having that panic and spit out a confusing error message still doesn't feel ideal.

I don't think it's common to use Diesel without cargo, so I doubt this is something many are likely to run into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment