From 84e7267778a070b1cba153fcb3f0cb1c0b4dc769 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 11:45:20 -0500 Subject: [PATCH 1/6] Fix version comparison for "admin" --- src/portable/create.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/portable/create.rs b/src/portable/create.rs index c7dd2ecf9..368d6b75f 100644 --- a/src/portable/create.rs +++ b/src/portable/create.rs @@ -442,10 +442,14 @@ pub fn bootstrap( fs::create_dir_all(&tmp_data).with_context(|| format!("creating {:?}", &tmp_data))?; let password = generate_password(); + let version = info.get_version()?; let script = bootstrap_script( user, &password, - if info.get_version()? >= &Build::from_str("6.0-dev.9024+4b89273").unwrap() { + if &Build::from_str("6.0-alpha.2+8fb3f01").unwrap() <= version + && version < &Build::from_str("6.0-dev.8321+d6c575a").unwrap() // lowest nightly + || version >= &Build::from_str("6.0-dev.9024+4b89273").unwrap() // first "admin" + { "admin" } else { "edgedb" From f1cdc52610e60e8d44f14e7c2630a97c2b7f4b31 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 11:52:18 -0500 Subject: [PATCH 2/6] Don't worry about old nightlies --- src/portable/create.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/portable/create.rs b/src/portable/create.rs index 368d6b75f..f607e4185 100644 --- a/src/portable/create.rs +++ b/src/portable/create.rs @@ -442,14 +442,10 @@ pub fn bootstrap( fs::create_dir_all(&tmp_data).with_context(|| format!("creating {:?}", &tmp_data))?; let password = generate_password(); - let version = info.get_version()?; let script = bootstrap_script( user, &password, - if &Build::from_str("6.0-alpha.2+8fb3f01").unwrap() <= version - && version < &Build::from_str("6.0-dev.8321+d6c575a").unwrap() // lowest nightly - || version >= &Build::from_str("6.0-dev.9024+4b89273").unwrap() // first "admin" - { + if info.get_version()? >= &Build::from_str("6.0-alpha.2+8fb3f01").unwrap() { "admin" } else { "edgedb" From b55b6134d0e32a01064d73301fed438759986ba4 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 12:02:50 -0500 Subject: [PATCH 3/6] Fix default_user --- src/portable/create.rs | 6 ++++-- src/portable/options.rs | 7 ++++--- src/portable/project.rs | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/portable/create.rs b/src/portable/create.rs index f607e4185..ed93785ae 100644 --- a/src/portable/create.rs +++ b/src/portable/create.rs @@ -28,7 +28,7 @@ use crate::print::{self, err_marker, msg, Highlight}; use crate::process; use crate::question; -use crate::portable::project::get_default_branch_name; +use crate::portable::project::{get_default_branch_name, get_default_user_name}; use edgedb_tokio::credentials::Credentials; fn ask_name(cloud_client: &mut cloud::client::CloudClient) -> anyhow::Result { @@ -171,7 +171,9 @@ pub fn create(cmd: &Create, opts: &crate::options::Options) -> anyhow::Result<() bootstrap( &paths, &info, - &cmd.default_user, + cmd.default_user + .as_deref() + .unwrap_or_else(|| get_default_user_name(specific_version)), &cmd.default_branch .clone() .unwrap_or_else(|| get_default_branch_name(specific_version)), diff --git a/src/portable/options.rs b/src/portable/options.rs index c62ef4308..3b250518f 100644 --- a/src/portable/options.rs +++ b/src/portable/options.rs @@ -335,9 +335,10 @@ pub struct Create { pub start_conf: Option, /// Default user name (created during initialization and saved in - /// credentials file). - #[arg(long, default_value = "admin")] - pub default_user: String, + /// credentials file). This defaults to 'admin' on EdgeDB >=6.x; otherwise + /// 'edgedb' is used. + #[arg(long)] + pub default_user: Option, /// The default branch name. This defaults to 'main' on EdgeDB >=5.x; otherwise /// 'edgedb' is used. diff --git a/src/portable/project.rs b/src/portable/project.rs index e999f3b3b..786068295 100644 --- a/src/portable/project.rs +++ b/src/portable/project.rs @@ -410,6 +410,14 @@ pub fn get_default_branch_name(version: &Specific) -> String { String::from("edgedb") } +pub fn get_default_user_name(version: &Specific) -> &'static str { + if version.major >= 6 { + "admin" + } else { + "edgedb" + } +} + pub fn get_default_branch_or_database(version: &Specific, project_dir: &Path) -> String { if version.major >= 5 { return String::from("main"); @@ -818,7 +826,7 @@ fn do_init( }, port: Some(port), start_conf: None, - default_user: "edgedb".into(), + default_user: None, non_interactive: true, cloud_opts: options.cloud_opts.clone(), default_branch: Some(database.to_string()), @@ -835,12 +843,18 @@ fn do_init( InstanceKind::Wsl(WslInfo {}) } else { let inst = install::package(pkg).context(concatcp!("error installing ", BRANDING))?; + let version = inst.version.specific(); let info = InstanceInfo { name: name.into(), installation: Some(inst), port, }; - create::bootstrap(&paths, &info, "admin", database)?; + create::bootstrap( + &paths, + &info, + get_default_user_name(&version), + database, + )?; match create::create_service(&info) { Ok(()) => {} Err(e) => { From 04fc39aa1db150065da965f6ddf683d0bd4cee58 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 12:20:27 -0500 Subject: [PATCH 4/6] rustfmt --- src/portable/project.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/portable/project.rs b/src/portable/project.rs index 786068295..dfe9a1d6f 100644 --- a/src/portable/project.rs +++ b/src/portable/project.rs @@ -849,12 +849,7 @@ fn do_init( installation: Some(inst), port, }; - create::bootstrap( - &paths, - &info, - get_default_user_name(&version), - database, - )?; + create::bootstrap(&paths, &info, get_default_user_name(&version), database)?; match create::create_service(&info) { Ok(()) => {} Err(e) => { From 67a50a695f81951ed0ab663c2360988435a4d168 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 12:51:11 -0500 Subject: [PATCH 5/6] CRF: use Specific --- src/portable/create.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/portable/create.rs b/src/portable/create.rs index ed93785ae..25098edc2 100644 --- a/src/portable/create.rs +++ b/src/portable/create.rs @@ -22,7 +22,7 @@ use crate::portable::options::{Create, InstanceName, Start}; use crate::portable::platform::optional_docker_check; use crate::portable::repository::{Query, QueryOptions}; use crate::portable::reset_password::{generate_password, password_hash}; -use crate::portable::ver::Build; +use crate::portable::ver::Specific; use crate::portable::{linux, macos, windows}; use crate::print::{self, err_marker, msg, Highlight}; use crate::process; @@ -447,7 +447,7 @@ pub fn bootstrap( let script = bootstrap_script( user, &password, - if info.get_version()? >= &Build::from_str("6.0-alpha.2+8fb3f01").unwrap() { + if info.get_version()?.specific() >= Specific::from_str("6.0-alpha.2").unwrap() { "admin" } else { "edgedb" From b58b2a2d85bbb1d82adf58ad280677001734c05c Mon Sep 17 00:00:00 2001 From: Fantix King Date: Thu, 5 Dec 2024 19:36:26 -0500 Subject: [PATCH 6/6] CRF: extract variable --- src/branding.rs | 4 ++++ src/portable/create.rs | 10 +++++++--- src/portable/project.rs | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/branding.rs b/src/branding.rs index ac216bc9e..c767a06cf 100644 --- a/src/branding.rs +++ b/src/branding.rs @@ -58,3 +58,7 @@ pub const CONFIG_FILE_DISPLAY_NAME: &str = if cfg!(feature = "gel") { /// The default query tag for server statistics. pub const QUERY_TAG: &str = "gel/cli"; pub const REPL_QUERY_TAG: &str = "gel/repl"; + +/// The default name of the database user bootstrapped in a new instance. +pub const BRANDING_DEFAULT_USERNAME: &str = "admin"; +pub const BRANDING_DEFAULT_USERNAME_LEGACY: &str = "edgedb"; diff --git a/src/portable/create.rs b/src/portable/create.rs index 25098edc2..657f2b89b 100644 --- a/src/portable/create.rs +++ b/src/portable/create.rs @@ -7,7 +7,10 @@ use fn_error_context::context; use color_print::cformat; -use crate::branding::{BRANDING, BRANDING_CLI_CMD, BRANDING_CLOUD}; +use crate::branding::{ + BRANDING, BRANDING_CLI_CMD, BRANDING_CLOUD, BRANDING_DEFAULT_USERNAME, + BRANDING_DEFAULT_USERNAME_LEGACY, +}; use crate::cloud; use crate::commands::ExitCode; use crate::credentials; @@ -447,10 +450,11 @@ pub fn bootstrap( let script = bootstrap_script( user, &password, + // This is the user included in the server. It changed since 6.0-alpha.2. if info.get_version()?.specific() >= Specific::from_str("6.0-alpha.2").unwrap() { - "admin" + BRANDING_DEFAULT_USERNAME } else { - "edgedb" + BRANDING_DEFAULT_USERNAME_LEGACY }, ); diff --git a/src/portable/project.rs b/src/portable/project.rs index dfe9a1d6f..609dc521f 100644 --- a/src/portable/project.rs +++ b/src/portable/project.rs @@ -23,6 +23,7 @@ use crate::branding::QUERY_TAG; use crate::branding::{ BRANDING, BRANDING_CLI_CMD, BRANDING_SCHEMA_FILE_EXT, CONFIG_FILE_DISPLAY_NAME, }; +use crate::branding::{BRANDING_DEFAULT_USERNAME, BRANDING_DEFAULT_USERNAME_LEGACY}; use crate::cloud; use crate::cloud::client::CloudClient; use crate::commands::ExitCode; @@ -412,9 +413,9 @@ pub fn get_default_branch_name(version: &Specific) -> String { pub fn get_default_user_name(version: &Specific) -> &'static str { if version.major >= 6 { - "admin" + BRANDING_DEFAULT_USERNAME } else { - "edgedb" + BRANDING_DEFAULT_USERNAME_LEGACY } }