| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#; |
| 4 | |
| 5 | use futures_corerust-analyzer cargo futures-core 0.3.34 crate/::futurerust-analyzer cargo futures-core 0.3.34 future/::BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#; |
| 6 | |
| 7 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#; |
| 8 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::{AppliedMigrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/AppliedMigration#, Migrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#}; |
| 9 | pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) use sqlx_corerust-analyzer cargo sqlx-core 0.8.3 crate/::migraterust-analyzer cargo sqlx-core 0.8.3 migrate/::{Migraterust-analyzer cargo sqlx-core 0.8.3 migrate/migrate/Migrate#, MigrateDatabaserust-analyzer cargo sqlx-core 0.8.3 migrate/migrate/MigrateDatabase#}; |
| 10 | |
| 11 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::connectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/::{ConnectOptionsrust-analyzer cargo sqlx-core 0.8.3 connection/ConnectOptions#, Connectionrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#}; |
| 12 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#; |
| 13 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::executorrust-analyzer cargo sqlx-core 0.8.3 executor/::Executorrust-analyzer cargo sqlx-core 0.8.3 executor/Executor#; |
| 14 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::queryrust-analyzer cargo sqlx-core 0.8.3 query/::queryrust-analyzer cargo sqlx-core 0.8.3 query/query().; |
| 15 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::query_asrust-analyzer cargo sqlx-core 0.8.3 query_as/::query_asrust-analyzer cargo sqlx-core 0.8.3 query_as/query_as().; |
| 16 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::query_scalarrust-analyzer cargo sqlx-core 0.8.3 query_scalar/::query_scalarrust-analyzer cargo sqlx-core 0.8.3 query_scalar/query_scalar().; |
| 17 | use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#, PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#, Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres#}; |
| 18 | |
| 19 | fn parse_for_maintenancerust-analyzer cargo sqlx-postgres 0.8.3 migrate/parse_for_maintenance().(url: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 20 | let mut options = PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#::from_strrust-analyzer cargo sqlx-postgres 0.8.3 options/parse/impl#[PgConnectOptions][FromStr]from_str().(url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 21 | |
| 22 | // pull out the name of the database to create |
| 23 | let database = options |
| 24 | .databaserust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#database. |
| 25 | .as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().() |
| 26 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&options.usernamerust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#username.) |
| 27 | .to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(); |
| 28 | |
| 29 | // switch us to the maintenance database |
| 30 | // use `postgres` _unless_ the database is postgres, in which case, use `template1` |
| 31 | // this matches the behavior of the `createdb` util |
| 32 | options.databaserust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#database. = if database rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."postgres" { |
| 33 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("template1".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 34 | } else { |
| 35 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("postgres".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 36 | }; |
| 37 | |
| 38 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((options, database)) |
| 39 | } |
| 40 | |
| 41 | impl MigrateDatabaserust-analyzer cargo sqlx-core 0.8.3 migrate/migrate/MigrateDatabase# for Postgresrust-analyzer cargo sqlx-postgres 0.8.3 database/Postgres# { |
| 42 | fn create_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]create_database().(url: &str) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>> { |
| 43 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 44 | let (options, database) = parse_for_maintenancerust-analyzer cargo sqlx-postgres 0.8.3 migrate/parse_for_maintenance().(url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 45 | let mut conn = options.connectrust-analyzer cargo sqlx-postgres 0.8.3 options/connect/impl#[PgConnectOptions][ConnectOptions]connect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | |
| 47 | let _ = conn |
| 48 | .executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 49 | "CREATE DATABASE \"{}\"", |
| 50 | database.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('"', "\"\"") |
| 51 | )) |
| 52 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 53 | |
| 54 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 55 | }) |
| 56 | } |
| 57 | |
| 58 | fn database_existsrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]database_exists().(url: &str) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<bool, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>> { |
| 59 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 60 | let (options, database) = parse_for_maintenancerust-analyzer cargo sqlx-postgres 0.8.3 migrate/parse_for_maintenance().(url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 61 | let mut conn = options.connectrust-analyzer cargo sqlx-postgres 0.8.3 options/connect/impl#[PgConnectOptions][ConnectOptions]connect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 62 | |
| 63 | let exists: bool = |
| 64 | query_scalarrust-analyzer cargo sqlx-core 0.8.3 query_scalar/query_scalar().("select exists(SELECT 1 from pg_database WHERE datname = $1)") |
| 65 | .bindrust-analyzer cargo sqlx-core 0.8.3 query_scalar/impl#[`QueryScalar<'q, DB, O, <DB as Database>::Arguments<'q>>`]bind().(database) |
| 66 | .fetch_onerust-analyzer cargo sqlx-core 0.8.3 query_scalar/impl#[`QueryScalar<'q, DB, O, A>`]fetch_one().(&mut conn) |
| 67 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 68 | |
| 69 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(exists) |
| 70 | }) |
| 71 | } |
| 72 | |
| 73 | fn drop_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]drop_database().(url: &str) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>> { |
| 74 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 75 | let (options, database) = parse_for_maintenancerust-analyzer cargo sqlx-postgres 0.8.3 migrate/parse_for_maintenance().(url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 76 | let mut conn = options.connectrust-analyzer cargo sqlx-postgres 0.8.3 options/connect/impl#[PgConnectOptions][ConnectOptions]connect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 77 | |
| 78 | let _ = conn |
| 79 | .executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 80 | "DROP DATABASE IF EXISTS \"{}\"", |
| 81 | database.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('"', "\"\"") |
| 82 | )) |
| 83 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 84 | |
| 85 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | fn force_drop_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]force_drop_database().(url: &str) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>> { |
| 90 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 91 | let (options, database) = parse_for_maintenancerust-analyzer cargo sqlx-postgres 0.8.3 migrate/parse_for_maintenance().(url)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 92 | let mut conn = options.connectrust-analyzer cargo sqlx-postgres 0.8.3 options/connect/impl#[PgConnectOptions][ConnectOptions]connect().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 93 | |
| 94 | let row: (Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,) = query_asrust-analyzer cargo sqlx-core 0.8.3 query_as/query_as().("SELECT current_setting('server_version_num')") |
| 95 | .fetch_onerust-analyzer cargo sqlx-core 0.8.3 query_as/impl#[`QueryAs<'q, DB, O, A>`]fetch_one().(&mut conn) |
| 96 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 97 | |
| 98 | let version = row.0.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<i32>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 99 | |
| 100 | let pid_type = if version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]ge().90200 { "pid" } else { "procpid" }; |
| 101 | |
| 102 | conn.executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Deref]deref().formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 103 | "SELECT pg_terminate_backend(pg_stat_activity.{pid_type}) FROM pg_stat_activity \ |
| 104 | WHERE pg_stat_activity.datname = '{database}' AND {pid_type} <> pg_backend_pid()" |
| 105 | )) |
| 106 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 107 | |
| 108 | Selfrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]::drop_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[Postgres][MigrateDatabase]drop_database().(url).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). |
| 109 | }) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl Migraterust-analyzer cargo sqlx-core 0.8.3 migrate/migrate/Migrate# for PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection# { |
| 114 | fn ensure_migrations_tablerust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]ensure_migrations_table().(&mut self) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 115 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 116 | // language=SQL |
| 117 | self.executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().( |
| 118 | r#" |
| 119 | CREATE TABLE IF NOT EXISTS _sqlx_migrations ( |
| 120 | version BIGINT PRIMARY KEY, |
| 121 | description TEXT NOT NULL, |
| 122 | installed_on TIMESTAMPTZ NOT NULL DEFAULT now(), |
| 123 | success BOOLEAN NOT NULL, |
| 124 | checksum BYTEA NOT NULL, |
| 125 | execution_time BIGINT NOT NULL |
| 126 | ); |
| 127 | "#, |
| 128 | ) |
| 129 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 130 | |
| 131 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 132 | }) |
| 133 | } |
| 134 | |
| 135 | fn dirty_versionrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]dirty_version().(&mut self) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<i64>, MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 136 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 137 | // language=SQL |
| 138 | let row: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(i64,)> = query_asrust-analyzer cargo sqlx-core 0.8.3 query_as/query_as().( |
| 139 | "SELECT version FROM _sqlx_migrations WHERE success = false ORDER BY version LIMIT 1", |
| 140 | ) |
| 141 | .fetch_optionalrust-analyzer cargo sqlx-core 0.8.3 query_as/impl#[`QueryAs<'q, DB, O, A>`]fetch_optional().(self) |
| 142 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 143 | |
| 144 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(row.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|r| r.0)) |
| 145 | }) |
| 146 | } |
| 147 | |
| 148 | fn list_applied_migrationsrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]list_applied_migrations().( |
| 149 | &mut self, |
| 150 | ) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AppliedMigrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/AppliedMigration#>, MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 151 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 152 | // language=SQL |
| 153 | let rows: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<(i64, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>)> = |
| 154 | query_asrust-analyzer cargo sqlx-core 0.8.3 query_as/query_as().("SELECT version, checksum FROM _sqlx_migrations ORDER BY version") |
| 155 | .fetch_allrust-analyzer cargo sqlx-core 0.8.3 query_as/impl#[`QueryAs<'q, DB, O, A>`]fetch_all().(self) |
| 156 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 157 | |
| 158 | let migrations = rows |
| 159 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 160 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(version, checksum)| AppliedMigrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/AppliedMigration# { |
| 161 | versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/AppliedMigration#version., |
| 162 | checksumrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/AppliedMigration#checksum.: checksum.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 163 | }) |
| 164 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 165 | |
| 166 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(migrations) |
| 167 | }) |
| 168 | } |
| 169 | |
| 170 | fn lockrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]lock().(&mut self) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 171 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 172 | let database_name = current_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/current_database().(self).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 173 | let lock_id = generate_lock_idrust-analyzer cargo sqlx-postgres 0.8.3 migrate/generate_lock_id().(&database_name); |
| 174 | |
| 175 | // create an application lock over the database |
| 176 | // this function will not return until the lock is acquired |
| 177 | |
| 178 | // https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS |
| 179 | // https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS-TABLE |
| 180 | |
| 181 | // language=SQL |
| 182 | let _ = queryrust-analyzer cargo sqlx-core 0.8.3 query/query().("SELECT pg_advisory_lock($1)") |
| 183 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(lock_id) |
| 184 | .executerust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, A>`]execute().(self) |
| 185 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 186 | |
| 187 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | fn unlockrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]unlock().(&mut self) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 192 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 193 | let database_name = current_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/current_database().(self).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 194 | let lock_id = generate_lock_idrust-analyzer cargo sqlx-postgres 0.8.3 migrate/generate_lock_id().(&database_name); |
| 195 | |
| 196 | // language=SQL |
| 197 | let _ = queryrust-analyzer cargo sqlx-core 0.8.3 query/query().("SELECT pg_advisory_unlock($1)") |
| 198 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(lock_id) |
| 199 | .executerust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, A>`]execute().(self) |
| 200 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 201 | |
| 202 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 203 | }) |
| 204 | } |
| 205 | |
| 206 | fn applyrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]apply().<'e: 'm, 'm>( |
| 207 | &'e mut self, |
| 208 | migration: &'m Migrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#, |
| 209 | ) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'m, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 210 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 211 | let start = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(); |
| 212 | |
| 213 | // execute migration queries |
| 214 | if migration.no_txrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#no_tx. { |
| 215 | execute_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/execute_migration().(self, migration).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 216 | } else { |
| 217 | // Use a single transaction for the actual migration script and the essential bookeeping so we never |
| 218 | // execute migrations twice. See https://github.com/launchbadge/sqlx/issues/1966. |
| 219 | // The `execution_time` however can only be measured for the whole transaction. This value _only_ exists for |
| 220 | // data lineage and debugging reasons, so it is not super important if it is lost. So we initialize it to -1 |
| 221 | // and update it once the actual transaction completed. |
| 222 | let mut tx = self.beginrust-analyzer cargo sqlx-postgres 0.8.3 connection/impl#[PgConnection][Connection]begin().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 223 | execute_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/execute_migration().(&mut tx, migration).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 224 | tx.commitrust-analyzer cargo sqlx-core 0.8.3 transaction/impl#[`Transaction<'c, DB>`]commit().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 225 | } |
| 226 | |
| 227 | // Update `elapsed_time`. |
| 228 | // NOTE: The process may disconnect/die at this point, so the elapsed time value might be lost. We accept |
| 229 | // this small risk since this value is not super important. |
| 230 | let elapsed = start.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().(); |
| 231 | |
| 232 | // language=SQL |
| 233 | #[allow(clippy::cast_possible_truncation)] |
| 234 | let _ = queryrust-analyzer cargo sqlx-core 0.8.3 query/query().( |
| 235 | r#" |
| 236 | UPDATE _sqlx_migrations |
| 237 | SET execution_time = $1 |
| 238 | WHERE version = $2 |
| 239 | "#, |
| 240 | ) |
| 241 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(elapsed.as_nanosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]as_nanos().() as i64) |
| 242 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(migration.versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#version.) |
| 243 | .executerust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, A>`]execute().(self) |
| 244 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 245 | |
| 246 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(elapsed) |
| 247 | }) |
| 248 | } |
| 249 | |
| 250 | fn revertrust-analyzer cargo sqlx-postgres 0.8.3 migrate/impl#[PgConnection][Migrate]revert().<'e: 'm, 'm>( |
| 251 | &'e mut self, |
| 252 | migration: &'m Migrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#, |
| 253 | ) -> BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'m, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#>> { |
| 254 | Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(async move { |
| 255 | let start = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(); |
| 256 | |
| 257 | // execute migration queries |
| 258 | if migration.no_txrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#no_tx. { |
| 259 | revert_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/revert_migration().(self, migration).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 260 | } else { |
| 261 | // Use a single transaction for the actual migration script and the essential bookeeping so we never |
| 262 | // execute migrations twice. See https://github.com/launchbadge/sqlx/issues/1966. |
| 263 | let mut tx = self.beginrust-analyzer cargo sqlx-postgres 0.8.3 connection/impl#[PgConnection][Connection]begin().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 264 | revert_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/revert_migration().(&mut tx, migration).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 265 | tx.commitrust-analyzer cargo sqlx-core 0.8.3 transaction/impl#[`Transaction<'c, DB>`]commit().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 266 | } |
| 267 | |
| 268 | let elapsed = start.elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().(); |
| 269 | |
| 270 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(elapsed) |
| 271 | }) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | async fn execute_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/execute_migration().( |
| 276 | conn: &mut PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#, |
| 277 | migration: &Migrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#, |
| 278 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#> { |
| 279 | let _ = conn |
| 280 | .executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().migration.sqlrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#sql.) |
| 281 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). |
| 282 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#::ExecuteMigrationrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#ExecuteMigration#(e, migration.versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#version.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 283 | |
| 284 | // language=SQL |
| 285 | let _ = queryrust-analyzer cargo sqlx-core 0.8.3 query/query().( |
| 286 | r#" |
| 287 | INSERT INTO _sqlx_migrations ( version, description, success, checksum, execution_time ) |
| 288 | VALUES ( $1, $2, TRUE, $3, -1 ) |
| 289 | "#, |
| 290 | ) |
| 291 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(migration.versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#version.) |
| 292 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().migration.descriptionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#description.) |
| 293 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().migration.checksumrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#checksum.) |
| 294 | .executerust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, A>`]execute().(conn) |
| 295 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 296 | |
| 297 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 298 | } |
| 299 | |
| 300 | async fn revert_migrationrust-analyzer cargo sqlx-postgres 0.8.3 migrate/revert_migration().( |
| 301 | conn: &mut PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#, |
| 302 | migration: &Migrationrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#, |
| 303 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#> { |
| 304 | let _ = conn |
| 305 | .executerust-analyzer cargo sqlx-core 0.8.3 executor/Executor#execute().(&*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`][Deref]deref().migration.sqlrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#sql.) |
| 306 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). |
| 307 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#::ExecuteMigrationrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#ExecuteMigration#(e, migration.versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#version.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 308 | |
| 309 | // language=SQL |
| 310 | let _ = queryrust-analyzer cargo sqlx-core 0.8.3 query/query().(r#"DELETE FROM _sqlx_migrations WHERE version = $1"#) |
| 311 | .bindrust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, <DB as Database>::Arguments<'q>>`]bind().(migration.versionrust-analyzer cargo sqlx-core 0.8.3 migrate/migration/Migration#version.) |
| 312 | .executerust-analyzer cargo sqlx-core 0.8.3 query/impl#[`Query<'q, DB, A>`]execute().(conn) |
| 313 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 314 | |
| 315 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 316 | } |
| 317 | |
| 318 | async fn current_databaserust-analyzer cargo sqlx-postgres 0.8.3 migrate/current_database().(conn: &mut PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, MigrateErrorrust-analyzer cargo sqlx-core 0.8.3 migrate/error/MigrateError#> { |
| 319 | // language=SQL |
| 320 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(query_scalarrust-analyzer cargo sqlx-core 0.8.3 query_scalar/query_scalar().("SELECT current_database()") |
| 321 | .fetch_onerust-analyzer cargo sqlx-core 0.8.3 query_scalar/impl#[`QueryScalar<'q, DB, O, A>`]fetch_one().(conn) |
| 322 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 323 | } |
| 324 | |
| 325 | // inspired from rails: https://github.com/rails/rails/blob/6e49cc77ab3d16c06e12f93158eaf3e507d4120e/activerecord/lib/active_record/migration.rb#L1308 |
| 326 | fn generate_lock_idrust-analyzer cargo sqlx-postgres 0.8.3 migrate/generate_lock_id().(database_name: &str) -> i64 { |
| 327 | const CRC_IEEErust-analyzer cargo sqlx-postgres 0.8.3 migrate/CRC_IEEE.: crcrust-analyzer cargo crc 3.4.0 crate/::Crcrust-analyzer cargo crc 3.4.0 Crc#<u32> = crcrust-analyzer cargo crc 3.4.0 crate/::Crcrust-analyzer cargo crc 3.4.0 Crc#::<u32>::newrust-analyzer cargo crc 3.4.0 crc32/impl#[`Crc<u32, Table<L>>`]new().(&crcrust-analyzer cargo crc 3.4.0 crate/::CRC_32_ISO_HDLCrust-analyzer cargo crc-catalog 2.5.0 algorithm/CRC_32_ISO_HDLC.); |
| 328 | // 0x3d32ad9e chosen by fair dice roll |
| 329 | 0x3d32ad9e rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().(CRC_IEEErust-analyzer cargo sqlx-postgres 0.8.3 migrate/CRC_IEEE..checksumrust-analyzer cargo crc 3.4.0 crc32/impl#[`Crc<u32, Table<L>>`]checksum().(database_name.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()) as i64) |
| 330 | } |