Code cleanup

Moved migrations/ into entity/
MessageIds now return errors except for API ones
This commit is contained in:
2024-02-03 16:21:16 +03:00
parent 64e3210cc5
commit bd10acb438
13 changed files with 67 additions and 62 deletions

View File

@ -10,4 +10,9 @@ workspace = true
[dependencies]
futures = "0.3"
sqlx = "0.7"
sqlx = { version = "0.7", features = [
"mysql",
"runtime-tokio-rustls",
"macros",
"migrate",
], default-features = false }

5
entity/build.rs Normal file
View File

@ -0,0 +1,5 @@
// generated by `sqlx migrate build-script`
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
}

View File

@ -0,0 +1,3 @@
DROP TABLE account;
DROP TABLE master_pass;

View File

@ -0,0 +1,16 @@
CREATE TABLE
master_pass (
user_id BIGINT UNSIGNED NOT NULL PRIMARY KEY,
salt BINARY(64) NOT NULL,
password_hash BINARY(64) NOT NULL
);
CREATE TABLE
account (
user_id BIGINT UNSIGNED NOT NULL,
name VARCHAR(255) NOT NULL,
salt BINARY(64) NOT NULL,
enc_login VARBINARY(256) NOT NULL,
enc_password VARBINARY(256) NOT NULL,
PRIMARY KEY (user_id, name)
);

View File

@ -5,6 +5,8 @@ pub mod account;
pub mod master_pass;
pub mod prelude;
pub use sqlx::Result;
pub use sqlx::{mysql::MySqlPool as Pool, Result};
pub type Pool = sqlx::mysql::MySqlPool;
pub async fn migrate(pool: &Pool) -> Result<(), sqlx::migrate::MigrateError> {
sqlx::migrate!().run(pool).await
}

View File

@ -1,2 +1 @@
pub use crate::account::Account;
pub use crate::master_pass::MasterPass;
pub use crate::{account::Account, master_pass::MasterPass, Pool};