Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions optd-persistent/src/bin/migrate_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use optd_persistent::{migrate, TEST_DATABASE_URL};
use sea_orm::*;
use sea_orm_migration::prelude::*;

#[tokio::main]
async fn main() {
let _ = std::fs::remove_file(TEST_DATABASE_URL);

let db = Database::connect(TEST_DATABASE_URL)
.await
.expect("Unable to connect to the database");

migrate(&db)
.await
.expect("Something went wrong during migration");

db.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Sqlite,
"PRAGMA foreign_keys = ON;".to_owned(),
))
.await
.expect("Unable to enable foreign keys");
}
1 change: 1 addition & 0 deletions optd-persistent/src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
#![allow(dead_code, unused_imports, unused_variables)]

pub use super::attribute::Entity as Attribute;
pub use super::attribute_constraint_junction::Entity as AttributeConstraintJunction;
Expand Down
4 changes: 4 additions & 0 deletions optd-persistent/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use sea_orm::*;
use sea_orm_migration::prelude::*;

mod entities;
mod migrator;
mod orm_manager;
mod storage_layer;
use migrator::Migrator;

pub const DATABASE_URL: &str = "sqlite:./sqlite.db?mode=rwc";
pub const DATABASE_FILE: &str = "./sqlite.db";
pub const TEST_DATABASE_URL: &str = "sqlite:./test.db?mode=rwc";

pub async fn migrate(db: &DatabaseConnection) -> Result<(), DbErr> {
Migrator::refresh(db).await
Expand Down
Loading