Reorganize migrations and database stuff
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0fe30fa7a9
commit
8c2f76ddd2
@ -18,7 +18,7 @@ if [[ -z "$MIGRATION_NAME" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
MIGRATIONS_DIR="$PROJECT_ROOT/src/migrations"
|
||||
MIGRATIONS_DIR="$PROJECT_ROOT/src/database/migrations"
|
||||
|
||||
# echo "MIGRATIONS_DIR: $MIGRATIONS_DIR"
|
||||
|
||||
@ -57,9 +57,9 @@ for SUFFIX in "up" "down"; do
|
||||
touch "$migration_file"
|
||||
done
|
||||
|
||||
LINE_TO_INSERT=" migs.add(include_file_migration!($NEXT_MIGRATION, \"$NEXT_MIGRATION_PREFIX-$MIGRATION_NAME\"));"
|
||||
LINE_TO_INSERT="\ \ \ \ migs.add(include_file_migration!($NEXT_MIGRATION, \"$NEXT_MIGRATION_PREFIX-$MIGRATION_NAME\"));"
|
||||
|
||||
MIGRATIONS_RS="$PROJECT_ROOT/src/db.rs"
|
||||
MIGRATIONS_RS="$PROJECT_ROOT/src/database/migrations/mod.rs"
|
||||
echo "Inserting line in $MIGRATIONS_RS"
|
||||
sed -i "/INSERT MIGRATION ABOVE/i \
|
||||
$LINE_TO_INSERT" "$MIGRATIONS_RS"
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::migrations::{Migrations, SimpleMigration};
|
||||
use super::migration::{Migrations, SimpleMigration};
|
||||
|
||||
macro_rules! include_file_migration {
|
||||
($mig_version:expr, $mig_name:literal) => {
|
||||
SimpleMigration::new_box(
|
||||
$mig_version,
|
||||
include_str!(concat!("migrations/", $mig_name, "-up.sql")),
|
||||
include_str!(concat!("migrations/", $mig_name, "-down.sql")),
|
||||
include_str!(concat!($mig_name, "-up.sql")),
|
||||
include_str!(concat!($mig_name, "-down.sql")),
|
||||
)
|
||||
};
|
||||
}
|
||||
@ -19,4 +19,4 @@ pub fn create_migrations() -> Migrations {
|
||||
migs.add(include_file_migration!(5, "0005-view_program_sequence"));
|
||||
// INSERT MIGRATION ABOVE -- DO NOT EDIT THIS COMMENT
|
||||
migs
|
||||
}
|
||||
}
|
5
src/database/mod.rs
Normal file
5
src/database/mod.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod migration;
|
||||
mod migrations;
|
||||
|
||||
pub use migration::*;
|
||||
pub use migrations::create_migrations;
|
@ -7,8 +7,7 @@ use rusqlite::NO_PARAMS;
|
||||
use tracing::info;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
mod db;
|
||||
mod migrations;
|
||||
mod database;
|
||||
mod model;
|
||||
mod option_future;
|
||||
mod program_runner;
|
||||
@ -25,7 +24,7 @@ fn setup_db() -> Result<DbConnection> {
|
||||
// let conn = DbConnection::open_in_memory()?;
|
||||
let mut conn = DbConnection::open("test.db")?;
|
||||
|
||||
let migs = db::create_migrations();
|
||||
let migs = database::create_migrations();
|
||||
migs.apply(&mut conn)?;
|
||||
|
||||
Ok(conn)
|
||||
|
Loading…
x
Reference in New Issue
Block a user