Skip to content

Commit

Permalink
Remove transaction from edgedb migrate (#1189)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs authored Jan 8, 2024
1 parent f6783e8 commit ffc544c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/migrations/dev_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub async fn migrate(cli: &mut Connection, ctx: &Context, bar: &ProgressBar)
.ok_or_else(|| bug::error("`skip` is out of range"))?;
if !migrations.is_empty() {
bar.set_message("applying migrations");
apply_migrations(cli, migrations, &ctx).await?;
apply_migrations(cli, migrations, &ctx, false).await?;
}
bar.set_message("calculating diff");
log::info!("Calculating schema diff.");
Expand Down
30 changes: 17 additions & 13 deletions src/migrations/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ async fn _migrate(cli: &mut Connection, _options: &Options,
}
return Ok(());
}
apply_migrations(cli, migrations, &ctx).await?;
apply_migrations(cli, migrations, &ctx, migrate.single_transaction).await?;
if db_migrations.is_empty() {
disable_ddl(cli).await?;
}
Expand Down Expand Up @@ -339,7 +339,7 @@ async fn fixup(
}
}

apply_migrations(cli, &operations, ctx).await?;
apply_migrations(cli, &operations, ctx, _options.single_transaction).await?;
Ok(())
}

Expand Down Expand Up @@ -431,23 +431,27 @@ fn backtrack<'a>(markup: &HashMap<&String, u32>,
}

pub async fn apply_migrations(cli: &mut Connection,
migrations: impl AsOperations<'_>, ctx: &Context)
migrations: impl AsOperations<'_>, ctx: &Context, single_transaction: bool)
-> anyhow::Result<()>
{
let old_timeout = timeout::inhibit_for_transaction(cli).await?;
async_try! {
async {
execute(cli, "START TRANSACTION").await?;
async_try! {
async {
apply_migrations_inner(cli, migrations, ctx.quiet).await
},
except async {
execute_if_connected(cli, "ROLLBACK").await
},
else async {
execute(cli, "COMMIT").await
if single_transaction {
execute(cli, "START TRANSACTION").await?;
async_try! {
async {
apply_migrations_inner(cli, migrations, ctx.quiet).await
},
except async {
execute_if_connected(cli, "ROLLBACK").await
},
else async {
execute(cli, "COMMIT").await
}
}
} else {
apply_migrations_inner(cli, migrations, ctx.quiet).await
}
},
finally async {
Expand Down
4 changes: 4 additions & 0 deletions src/migrations/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ pub struct Migrate {
/// a regular `.edgeql` file, after which the above query will return nothing.
#[arg(long)]
pub dev_mode: bool,

/// Runs the migration(s) in a single transaction.
#[arg(long="single-transaction")]
pub single_transaction: bool,
}

#[derive(clap::Args, Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/portable/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ async fn migrate_async(inst: &Handle<'_>, ask_for_running: bool)
quiet: false,
to_revision: None,
dev_mode: false,
single_transaction: false,
conn: None,
}).await?;
Ok(())
Expand Down

0 comments on commit ffc544c

Please sign in to comment.