|
1 | | -use butane::migrations::{ |
2 | | - adb::DeferredSqlType, adb::TypeIdentifier, adb::TypeKey, MemMigrations, Migration, |
3 | | - MigrationMut, Migrations, MigrationsMut, |
4 | | -}; |
5 | | -use butane::{db::Connection, prelude::*, SqlType, SqlVal}; |
6 | 1 | use butane_core::codegen::{butane_type_with_migrations, model_with_migrations}; |
| 2 | +use butane_core::db::{BackendConnection, Connection}; |
| 3 | +use butane_core::migrations::adb::{DeferredSqlType, TypeIdentifier, TypeKey}; |
| 4 | +use butane_core::migrations::{MemMigrations, Migration, MigrationMut, Migrations, MigrationsMut}; |
| 5 | +use butane_core::{SqlType, SqlVal}; |
7 | 6 | #[cfg(feature = "pg")] |
8 | 7 | use butane_test_helper::pg_connection; |
9 | 8 | #[cfg(feature = "sqlite")] |
@@ -343,18 +342,21 @@ fn test_migrate( |
343 | 342 | .create_migration(&backends, "v2", ms.latest().as_ref()) |
344 | 343 | .unwrap()); |
345 | 344 |
|
346 | | - let mut to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 345 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
347 | 346 | assert_eq!(to_apply.len(), 2); |
348 | | - for m in &to_apply { |
349 | | - m.apply(conn).unwrap(); |
350 | | - } |
| 347 | + |
| 348 | + ms.migrate(conn).unwrap(); |
| 349 | + |
| 350 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 351 | + assert_eq!(to_apply.len(), 0); |
| 352 | + |
351 | 353 | verify_sql(conn, &ms, expected_up_sql, expected_down_sql); |
352 | 354 |
|
353 | 355 | // Now downgrade, just to make sure we can |
354 | | - to_apply.reverse(); |
355 | | - for m in to_apply { |
356 | | - m.downgrade(conn).unwrap(); |
357 | | - } |
| 356 | + ms.unmigrate(conn).unwrap(); |
| 357 | + |
| 358 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 359 | + assert_eq!(to_apply.len(), 2); |
358 | 360 | } |
359 | 361 |
|
360 | 362 | fn verify_sql( |
@@ -559,16 +561,19 @@ fn migration_delete_table(conn: &mut Connection, expected_up_sql: &str, expected |
559 | 561 | .create_migration(&backends, "v2", ms.latest().as_ref()) |
560 | 562 | .unwrap()); |
561 | 563 |
|
562 | | - let mut to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 564 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
563 | 565 | assert_eq!(to_apply.len(), 2); |
564 | | - for m in &to_apply { |
565 | | - m.apply(conn).unwrap(); |
566 | | - } |
| 566 | + |
| 567 | + ms.migrate(conn).unwrap(); |
| 568 | + |
| 569 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 570 | + assert_eq!(to_apply.len(), 0); |
| 571 | + |
567 | 572 | verify_sql(conn, &ms, expected_up_sql, expected_down_sql); |
568 | 573 |
|
569 | 574 | // Now downgrade, just to make sure we can |
570 | | - to_apply.reverse(); |
571 | | - for m in to_apply { |
572 | | - m.downgrade(conn).unwrap(); |
573 | | - } |
| 575 | + ms.unmigrate(conn).unwrap(); |
| 576 | + |
| 577 | + let to_apply = ms.unapplied_migrations(conn).unwrap(); |
| 578 | + assert_eq!(to_apply.len(), 2); |
574 | 579 | } |
0 commit comments