Skip to content

Commit

Permalink
fix: database migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jun 22, 2023
1 parent 31afbe3 commit e40e7ba
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
name = "crosup"
readme = "../../README.md"
repository = "https://github.com/tsirysndr/crosup"
version = "0.4.6"
version = "0.4.7"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 0 additions & 2 deletions crates/cli/src/cmd/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::{cmd::print_diff, macros::install, types::InstallArgs};
pub async fn execute_add(tools: Vec<String>, ask: bool) -> Result<(), Error> {
let (mut current_config, filename, content, is_present) = verify_if_config_file_is_present()?;

migration::run().await;

current_config.packages = match current_config.packages {
Some(ref mut packages) => {
tools.iter().for_each(|x| {
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/cmd/diff.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Error;
use crosup_core::config::verify_if_config_file_is_present;
use crosup_repo::{file::FileRepo, modification::ModificationRepo};
use migration::MigratorTrait;
use owo_colors::OwoColorize;
use sea_orm::DatabaseConnection;

Expand All @@ -11,9 +12,8 @@ use super::get_database_connection;
pub async fn execute_diff() -> Result<(), Error> {
let (_, filename, content, _) = verify_if_config_file_is_present()?;

migration::run().await;

let db: DatabaseConnection = get_database_connection().await?;
migration::Migrator::up(&db, None).await?;
let current_dir = std::env::current_dir()?;
let path = format!("{}/{}", current_dir.display(), filename);

Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/cmd/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use anyhow::Error;
use crosup_core::config::verify_if_config_file_is_present;
use crosup_repo::{file::FileRepo, modification::ModificationRepo};
use crosup_tui::{history::display_history, App};
use migration::MigratorTrait;
use owo_colors::OwoColorize;
use sea_orm::DatabaseConnection;

pub async fn execute_history() -> Result<(), Error> {
let (_, filename, _, _) = verify_if_config_file_is_present()?;

migration::run().await;

let db: DatabaseConnection = get_database_connection().await?;

migration::Migrator::up(&db, None).await?;

let current_dir = std::env::current_dir()?;
let path = format!("{}/{}", current_dir.display(), filename);

Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crosup_core::{
use crosup_repo::{file::FileRepo, modification::ModificationRepo};
use crosup_ssh::setup_ssh_connection;
use crosup_types::configuration::Configuration;
use migration::MigratorTrait;
use owo_colors::OwoColorize;
use sea_orm::{Database, DatabaseConnection};
use ssh2::Session;
Expand All @@ -15,8 +16,6 @@ use crate::{macros::install, types::InstallArgs};
pub async fn execute_install(args: InstallArgs) -> Result<(), Error> {
let (config, filename, content, _) = verify_if_config_file_is_present()?;

migration::run().await;

let mut config = match args.tools.clone() {
Some(packages) => Configuration {
packages: Some(packages),
Expand Down Expand Up @@ -81,6 +80,8 @@ pub async fn execute_install(args: InstallArgs) -> Result<(), Error> {

let db: DatabaseConnection = Database::connect(&database_url).await?;

migration::Migrator::up(&db, None).await?;

let current_dir = std::env::current_dir()?;
let path = format!("{}/{}", current_dir.display(), filename);

Expand Down

0 comments on commit e40e7ba

Please sign in to comment.