Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion sqlx-core/src/any/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::any::driver;
use crate::any::{Any, AnyConnection};
use crate::error::Error;
use crate::executor::Executor;
use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateError, Migration};
use crate::sql_str::AssertSqlSafe;
use futures_core::future::BoxFuture;
use std::time::Duration;

Expand Down Expand Up @@ -51,7 +53,18 @@ impl Migrate for AnyConnection {
&'e mut self,
table_name: &'e str,
) -> BoxFuture<'e, Result<(), MigrateError>> {
Box::pin(async {
Box::pin(async move {
let table_exists =
// language=SQL
self.execute(AssertSqlSafe(format!(
r#"SELECT 1 FROM {table_name};"#
)))
.await;

if table_exists.is_ok() {
return Ok(());
}

self.get_migrate()?
.ensure_migrations_table(table_name)
.await
Expand Down
Loading