Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: separate tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jul 16, 2024
1 parent e085330 commit 4fab07d
Show file tree
Hide file tree
Showing 37 changed files with 575 additions and 1,095 deletions.
2 changes: 1 addition & 1 deletion rivet-cli/src/commands/backend/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use clap::Parser;
use toolchain::rivet_api::{apis, models};
use futures_util::{StreamExt, TryStreamExt};
use global_error::prelude::*;
use serde::Deserialize;
use tokio::fs;
use toolchain::rivet_api::{apis, models};

use crate::{
commands::backend::{get_or_create_project, run_opengb_command, OpenGbCommandOpts},
Expand Down
1 change: 0 additions & 1 deletion rivet-cli/src/commands/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::util::{global_config, paths, term};

pub(crate) mod database;
pub mod deploy;
pub mod environment;

#[derive(Parser)]
pub enum SubCommand {
Expand Down
74 changes: 8 additions & 66 deletions rivet-toolchain/src/backend/database.rs
Original file line number Diff line number Diff line change
@@ -1,74 +1,16 @@
use std::path::PathBuf;

use clap::Parser;
use toolchain::rivet_api::apis;
use global_error::prelude::*;
use rivet_api::apis;
use uuid::Uuid;

use crate::util::global_config;

// Used for parsing env flag from passthrough command. Not an actual Rivet CLI command
#[derive(Parser)]
pub enum PassthroughSubCommand {
#[clap(alias = "db")]
Database {
#[clap(subcommand)]
command: DbSubCommand,

/// The location of the OpenGB project.
#[clap(global = true, long)]
path: Option<PathBuf>,
},
}

impl PassthroughSubCommand {
pub fn get_cmd(&self) -> &Opts {
match self {
PassthroughSubCommand::Database { command, .. } => command.get_cmd(),
}
}
}

#[derive(Parser)]
pub enum DbSubCommand {
Dev(Opts),
Status(Opts),
Reset(Opts),
Deploy(Opts),
Sh(Opts),
Url(Opts),
}

impl DbSubCommand {
fn get_cmd(&self) -> &Opts {
match self {
DbSubCommand::Dev(opts) => &opts,
DbSubCommand::Status(opts) => &opts,
DbSubCommand::Reset(opts) => &opts,
DbSubCommand::Deploy(opts) => &opts,
DbSubCommand::Sh(opts) => &opts,
DbSubCommand::Url(opts) => &opts,
}
}
}

#[derive(Parser)]
pub struct Opts {
/// The environment to deploy to.
#[clap(long = "env")]
pub env_name_id: String,

/// The modules to migrate.
#[clap(index = 1, action = clap::ArgAction::Append)]
pub modules: Vec<String>,
}
use crate::{config, ctx::Ctx, util::task::TaskCtx};

pub async fn provision_database(
ctx: &toolchain::Ctx,
task: TaskCtx,
ctx: &Ctx,
project_id: Uuid,
env_id: Uuid,
) -> GlobalResult<()> {
rivet_term::status::info("Provisioning databases", "");
task.log_stdout("[Provisioning Database]");

apis::ee_cloud_backend_projects_envs_api::ee_cloud_backend_projects_envs_provision_database(
&ctx.openapi_config_cloud,
Expand All @@ -78,7 +20,7 @@ pub async fn provision_database(
.await?;

// Fetch remote DB URL
let mut global_project_config = global_config::mutate_project(|config| {
let mut global_project_config = config::global::mutate_project(|config| {
config
.opengb
.projects
Expand All @@ -93,7 +35,7 @@ pub async fn provision_database(
.or_default();

if env_config.url.is_none() {
rivet_term::status::info("Fetching connection", "");
task.log_stdout("[Fetching Connection]");

let db_url_res =
apis::ee_cloud_backend_projects_envs_api::ee_cloud_backend_projects_envs_get_db_url(
Expand All @@ -107,7 +49,7 @@ pub async fn provision_database(
env_config.url = db_url_res.url;

// Update cache
global_config::try_mutate_project(|config| {
config::global::try_mutate_project(|config| {
// Was inserted in last `mutate_project` call
let project = unwrap!(config.opengb.projects.get_mut(&project_id));

Expand Down
214 changes: 0 additions & 214 deletions rivet-toolchain/src/backend/deploy.rs

This file was deleted.

Loading

0 comments on commit 4fab07d

Please sign in to comment.