Skip to content

Commit

Permalink
Branches: Disallow server version <5 for all branch commands (#1234)
Browse files Browse the repository at this point in the history
* add check for server version

* add deprecation of edgedb database commands

* eprintln instead of bail

* clippy
  • Loading branch information
quinchs authored Mar 6, 2024
1 parent 685d8a7 commit 7158c7d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/branch/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ pub async fn branch_main(options: &Options, cmd: &BranchCommand) -> anyhow::Resu

let mut connection: Connection = options.create_connector().await?.connect().await?;

let server_version = connection.get_version().await?;
if server_version.specific().major < 5 {
anyhow::bail!("Branches are not supported on server version {}, please upgrade to EdgeDB 5+", server_version)
}

// match commands that don't require a connection to run, then match the ones that do with a connection.
match &cmd.subcommand {
Command::Switch(switch) => switch::main(switch, &context, &mut connection).await,
Expand Down
12 changes: 12 additions & 0 deletions src/commands/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use crate::question;
pub async fn create(cli: &mut Connection, options: &CreateDatabase, _: &Options)
-> Result<(), anyhow::Error>
{
if cli.get_version().await?.specific().major >= 5 {
eprintln!("'edgedb database create' is deprecated in EdgeDB 5+. Please use 'edgedb branch create'");
}

let status = cli.execute(
&format!("CREATE DATABASE {}", quote_name(&options.database_name)),
&(),
Expand All @@ -23,6 +27,10 @@ pub async fn create(cli: &mut Connection, options: &CreateDatabase, _: &Options)
pub async fn drop(cli: &mut Connection, options: &DropDatabase, _: &Options)
-> Result<(), anyhow::Error>
{
if cli.get_version().await?.specific().major >= 5 {
eprintln!("'edgedb database drop' is deprecated in EdgeDB 5+. Please use 'edgedb branch drop'");
}

if !options.non_interactive {
let q = question::Confirm::new_dangerous(
format!("Do you really want to delete database {:?}?",
Expand All @@ -44,6 +52,10 @@ pub async fn drop(cli: &mut Connection, options: &DropDatabase, _: &Options)
pub async fn wipe(cli: &mut Connection, options: &WipeDatabase, _: &Options)
-> Result<(), anyhow::Error>
{
if cli.get_version().await?.specific().major >= 5 {
eprintln!("'edgedb database wipe' is deprecated in EdgeDB 5+. Please use 'edgedb branch wipe'");
}

if cli.get_version().await?.specific() < "3.0-alpha.2".parse().unwrap() {
return Err(
anyhow::anyhow!("The `database wipe` command is only \
Expand Down
4 changes: 2 additions & 2 deletions src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use fs_err as fs;

use edgedb_tokio::Config;
use edgedb_tokio::credentials::Credentials;
use serde::Deserialize;
use serde_json::Deserializer;



use crate::platform::{config_dir, tmp_file_name};
use crate::question;
Expand Down

0 comments on commit 7158c7d

Please sign in to comment.