Skip to content

Commit

Permalink
Fix reverting embedded migrations
Browse files Browse the repository at this point in the history
Also fix a brocken mysql down migration
  • Loading branch information
weiznich committed Mar 26, 2021
1 parent e2dca0a commit 57729f9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion diesel_derives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ quote = "1"
proc-macro2 = "1"

[dev-dependencies]
cfg-if = "0.1.10"
cfg-if = "1"
dotenv = "0.15"

[dev-dependencies.diesel]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn migration_literal_from_path(path: &Path) -> Result<proc_macro2::TokenStream,
}
let up_sql = path.join("up.sql");
let up_sql_path = up_sql.to_str();
let down_sql = path.join("up.sql");
let down_sql = path.join("down.sql");
let down_sql_path = down_sql.to_str();
let metadata = TomlMetadata::read_from_file(&path.join("metadata.toml")).unwrap_or_default();
let run_in_transaction = metadata.run_in_transaction;
Expand Down
26 changes: 25 additions & 1 deletion diesel_migrations/migrations_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,38 @@ use proc_macro::TokenStream;
/// # include!("../../../diesel/src/doctest_setup.rs");
/// #
/// # #[cfg(feature = "postgres")]
/// # fn migration_connection() -> diesel::PgConnection {
/// # let connection_url = database_url_from_env("PG_DATABASE_URL");
/// # let conn = diesel::PgConnection::establish(&connection_url).unwrap();
/// # conn.begin_test_transaction().unwrap();
/// # conn
/// # }
/// #
/// # #[cfg(feature = "sqlite")]
/// # fn migration_connection() -> diesel::SqliteConnection {
/// # let connection_url = database_url_from_env("SQLITE_DATABASE_URL");
/// # let conn = diesel::SqliteConnection::establish(&connection_url).unwrap();
/// # conn.begin_test_transaction().unwrap();
/// # conn
/// # }
/// #
/// # #[cfg(feature = "mysql")]
/// # fn migration_connection() -> diesel::MysqlConnection {
/// # let connection_url = database_url_from_env("MYSQL_DATABASE_URL");
/// # let conn = diesel::MysqlConnection::establish(&connection_url).unwrap();
/// # conn
/// # }
/// #
/// #
/// # #[cfg(feature = "postgres")]
/// pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("../../migrations/postgresql");
/// # #[cfg(all(feature = "mysql", not(feature = "postgres")))]
/// # pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("../../migrations/mysql");
/// # #[cfg(all(feature = "sqlite", not(any(feature = "postgres", feature = "mysql"))))]
/// # pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!("../../migrations/sqlite");
///
/// # fn main() {
/// # let connection = connection_no_data();
/// # let connection = migration_connection();
/// # run_migrations(&connection).unwrap();
/// # }
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DROP INDEX users_hair_color;
DROP INDEX posts_user_id;
DROP INDEX users_hair_color ON users;
DROP INDEX posts_user_id ON posts;

0 comments on commit 57729f9

Please sign in to comment.