From 1156eb4cf9822522672a7a7d8b1c8af7a556fd3b Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Tue, 13 Feb 2024 16:35:55 +0000 Subject: [PATCH 1/6] Add github action to check changelog --- .github/workflows/check_changelog.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/workflows/check_changelog.yml diff --git a/.github/workflows/check_changelog.yml b/.github/workflows/check_changelog.yml new file mode 100644 index 000000000..71e8dfdb4 --- /dev/null +++ b/.github/workflows/check_changelog.yml @@ -0,0 +1,11 @@ +name: check-changelog +on: + pull_request: + +jobs: + check-changelog: + runs-on: ubuntu-latest + steps: + - uses: tarides/changelog-check-action@v2 + with: + changelog: CHANGELOG.md From 41f38cf5425f499e9856cbbe5431ad2ba21f0816 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Tue, 13 Feb 2024 16:37:44 +0000 Subject: [PATCH 2/6] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea1ccf17..f3402320c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [553](https://github.com/thoth-pub/thoth/pull/553) - Upgrade rust to `1.76.0` in production and development `Dockerfile` - [305](https://github.com/thoth-pub/thoth/issues/305) - Update rust edition to 2021 +### Added + - [557](https://github.com/thoth-pub/thoth/pull/557) - Added github action to chech that the changelog has been updated on PRs + ## [[0.11.15]](https://github.com/thoth-pub/thoth/releases/tag/v0.11.15) - 2024-01-18 ### Changed - [536](https://github.com/thoth-pub/thoth/issues/536) - Rename "SciELO" location platform to "SciELO Books" From e8bbcdfd0589d6fe1a2036708058e2903bf943ab Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Feb 2024 09:37:41 +0000 Subject: [PATCH 3/6] Add function to revert migrations --- thoth-api/src/db.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/thoth-api/src/db.rs b/thoth-api/src/db.rs index 8e82f279f..cc9819318 100644 --- a/thoth-api/src/db.rs +++ b/thoth-api/src/db.rs @@ -39,3 +39,11 @@ pub fn run_migrations() -> ThothResult<()> { Err(error) => Err(ThothError::DatabaseError(error.to_string())), } } + +pub fn revert_migrations() -> ThothResult<()> { + let mut connection = establish_connection().get().unwrap(); + match connection.revert_all_migrations(MIGRATIONS) { + Ok(_) => Ok(()), + Err(error) => Err(ThothError::DatabaseError(error.to_string())), + } +} From 64d49acc67abb07d69fec24c7b7bf72a58756339 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Feb 2024 09:38:39 +0000 Subject: [PATCH 4/6] Add flag to CLI to revert migrations --- src/bin/thoth.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/bin/thoth.rs b/src/bin/thoth.rs index 1595db5d9..ac3cf990a 100644 --- a/src/bin/thoth.rs +++ b/src/bin/thoth.rs @@ -1,10 +1,10 @@ -use clap::{crate_authors, crate_version, value_parser, Arg, Command}; +use clap::{crate_authors, crate_version, value_parser, Arg, ArgAction, Command}; use dialoguer::{console::Term, theme::ColorfulTheme, Input, MultiSelect, Password, Select}; use dotenv::dotenv; use std::env; use thoth::api::account::model::{AccountData, LinkedPublisher}; use thoth::api::account::service::{all_emails, all_publishers, register, update_password}; -use thoth::api::db::{establish_connection, run_migrations}; +use thoth::api::db::{establish_connection, revert_migrations, run_migrations}; use thoth::api_server; use thoth::app_server; use thoth::export_server; @@ -129,7 +129,16 @@ fn thoth_commands() -> Command { .about(env!("CARGO_PKG_DESCRIPTION")) .subcommand_required(true) .arg_required_else_help(true) - .subcommand(Command::new("migrate").about("Run the database migrations")) + .subcommand( + Command::new("migrate") + .about("Run the database migrations") + .arg( + Arg::new("revert") + .long("revert") + .help("Revert all database migrations") + .action(ArgAction::SetTrue), + ), + ) .subcommand( Command::new("start") .about("Start an instance of Thoth API or GUI") @@ -240,7 +249,10 @@ fn main() -> ThothResult<()> { } _ => unreachable!(), }, - Some(("migrate", _)) => run_migrations(), + Some(("migrate", migrate_matches)) => match migrate_matches.get_flag("revert") { + true => revert_migrations(), + false => run_migrations(), + }, Some(("init", init_matches)) => { let host = init_matches.get_one::("host").unwrap().to_owned(); let port = init_matches.get_one::("port").unwrap().to_owned(); From 3a754c1b39e3f27a7410ffd8a8cf4e6d3685b588 Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Feb 2024 09:39:03 +0000 Subject: [PATCH 5/6] Test reverting migrations in github action --- .github/workflows/run_migrations.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/run_migrations.yml b/.github/workflows/run_migrations.yml index 776c95a6a..9b928204d 100644 --- a/.github/workflows/run_migrations.yml +++ b/.github/workflows/run_migrations.yml @@ -66,3 +66,8 @@ jobs: with: command: run args: migrate + - name: Revert migrations + uses: actions-rs/cargo@v1 + with: + command: run + args: migrate --revert From 9a4f99eda72a3b6d28488e82040b2e995c1797dc Mon Sep 17 00:00:00 2001 From: Javier Arias Date: Wed, 14 Feb 2024 09:41:55 +0000 Subject: [PATCH 6/6] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea1ccf17..13bbf4a41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [553](https://github.com/thoth-pub/thoth/pull/553) - Upgrade rust to `1.76.0` in production and development `Dockerfile` - [305](https://github.com/thoth-pub/thoth/issues/305) - Update rust edition to 2021 +### Added + - [503](https://github.com/thoth-pub/thoth/issues/503) - Allow reverting migrations in the CLI and check that migrations can be reverted in run-migration github action + ## [[0.11.15]](https://github.com/thoth-pub/thoth/releases/tag/v0.11.15) - 2024-01-18 ### Changed - [536](https://github.com/thoth-pub/thoth/issues/536) - Rename "SciELO" location platform to "SciELO Books"