diff --git a/migrations/20220203034730_create-initial-table.sql b/migrations/20220203034730_create-initial-table.sql index 9677b35..4b6c083 100644 --- a/migrations/20220203034730_create-initial-table.sql +++ b/migrations/20220203034730_create-initial-table.sql @@ -4,11 +4,10 @@ CREATE TABLE application ( app_name TEXT NOT NULL, url TEXT NOT NULL, description TEXT, - active Boolean NOT NULL DEFAULT 1, + active Boolean DEFAULT 1 NOT NULL, glyph TEXT, application_category_id INTEGER, - alive Boolean NOT NULL DEFAULT 1, - enable_healthcheck Boolean NOT NULL DEFAULT 0 + enable_healthcheck Boolean DEFAULT 0 NOT NULL ); CREATE TABLE application_category ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, diff --git a/src/api/mod.rs b/src/api/mod.rs index 5bf6b6f..a84f2e8 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -89,11 +89,6 @@ pub mod test_prelude { pub use crate::error::Result; pub use actix_web::dev::ServiceResponse; pub use actix_web::{test, web, App}; - use sea_orm::sea_query::TableCreateStatement; - use sea_orm::ConnectionTrait; - use sea_orm::Database; - use sea_orm::DbBackend; - use sea_orm::Schema; pub use sea_orm::{ entity::prelude::*, entity::*, tests_cfg::*, DatabaseBackend, MockDatabase, MockExecResult, Transaction, @@ -102,22 +97,11 @@ pub mod test_prelude { /// Sets up a testing state with an in-memory database and creates the scheme. pub async fn setup_state() -> Result> { - let db = Database::connect("sqlite::memory:").await?; - let schema = Schema::new(DbBackend::Sqlite); + let pool = sqlx::SqlitePool::connect(":memory:").await?; + sqlx::migrate!("./migrations").run(&pool).await?; + tracing::info!("Database migrated"); - let stmt: TableCreateStatement = schema.create_table_from_entity(application::Entity); - db.execute(db.get_database_backend().build(&stmt)).await?; - let stmt: TableCreateStatement = - schema.create_table_from_entity(application_category::Entity); - db.execute(db.get_database_backend().build(&stmt)).await?; - let stmt: TableCreateStatement = schema.create_table_from_entity(bookmark::Entity); - db.execute(db.get_database_backend().build(&stmt)).await?; - - let stmt: TableCreateStatement = schema.create_table_from_entity(bookmark_category::Entity); - db.execute(db.get_database_backend().build(&stmt)).await?; - - let stmt: TableCreateStatement = schema.create_table_from_entity(setting::Entity); - db.execute(db.get_database_backend().build(&stmt)).await?; + let db = sea_orm::SqlxSqliteConnector::from_sqlx_sqlite_pool(pool); auth::generate_secret(&db).await?;