sqlx_core_guts/any/
migrate.rs1use crate::any::connection::AnyConnectionKind;
2use crate::any::kind::AnyKind;
3use crate::any::{Any, AnyConnection};
4use crate::error::Error;
5use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateError, Migration};
6use futures_core::future::BoxFuture;
7use std::str::FromStr;
8use std::time::Duration;
9
10impl MigrateDatabase for Any {
11 fn create_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
12 Box::pin(async move {
13 match AnyKind::from_str(url)? {
14 #[cfg(feature = "postgres")]
15 AnyKind::Postgres => crate::postgres::Postgres::create_database(url).await,
16
17 #[cfg(feature = "sqlite")]
18 AnyKind::Sqlite => crate::sqlite::Sqlite::create_database(url).await,
19
20 #[cfg(feature = "mysql")]
21 AnyKind::MySql => crate::mysql::MySql::create_database(url).await,
22
23 #[cfg(feature = "mssql")]
24 AnyKind::Mssql => unimplemented!(),
25 }
26 })
27 }
28
29 fn database_exists(url: &str) -> BoxFuture<'_, Result<bool, Error>> {
30 Box::pin(async move {
31 match AnyKind::from_str(url)? {
32 #[cfg(feature = "postgres")]
33 AnyKind::Postgres => crate::postgres::Postgres::database_exists(url).await,
34
35 #[cfg(feature = "sqlite")]
36 AnyKind::Sqlite => crate::sqlite::Sqlite::database_exists(url).await,
37
38 #[cfg(feature = "mysql")]
39 AnyKind::MySql => crate::mysql::MySql::database_exists(url).await,
40
41 #[cfg(feature = "mssql")]
42 AnyKind::Mssql => unimplemented!(),
43 }
44 })
45 }
46
47 fn drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
48 Box::pin(async move {
49 match AnyKind::from_str(url)? {
50 #[cfg(feature = "postgres")]
51 AnyKind::Postgres => crate::postgres::Postgres::drop_database(url).await,
52
53 #[cfg(feature = "sqlite")]
54 AnyKind::Sqlite => crate::sqlite::Sqlite::drop_database(url).await,
55
56 #[cfg(feature = "mysql")]
57 AnyKind::MySql => crate::mysql::MySql::drop_database(url).await,
58
59 #[cfg(feature = "mssql")]
60 AnyKind::Mssql => unimplemented!(),
61 }
62 })
63 }
64}
65
66impl Migrate for AnyConnection {
67 fn ensure_migrations_table(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
68 match &mut self.0 {
69 #[cfg(feature = "postgres")]
70 AnyConnectionKind::Postgres(conn) => conn.ensure_migrations_table(),
71
72 #[cfg(feature = "sqlite")]
73 AnyConnectionKind::Sqlite(conn) => conn.ensure_migrations_table(),
74
75 #[cfg(feature = "mysql")]
76 AnyConnectionKind::MySql(conn) => conn.ensure_migrations_table(),
77
78 #[cfg(feature = "mssql")]
79 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
80 }
81 }
82
83 #[allow(deprecated)]
84 fn version(&mut self) -> BoxFuture<'_, Result<Option<(i64, bool)>, MigrateError>> {
85 match &mut self.0 {
86 #[cfg(feature = "postgres")]
87 AnyConnectionKind::Postgres(conn) => conn.version(),
88
89 #[cfg(feature = "sqlite")]
90 AnyConnectionKind::Sqlite(conn) => conn.version(),
91
92 #[cfg(feature = "mysql")]
93 AnyConnectionKind::MySql(conn) => conn.version(),
94
95 #[cfg(feature = "mssql")]
96 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
97 }
98 }
99
100 fn dirty_version(&mut self) -> BoxFuture<'_, Result<Option<i64>, MigrateError>> {
101 match &mut self.0 {
102 #[cfg(feature = "postgres")]
103 AnyConnectionKind::Postgres(conn) => conn.dirty_version(),
104
105 #[cfg(feature = "sqlite")]
106 AnyConnectionKind::Sqlite(conn) => conn.dirty_version(),
107
108 #[cfg(feature = "mysql")]
109 AnyConnectionKind::MySql(conn) => conn.dirty_version(),
110
111 #[cfg(feature = "mssql")]
112 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
113 }
114 }
115
116 #[allow(deprecated)]
117 fn validate<'e: 'm, 'm>(
118 &'e mut self,
119 migration: &'m Migration,
120 ) -> BoxFuture<'m, Result<(), MigrateError>> {
121 match &mut self.0 {
122 #[cfg(feature = "postgres")]
123 AnyConnectionKind::Postgres(conn) => conn.validate(migration),
124
125 #[cfg(feature = "sqlite")]
126 AnyConnectionKind::Sqlite(conn) => conn.validate(migration),
127
128 #[cfg(feature = "mysql")]
129 AnyConnectionKind::MySql(conn) => conn.validate(migration),
130
131 #[cfg(feature = "mssql")]
132 AnyConnectionKind::Mssql(_conn) => {
133 let _ = migration;
134 unimplemented!()
135 }
136 }
137 }
138
139 fn list_applied_migrations(
140 &mut self,
141 ) -> BoxFuture<'_, Result<Vec<AppliedMigration>, MigrateError>> {
142 match &mut self.0 {
143 #[cfg(feature = "postgres")]
144 AnyConnectionKind::Postgres(conn) => conn.list_applied_migrations(),
145
146 #[cfg(feature = "sqlite")]
147 AnyConnectionKind::Sqlite(conn) => conn.list_applied_migrations(),
148
149 #[cfg(feature = "mysql")]
150 AnyConnectionKind::MySql(conn) => conn.list_applied_migrations(),
151
152 #[cfg(feature = "mssql")]
153 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
154 }
155 }
156
157 fn lock(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
158 match &mut self.0 {
159 #[cfg(feature = "postgres")]
160 AnyConnectionKind::Postgres(conn) => conn.lock(),
161
162 #[cfg(feature = "sqlite")]
163 AnyConnectionKind::Sqlite(conn) => conn.lock(),
164
165 #[cfg(feature = "mysql")]
166 AnyConnectionKind::MySql(conn) => conn.lock(),
167
168 #[cfg(feature = "mssql")]
169 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
170 }
171 }
172
173 fn unlock(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
174 match &mut self.0 {
175 #[cfg(feature = "postgres")]
176 AnyConnectionKind::Postgres(conn) => conn.unlock(),
177
178 #[cfg(feature = "sqlite")]
179 AnyConnectionKind::Sqlite(conn) => conn.unlock(),
180
181 #[cfg(feature = "mysql")]
182 AnyConnectionKind::MySql(conn) => conn.unlock(),
183
184 #[cfg(feature = "mssql")]
185 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
186 }
187 }
188
189 fn apply<'e: 'm, 'm>(
190 &'e mut self,
191 migration: &'m Migration,
192 ) -> BoxFuture<'m, Result<Duration, MigrateError>> {
193 match &mut self.0 {
194 #[cfg(feature = "postgres")]
195 AnyConnectionKind::Postgres(conn) => conn.apply(migration),
196
197 #[cfg(feature = "sqlite")]
198 AnyConnectionKind::Sqlite(conn) => conn.apply(migration),
199
200 #[cfg(feature = "mysql")]
201 AnyConnectionKind::MySql(conn) => conn.apply(migration),
202
203 #[cfg(feature = "mssql")]
204 AnyConnectionKind::Mssql(_conn) => {
205 let _ = migration;
206 unimplemented!()
207 }
208 }
209 }
210
211 fn revert<'e: 'm, 'm>(
212 &'e mut self,
213 migration: &'m Migration,
214 ) -> BoxFuture<'m, Result<Duration, MigrateError>> {
215 match &mut self.0 {
216 #[cfg(feature = "postgres")]
217 AnyConnectionKind::Postgres(conn) => conn.revert(migration),
218
219 #[cfg(feature = "sqlite")]
220 AnyConnectionKind::Sqlite(conn) => conn.revert(migration),
221
222 #[cfg(feature = "mysql")]
223 AnyConnectionKind::MySql(conn) => conn.revert(migration),
224
225 #[cfg(feature = "mssql")]
226 AnyConnectionKind::Mssql(_conn) => {
227 let _ = migration;
228 unimplemented!()
229 }
230 }
231 }
232}