Move database migrations to SQLx

This commit is contained in:
jude 2023-03-23 11:38:53 +00:00
parent 4edcee2567
commit 31ee6b4540
9 changed files with 441 additions and 382 deletions

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/migrations/00-initial.sql" dialect="GenericSQL" />
<file url="PROJECT" dialect="MySQL" />
</component>
</project>

809
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,11 +7,11 @@ edition = "2018"
[dependencies]
songbird = { version = "0.3", features = ["builtin-queue"] }
poise = "0.3"
sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal"] }
sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "migrate"] }
tokio = { version = "1", features = ["fs", "process", "io-util"] }
lazy_static = "1.4"
reqwest = "0.11"
env_logger = "0.9"
env_logger = "0.10"
regex = "1.4"
log = "0.4"
serde_json = "1.0"
@ -20,3 +20,6 @@ serde = "1.0"
[patch."https://github.com/serenity-rs/serenity"]
serenity = { version = "0.11.5" }
[package.metadata.deb]
depends = ["$auto", "ffmpeg", "libopus-dev"]

3
build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("cargo:rerun-if-changed=migrations");
}

View File

@ -66,7 +66,6 @@ pub async fn register_application_commands(
Ok(())
}
// entry point
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
env_logger::init();
@ -129,6 +128,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.await
.unwrap();
sqlx::migrate!().run(&database).await?;
poise::Framework::builder()
.token(discord_token)
.user_data_setup(move |ctx, _bot, framework| {