sqlx_core_oldapi/any/
migrate.rs1use crate::any::connection::AnyConnectionKind;
2use crate::any::kind::AnyKind;
3use crate::any::{Any, AnyConnection};
4use crate::error::Result;
5use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateResult, 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<()>> {
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 #[cfg(feature = "odbc")]
27 AnyKind::Odbc => unimplemented!(),
28 }
29 })
30 }
31
32 fn database_exists(url: &str) -> BoxFuture<'_, Result<bool>> {
33 Box::pin(async move {
34 match AnyKind::from_str(url)? {
35 #[cfg(feature = "postgres")]
36 AnyKind::Postgres => crate::postgres::Postgres::database_exists(url).await,
37
38 #[cfg(feature = "sqlite")]
39 AnyKind::Sqlite => crate::sqlite::Sqlite::database_exists(url).await,
40
41 #[cfg(feature = "mysql")]
42 AnyKind::MySql => crate::mysql::MySql::database_exists(url).await,
43
44 #[cfg(feature = "mssql")]
45 AnyKind::Mssql => unimplemented!(),
46
47 #[cfg(feature = "odbc")]
48 AnyKind::Odbc => unimplemented!(),
49 }
50 })
51 }
52
53 fn drop_database(url: &str) -> BoxFuture<'_, Result<()>> {
54 Box::pin(async move {
55 match AnyKind::from_str(url)? {
56 #[cfg(feature = "postgres")]
57 AnyKind::Postgres => crate::postgres::Postgres::drop_database(url).await,
58
59 #[cfg(feature = "sqlite")]
60 AnyKind::Sqlite => crate::sqlite::Sqlite::drop_database(url).await,
61
62 #[cfg(feature = "mysql")]
63 AnyKind::MySql => crate::mysql::MySql::drop_database(url).await,
64
65 #[cfg(feature = "mssql")]
66 AnyKind::Mssql => unimplemented!(),
67
68 #[cfg(feature = "odbc")]
69 AnyKind::Odbc => unimplemented!(),
70 }
71 })
72 }
73}
74
75impl Migrate for AnyConnection {
76 fn ensure_migrations_table(&mut self) -> BoxFuture<'_, Result<()>> {
77 match &mut self.0 {
78 #[cfg(feature = "postgres")]
79 AnyConnectionKind::Postgres(conn) => conn.ensure_migrations_table(),
80
81 #[cfg(feature = "sqlite")]
82 AnyConnectionKind::Sqlite(conn) => conn.ensure_migrations_table(),
83
84 #[cfg(feature = "mysql")]
85 AnyConnectionKind::MySql(conn) => conn.ensure_migrations_table(),
86
87 #[cfg(feature = "mssql")]
88 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
89
90 #[cfg(feature = "odbc")]
91 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
92 }
93 }
94
95 #[allow(deprecated)]
96 fn version(&mut self) -> BoxFuture<'_, Result<Option<(i64, bool)>>> {
97 match &mut self.0 {
98 #[cfg(feature = "postgres")]
99 AnyConnectionKind::Postgres(conn) => conn.version(),
100
101 #[cfg(feature = "sqlite")]
102 AnyConnectionKind::Sqlite(conn) => conn.version(),
103
104 #[cfg(feature = "mysql")]
105 AnyConnectionKind::MySql(conn) => conn.version(),
106
107 #[cfg(feature = "mssql")]
108 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
109
110 #[cfg(feature = "odbc")]
111 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
112 }
113 }
114
115 fn dirty_version(&mut self) -> BoxFuture<'_, Result<Option<i64>>> {
116 match &mut self.0 {
117 #[cfg(feature = "postgres")]
118 AnyConnectionKind::Postgres(conn) => conn.dirty_version(),
119
120 #[cfg(feature = "sqlite")]
121 AnyConnectionKind::Sqlite(conn) => conn.dirty_version(),
122
123 #[cfg(feature = "mysql")]
124 AnyConnectionKind::MySql(conn) => conn.dirty_version(),
125
126 #[cfg(feature = "mssql")]
127 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
128
129 #[cfg(feature = "odbc")]
130 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
131 }
132 }
133
134 #[allow(deprecated)]
135 fn validate<'e: 'm, 'm>(
136 &'e mut self,
137 migration: &'m Migration,
138 ) -> BoxFuture<'m, MigrateResult<()>> {
139 match &mut self.0 {
140 #[cfg(feature = "postgres")]
141 AnyConnectionKind::Postgres(conn) => conn.validate(migration),
142
143 #[cfg(feature = "sqlite")]
144 AnyConnectionKind::Sqlite(conn) => conn.validate(migration),
145
146 #[cfg(feature = "mysql")]
147 AnyConnectionKind::MySql(conn) => conn.validate(migration),
148
149 #[cfg(feature = "mssql")]
150 AnyConnectionKind::Mssql(_conn) => {
151 let _ = migration;
152 unimplemented!()
153 }
154
155 #[cfg(feature = "odbc")]
156 AnyConnectionKind::Odbc(_conn) => {
157 let _ = migration;
158 unimplemented!()
159 }
160 }
161 }
162
163 fn list_applied_migrations(&mut self) -> BoxFuture<'_, Result<Vec<AppliedMigration>>> {
164 match &mut self.0 {
165 #[cfg(feature = "postgres")]
166 AnyConnectionKind::Postgres(conn) => conn.list_applied_migrations(),
167
168 #[cfg(feature = "sqlite")]
169 AnyConnectionKind::Sqlite(conn) => conn.list_applied_migrations(),
170
171 #[cfg(feature = "mysql")]
172 AnyConnectionKind::MySql(conn) => conn.list_applied_migrations(),
173
174 #[cfg(feature = "mssql")]
175 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
176
177 #[cfg(feature = "odbc")]
178 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
179 }
180 }
181
182 fn lock(&mut self) -> BoxFuture<'_, Result<()>> {
183 match &mut self.0 {
184 #[cfg(feature = "postgres")]
185 AnyConnectionKind::Postgres(conn) => conn.lock(),
186
187 #[cfg(feature = "sqlite")]
188 AnyConnectionKind::Sqlite(conn) => conn.lock(),
189
190 #[cfg(feature = "mysql")]
191 AnyConnectionKind::MySql(conn) => conn.lock(),
192
193 #[cfg(feature = "mssql")]
194 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
195
196 #[cfg(feature = "odbc")]
197 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
198 }
199 }
200
201 fn unlock(&mut self) -> BoxFuture<'_, Result<()>> {
202 match &mut self.0 {
203 #[cfg(feature = "postgres")]
204 AnyConnectionKind::Postgres(conn) => conn.unlock(),
205
206 #[cfg(feature = "sqlite")]
207 AnyConnectionKind::Sqlite(conn) => conn.unlock(),
208
209 #[cfg(feature = "mysql")]
210 AnyConnectionKind::MySql(conn) => conn.unlock(),
211
212 #[cfg(feature = "mssql")]
213 AnyConnectionKind::Mssql(_conn) => unimplemented!(),
214
215 #[cfg(feature = "odbc")]
216 AnyConnectionKind::Odbc(_conn) => unimplemented!(),
217 }
218 }
219
220 fn apply<'e: 'm, 'm>(
221 &'e mut self,
222 migration: &'m Migration,
223 ) -> BoxFuture<'m, Result<Duration>> {
224 match &mut self.0 {
225 #[cfg(feature = "postgres")]
226 AnyConnectionKind::Postgres(conn) => conn.apply(migration),
227
228 #[cfg(feature = "sqlite")]
229 AnyConnectionKind::Sqlite(conn) => conn.apply(migration),
230
231 #[cfg(feature = "mysql")]
232 AnyConnectionKind::MySql(conn) => conn.apply(migration),
233
234 #[cfg(feature = "mssql")]
235 AnyConnectionKind::Mssql(_conn) => {
236 let _ = migration;
237 unimplemented!()
238 }
239
240 #[cfg(feature = "odbc")]
241 AnyConnectionKind::Odbc(_conn) => {
242 let _ = migration;
243 unimplemented!()
244 }
245 }
246 }
247
248 fn revert<'e: 'm, 'm>(
249 &'e mut self,
250 migration: &'m Migration,
251 ) -> BoxFuture<'m, Result<Duration>> {
252 match &mut self.0 {
253 #[cfg(feature = "postgres")]
254 AnyConnectionKind::Postgres(conn) => conn.revert(migration),
255
256 #[cfg(feature = "sqlite")]
257 AnyConnectionKind::Sqlite(conn) => conn.revert(migration),
258
259 #[cfg(feature = "mysql")]
260 AnyConnectionKind::MySql(conn) => conn.revert(migration),
261
262 #[cfg(feature = "mssql")]
263 AnyConnectionKind::Mssql(_conn) => {
264 let _ = migration;
265 unimplemented!()
266 }
267
268 #[cfg(feature = "odbc")]
269 AnyConnectionKind::Odbc(_conn) => {
270 let _ = migration;
271 unimplemented!()
272 }
273 }
274 }
275}