Skip to content

Create crates-admin migrate to sync categories and migrate the db #3556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2021
Merged
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
1 change: 0 additions & 1 deletion .buildpacks
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
https://github.com/emk/heroku-buildpack-rust#cfa0f06
https://github.com/heroku/heroku-buildpack-nodejs#v176
https://github.com/heroku/heroku-buildpack-nginx#53b03b0
https://github.com/sgrif/heroku-buildpack-diesel#f605edd
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ derive_deref = "1.1.1"
dialoguer = "0.8"
diesel = { version = "1.4.0", features = ["postgres", "serde_json", "chrono", "r2d2"] }
diesel_full_text_search = "1.0.0"
diesel_migrations = { version = "1.3.0", features = ["postgres"] }
dotenv = "0.15"
flate2 = "1.0"
futures-channel = { version = "0.3.1", default-features = false }
Expand Down Expand Up @@ -88,7 +89,6 @@ url = "2.1"
[dev-dependencies]
claim = "0.5"
conduit-test = "0.9.0-alpha.4"
diesel_migrations = { version = "1.3.0", features = ["postgres"] }
hyper-tls = "0.5"
lazy_static = "1.0"
tokio = "1"
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release: bin/diesel migration run
release: ./target/release/crates-admin migrate
web: ./target/release/server
background_worker: ./target/release/background-worker
19 changes: 19 additions & 0 deletions src/admin/migrate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use anyhow::Error;

static CATEGORIES_TOML: &'static str = include_str!("../boot/categories.toml");
diesel_migrations::embed_migrations!("./migrations");

#[derive(clap::Clap, Debug, Copy, Clone)]
#[clap(name = "migrate", about = "Migrate the database.")]
pub struct Opts;

pub fn run(_opts: Opts) -> Result<(), Error> {
println!("==> migrating the database");
let conn = crate::db::connect_now()?;
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?;

println!("==> synchronizing crate categories");
crate::boot::categories::sync(CATEGORIES_TOML).unwrap();

Ok(())
}
1 change: 1 addition & 0 deletions src/admin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod delete_crate;
pub mod delete_version;
pub mod dialoguer;
pub mod migrate;
pub mod on_call;
pub mod populate;
pub mod render_readmes;
Expand Down
6 changes: 4 additions & 2 deletions src/bin/crates-admin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![warn(clippy::all, rust_2018_idioms)]

use cargo_registry::admin::{
delete_crate, delete_version, populate, render_readmes, test_pagerduty, transfer_crates,
verify_token,
delete_crate, delete_version, migrate, populate, render_readmes, test_pagerduty,
transfer_crates, verify_token,
};

use clap::Clap;
Expand All @@ -23,6 +23,7 @@ enum SubCommand {
TestPagerduty(test_pagerduty::Opts),
TransferCrates(transfer_crates::Opts),
VerifyToken(verify_token::Opts),
Migrate(migrate::Opts),
}

fn main() {
Expand All @@ -36,5 +37,6 @@ fn main() {
SubCommand::TestPagerduty(opts) => test_pagerduty::run(opts).unwrap(),
SubCommand::TransferCrates(opts) => transfer_crates::run(opts),
SubCommand::VerifyToken(opts) => verify_token::run(opts).unwrap(),
SubCommand::Migrate(opts) => migrate::run(opts).unwrap(),
}
}
7 changes: 1 addition & 6 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![warn(clippy::all, rust_2018_idioms)]
#![allow(unknown_lints)]

use cargo_registry::{boot, App, Env};
use cargo_registry::{App, Env};
use std::{borrow::Cow, fs::File, process::Command, sync::Arc, time::Duration};

use conduit_hyper::Service;
Expand Down Expand Up @@ -43,11 +43,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let handler = cargo_registry::build_handler(app.clone());

// On every server restart, ensure the categories available in the database match
// the information in *src/categories.toml*.
let categories_toml = include_str!("../boot/categories.toml");
boot::categories::sync(categories_toml).unwrap();

let heroku = dotenv::var("HEROKU").is_ok();
let fastboot = dotenv::var("USE_FASTBOOT").is_ok();
let dev_docker = dotenv::var("DEV_DOCKER").is_ok();
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ extern crate derive_deref;
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate serde_json;
Expand Down