Skip to content

Commit

Permalink
Add more Clones (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Apr 14, 2024
1 parent 87456eb commit 0a7824d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion butane_core/src/db/connmethods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion butane_core/src/migrations/adb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeKey, TypeIdentifier>,
Expand Down
6 changes: 3 additions & 3 deletions butane_core/src/migrations/fsmigrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type SqlTypeMap = BTreeMap<TypeKey, DeferredSqlType>;
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
Expand All @@ -42,7 +42,7 @@ impl MigrationInfo {
}

/// Metadata about the migration series.
#[derive(Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
struct MigrationsState {
latest: Option<String>,
}
Expand Down Expand Up @@ -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<dyn Filesystem>,
root: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion butane_core/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
20 changes: 10 additions & 10 deletions examples/getting_started/tests/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down

0 comments on commit 0a7824d

Please sign in to comment.