risedev/task/
mysql_service.rs1use super::docker_service::{DockerService, DockerServiceConfig};
16use crate::MySqlConfig;
17
18impl DockerServiceConfig for MySqlConfig {
19 fn id(&self) -> String {
20 self.id.clone()
21 }
22
23 fn is_user_managed(&self) -> bool {
24 self.user_managed
25 }
26
27 fn image(&self) -> String {
28 self.image.clone()
29 }
30
31 fn envs(&self) -> Vec<(String, String)> {
32 let mut envs = vec![("MYSQL_DATABASE".to_owned(), self.database.clone())];
33 if self.user == "root" {
34 if self.password.is_empty() {
35 envs.push(("MYSQL_ALLOW_EMPTY_PASSWORD".to_owned(), "1".to_owned()));
36 } else {
37 envs.push(("MYSQL_ROOT_PASSWORD".to_owned(), self.password.clone()));
38 }
39 } else {
40 envs.extend([
41 ("MYSQL_ALLOW_EMPTY_PASSWORD".to_owned(), "1".to_owned()),
42 ("MYSQL_USER".to_owned(), self.user.clone()),
43 ("MYSQL_PASSWORD".to_owned(), self.password.clone()),
44 ]);
45 }
46 envs
47 }
48
49 fn ports(&self) -> Vec<(String, String)> {
50 vec![(self.port.to_string(), "3306".to_owned())]
51 }
52
53 fn data_path(&self) -> Option<String> {
54 self.persist_data.then(|| "/var/lib/mysql".to_owned())
55 }
56}
57
58pub type MySqlService = DockerService<MySqlConfig>;