Skip to content
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions crates/defguard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use bytes::Bytes;
use defguard_common::{
VERSION,
CARGO_VERSION, VERSION,
config::{Command, DefGuardConfig, SERVER_CONFIG},
db::{
init_db,
Expand Down Expand Up @@ -139,7 +139,7 @@ async fn main() -> Result<(), anyhow::Error> {
}

let has_auto_adopt_flags = config.adopt_edge.is_some() && config.adopt_gateway.is_some();
let wizard = Wizard::init(&pool, has_auto_adopt_flags, &config).await?;
let mut wizard = Wizard::init(&pool, has_auto_adopt_flags, &config).await?;

Settings::initialize_runtime_defaults(&pool).await?;
SERVER_CONFIG.set(config.clone()).ok();
Expand Down Expand Up @@ -178,6 +178,10 @@ async fn main() -> Result<(), anyhow::Error> {
}
}

wizard
.update_last_version_migrated_to(&pool, CARGO_VERSION)
.await?;

// Reload settings from database after setup completion to ensure any changes made during setup
// are reflected in the in-memory settings.
let settings = Settings::get(&pool).await?.ok_or_else(|| {
Expand Down
21 changes: 18 additions & 3 deletions crates/defguard_common/src/db/models/wizard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl fmt::Display for ActiveWizard {
pub struct Wizard {
pub active_wizard: ActiveWizard,
pub completed: bool,
pub last_version_migrated_to: Option<String>,
}

impl Wizard {
Expand All @@ -53,10 +54,11 @@ impl Wizard {
E: PgExecutor<'e>,
{
query!(
"UPDATE wizard SET active_wizard = $1, completed = $2 \
"UPDATE wizard SET active_wizard = $1, completed = $2, last_version_migrated_to = $3 \
WHERE is_singleton",
self.active_wizard as ActiveWizard,
self.completed
self.completed,
self.last_version_migrated_to
)
.execute(executor)
.await?;
Expand All @@ -70,7 +72,7 @@ impl Wizard {
{
let row = query_as!(
Wizard,
"SELECT active_wizard \"active_wizard!: ActiveWizard\", completed \
"SELECT active_wizard \"active_wizard!: ActiveWizard\", completed, last_version_migrated_to \
FROM wizard WHERE is_singleton LIMIT 1",
)
.fetch_one(executor)
Expand All @@ -79,6 +81,7 @@ impl Wizard {
Ok(Self {
active_wizard: row.active_wizard,
completed: row.completed,
last_version_migrated_to: row.last_version_migrated_to,
})
}

Expand Down Expand Up @@ -210,4 +213,16 @@ impl Wizard {
_ => Ok(true),
}
}

pub async fn update_last_version_migrated_to<'e, E>(
&mut self,
executor: E,
version: &str,
) -> Result<(), sqlx::Error>
where
E: PgExecutor<'e>,
{
self.last_version_migrated_to = Some(version.to_string());
self.save(executor).await
}
}
2 changes: 1 addition & 1 deletion crates/defguard_core/src/enterprise/ldap/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl super::LDAPConnection {
let mut sync_group_members = HashSet::new();
for sync_group in &sync_groups {
let members = sync_group.members(pool).await?;
sync_group_members.extend(members.into_iter());
sync_group_members.extend(members);
}

let mut all_ldap_users = self.get_all_users().await?;
Expand Down
1 change: 1 addition & 0 deletions crates/defguard_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ pub async fn init_dev_env(config: &DefGuardConfig) {
let wizard = Wizard {
active_wizard: ActiveWizard::None,
completed: true,
last_version_migrated_to: None,
};
// Ensure wizard is initialized, then overwrite with completed state
let _ = Wizard::init(&pool, false, config).await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};

use defguard_proto::{
client_types::InstanceInfoRequest,
proxy::{CoreRequest, core_request, core_response},
};
use sqlx::postgres::{PgConnectOptions, PgPoolOptions};

use super::support::{
assert_error_response, clear_test_license, complete_proxy_handshake, create_device_for_user,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE wizard DROP COLUMN last_version_migrated_to;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE wizard ADD COLUMN last_version_migrated_to TEXT;
Loading