Skip to content

Commit 5bde4c5

Browse files
committed
feat(mysql): create database if MYSQL_* env are defined
1 parent 460a278 commit 5bde4c5

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mysql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description = "MySQL plugin for FluentCI"
66
edition = "2021"
77
license = "MIT"
88
name = "mysql"
9-
version = "0.1.3"
9+
version = "0.1.4"
1010

1111
[lib]
1212
crate-type = [

mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use fluentci_pdk::dag;
3636

3737
// ...
3838

39-
dag().call("https://pkg.fluentci.io/[email protected].3?wasm=1", "start", vec![])?;
39+
dag().call("https://pkg.fluentci.io/[email protected].4?wasm=1", "start", vec![])?;
4040
```
4141

4242
## 📚 Examples

mysql/fluentci.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ keywords = [
88
]
99
license = "MIT"
1010
name = "mysql"
11-
version = "0.1.3"
11+
version = "0.1.4"

mysql/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ pub mod helpers;
66
#[plugin_fn]
77
pub fn start(_args: String) -> FnResult<String> {
88
helpers::setup()?;
9+
let user = dag().get_env("MYSQL_USER")?;
10+
let password = dag().get_env("MYSQL_PASSWORD")?;
11+
let database = dag().get_env("MYSQL_DATABASE")?;
912
let port = dag().get_env("MYSQL_PORT")?;
13+
14+
if user.is_empty() {
15+
dag().set_envs(vec![("MYSQL_USER".into(), "fluentci".into())])?;
16+
}
17+
18+
if password.is_empty() {
19+
dag().set_envs(vec![("MYSQL_PASSWORD".into(), "fluentci".into())])?;
20+
}
21+
22+
if database.is_empty() {
23+
dag().set_envs(vec![("MYSQL_DATABASE".into(), "demo".into())])?;
24+
}
25+
1026
let stdout = dag()
1127
.flox()?
1228
.with_workdir(".fluentci/mysql")?
@@ -20,6 +36,30 @@ pub fn start(_args: String) -> FnResult<String> {
2036
])?
2137
.wait_on(port.parse()?, None)?
2238
.with_exec(vec!["cat", "$MYSQL_HOME/mysql.log"])?
39+
.with_exec(vec![
40+
"mysql",
41+
"-u",
42+
"root",
43+
"--socket=$MYSQL_HOME/mysql.socket -e \"CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;\"",
44+
])?
45+
.with_exec(vec![
46+
"mysql",
47+
"-u",
48+
"root",
49+
"--socket=$MYSQL_HOME/mysql.socket -e \"CREATE USER IF NOT EXISTS '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';\"",
50+
])?
51+
.with_exec(vec![
52+
"mysql",
53+
"-u",
54+
"root",
55+
"--socket=$MYSQL_HOME/mysql.socket -e \"GRANT ALL PRIVILEGES ON $MYSQL_DATABASE.* TO '$MYSQL_USER'@'localhost';\"",
56+
])?
57+
.with_exec(vec![
58+
"mysql",
59+
"-u",
60+
"root",
61+
"--socket=$MYSQL_HOME/mysql.socket -e \"FLUSH PRIVILEGES;\"",
62+
])?
2363
.with_exec(vec!["overmind", "status"])?
2464
.stdout()?;
2565
Ok(stdout)

0 commit comments

Comments
 (0)