Skip to content
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

Cannot run migration with migrate! macro #746

Closed
esemeniuc opened this issue Oct 18, 2020 · 10 comments
Closed

Cannot run migration with migrate! macro #746

esemeniuc opened this issue Oct 18, 2020 · 10 comments
Labels
db:sqlite Related to SQLite macros

Comments

@esemeniuc
Copy link
Contributor

esemeniuc commented Oct 18, 2020

When running sqlx::migrate!("migrations").run(&conn).await?;, I get this output:

error: paths relative to the current file's directory are not currently supported
  --> src/db.rs:24:20
   |
24 |     sqlx::migrate!("migrations").run(&conn).await?;
   |                    ^^^^^^^^^^^^

I get this result on rust 1.47 and 1.49 nightly. This is my Cargo.toml entry: sqlx = { version = "0.4.0-beta.1", features = [ "macros", "sqlite", "chrono", "migrate" ] }

Running sqlx::migrate!("/").run(&conn).await?; results in

error: absolute paths will only work on the current machine
  --> src/db.rs:24:20
   |
24 |     sqlx::migrate!("/").run(&conn).await?;
   |                    ^^^

All my work is based on this documentation: https://docs.rs/sqlx/0.4.0-beta.1/sqlx/macro.migrate.html

@abonander
Copy link
Collaborator

Try sqlx::migrate!("./migrations")

@ghost
Copy link

ghost commented Oct 21, 2020

sqlx::migrate!("./migrations") gives me:

error: invalid digit found in string
  --> database/src/postgres.rs:29:9
   |
29 |         sqlx::migrate!("./migrations")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@izik1 izik1 added macros db:sqlite Related to SQLite labels Oct 22, 2020
@izik1
Copy link
Contributor

izik1 commented Oct 22, 2020

Could we get a list of your migration file names?

@abonander
Copy link
Collaborator

error: invalid digit found in string

Are you on Windows? That would explain that error. I thought we were normalizing paths for the OS though.

@ghost
Copy link

ghost commented Oct 22, 2020

Was using a non integer prefix for the migration file. Thanks

@izik1
Copy link
Contributor

izik1 commented Oct 22, 2020

I think I'm going to close this, perhaps another issue should be opened to make the migration naming format more obvious?

@izik1 izik1 closed this as completed Oct 22, 2020
@izik1 izik1 reopened this Oct 22, 2020
@izik1
Copy link
Contributor

izik1 commented Oct 22, 2020

wait a second, got a mixup, uhh, @esemeniuc is everything okay on your end?

@esemeniuc
Copy link
Contributor Author

It works with sqlx::migrate!();, thank you :)

esemeniuc added a commit to esemeniuc/sqlx that referenced this issue Oct 22, 2020
Fixes issue experienced in launchbadge#746 when using no parameter:

```
error: paths relative to the current file's directory are not currently supported
 --> src/db.rs:7:5
  |
7 |     sqlx::migrate!().run(&conn).await?;
  |     ^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```
mehcode pushed a commit that referenced this issue Oct 23, 2020
Fixes issue experienced in #746 when using no parameter:

```
error: paths relative to the current file's directory are not currently supported
 --> src/db.rs:7:5
  |
7 |     sqlx::migrate!().run(&conn).await?;
  |     ^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```
@ketzu
Copy link

ketzu commented Jun 22, 2024

Try sqlx::migrate!("./migrations")

Thank you, from the documentation it was somewhat confusing to figure out that:

  • sqlx::migrate!("migrations") is treated as a relative path to the cwd and refused
  • sqlx::migrate!("./migrations") is treated as a relative path to the root and accepted
  • sqlx::migrate!("db/migrations") is treated as a relative path to the root and accepted (the example from the documentation)

@your-diary
Copy link

The documentation uses

#[sqlx::test(migrations = "foo_migrations")]

, which doesn't work due to the reason discussed in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:sqlite Related to SQLite macros
Projects
None yet
Development

No branches or pull requests

5 participants