From 5dbc598b6046a6e70b9ca1a5f3938a58095d0c5a Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Thu, 11 Apr 2024 11:34:33 +0800 Subject: [PATCH 1/2] Add Clones --- butane_core/src/db/connmethods.rs | 2 +- butane_core/src/migrations/adb.rs | 2 +- butane_core/src/migrations/fsmigrations.rs | 6 +++--- butane_core/src/migrations/mod.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/butane_core/src/db/connmethods.rs b/butane_core/src/db/connmethods.rs index 79ea3b13..27a4140e 100644 --- a/butane_core/src/db/connmethods.rs +++ b/butane_core/src/db/connmethods.rs @@ -57,7 +57,7 @@ pub trait ConnectionMethods { /// Represents a database column. Most users do not need to use this /// directly. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Column { name: &'static str, ty: SqlType, diff --git a/butane_core/src/migrations/adb.rs b/butane_core/src/migrations/adb.rs index cd07017e..a596949b 100644 --- a/butane_core/src/migrations/adb.rs +++ b/butane_core/src/migrations/adb.rs @@ -131,7 +131,7 @@ impl Ord for TypeKey { } } -#[derive(Debug)] +#[derive(Clone, Debug)] struct TypeResolver { // The types of some columns may not be known right away types: HashMap, diff --git a/butane_core/src/migrations/fsmigrations.rs b/butane_core/src/migrations/fsmigrations.rs index 313fe581..0990bf9d 100644 --- a/butane_core/src/migrations/fsmigrations.rs +++ b/butane_core/src/migrations/fsmigrations.rs @@ -17,7 +17,7 @@ type SqlTypeMap = BTreeMap; const TYPES_FILENAME: &str = "types.json"; /// Metadata stored in each migration in the filesystem. -#[derive(Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize)] struct MigrationInfo { /// The migration this one is based on, or None if this is the /// first migration in the chain @@ -42,7 +42,7 @@ impl MigrationInfo { } /// Metadata about the migration series. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize)] struct MigrationsState { latest: Option, } @@ -344,7 +344,7 @@ impl PartialEq for FsMigration { impl Eq for FsMigration {} /// A collection of migrations stored in the filesystem. -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct FsMigrations { fs: Rc, root: PathBuf, diff --git a/butane_core/src/migrations/mod.rs b/butane_core/src/migrations/mod.rs index 0d0ad257..4dcdd42e 100644 --- a/butane_core/src/migrations/mod.rs +++ b/butane_core/src/migrations/mod.rs @@ -275,7 +275,7 @@ pub fn copy_migration(from: &impl Migration, to: &mut impl MigrationMut) -> Resu Ok(()) } -#[derive(Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] struct ButaneMigration { name: String, } From 879a069313e1f6b20a9a1abadae05b88d1769f0e Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Thu, 11 Apr 2024 11:42:55 +0800 Subject: [PATCH 2/2] Strangely this now passes migration --- examples/getting_started/tests/rollback.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/getting_started/tests/rollback.rs b/examples/getting_started/tests/rollback.rs index 65c7f0d9..7932fc8b 100644 --- a/examples/getting_started/tests/rollback.rs +++ b/examples/getting_started/tests/rollback.rs @@ -40,16 +40,6 @@ fn migrate_and_rollback(mut connection: Connection) { let migrations = butane_cli::get_migrations(&base_dir).unwrap(); let to_apply = migrations.unapplied_migrations(&connection).unwrap(); for migration in &to_apply { - if connection.backend_name() == "pg" - && migration.name() == "20240115_023841384_dbconstraints" - { - // migration 20240115_023841384_dbconstraints failed: Postgres error db error: - // ERROR: cannot drop table tag because other objects depend on it - // DETAIL: constraint post_tags_many__butane_tmp_has_fkey1 on table post_tags_many depends on table tag - let err = migration.apply(&mut connection).unwrap_err(); - eprintln!("Migration {} failed: {err:?}", migration.name()); - return; - } migration .apply(&mut connection) .unwrap_or_else(|err| panic!("migration {} failed: {err}", migration.name())); @@ -60,6 +50,16 @@ fn migrate_and_rollback(mut connection: Connection) { // Rollback migrations. for migration in to_apply.iter().rev() { + if connection.backend_name() == "pg" + && migration.name() == "20240115_023841384_dbconstraints" + { + // migration 20240115_023841384_dbconstraints failed: Postgres error db error: + // ERROR: cannot drop table post because other objects depend on it + // DETAIL: constraint post_tags_many__butane_tmp_owner_fkey on table post_tags_many depends on table post + let err = migration.apply(&mut connection).unwrap_err(); + eprintln!("Migration {} failed: {err:?}", migration.name()); + return; + } migration .downgrade(&mut connection) .unwrap_or_else(|err| panic!("rollback of {} failed: {err}", migration.name()));