Skip to content

Commit 184241d

Browse files
committed
Merge remote-tracking branch 'origin/main' into new-issue-1872
Signed-off-by: Chen-Rong-Zi <1398881912@qq.com>
2 parents 2d0fe03 + 71a8bd6 commit 184241d

14 files changed

Lines changed: 254 additions & 96 deletions

File tree

common/src/config/mod.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ pub struct Config {
9898
pub object_storage: ObjectStorageConfig,
9999
#[serde(default)]
100100
pub orion_server: Option<OrionServerConfig>,
101+
#[serde(default)]
102+
pub sidebar: SidebarConfig,
101103
}
102104

103105
impl Config {
@@ -136,6 +138,7 @@ impl Config {
136138
buck: None,
137139
object_storage: ObjectStorageConfig::default(),
138140
orion_server: None,
141+
sidebar: SidebarConfig::default(),
139142
}
140143
}
141144

@@ -647,8 +650,6 @@ pub struct BuildConfig {
647650
pub orion_server: String,
648651
#[serde(default)]
649652
pub orion_preheat_shallow_depth: usize,
650-
#[serde(default)]
651-
pub orion_buck2_isolation_dir_base: Option<String>,
652653
}
653654

654655
/// Orion Server configuration (flat structure)
@@ -875,6 +876,55 @@ impl Default for BuckConfig {
875876
}
876877
}
877878

879+
#[derive(Deserialize, Debug)]
880+
pub struct SidebarConfig {
881+
pub default_items: Vec<SidebarItem>,
882+
}
883+
884+
#[derive(Deserialize, Debug)]
885+
pub struct SidebarItem {
886+
pub public_id: String,
887+
pub label: String,
888+
pub href: String,
889+
#[serde(default = "default_visible")]
890+
pub visible: bool,
891+
pub order_index: i32,
892+
}
893+
894+
impl Default for SidebarConfig {
895+
fn default() -> Self {
896+
Self {
897+
default_items: vec![
898+
SidebarItem {
899+
public_id: "home".to_string(),
900+
label: "Home".to_string(),
901+
href: "/posts".to_string(),
902+
visible: true,
903+
order_index: 0,
904+
},
905+
SidebarItem {
906+
public_id: "inbox".to_string(),
907+
label: "Inbox".to_string(),
908+
href: "/inbox".to_string(),
909+
visible: true,
910+
order_index: 1,
911+
},
912+
SidebarItem {
913+
public_id: "docs".to_string(),
914+
label: "Docs".to_string(),
915+
href: "/notes".to_string(),
916+
visible: true,
917+
order_index: 2,
918+
},
919+
],
920+
}
921+
}
922+
}
923+
924+
fn default_visible() -> bool {
925+
true
926+
}
927+
878928
#[cfg(test)]
879929
mod test {
880930
use std::path::Path;

config/config-test.toml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ orion_server = "https://orion.gitmega.com"
8787

8888
# Orion worker: shallow preheat depth before buck2 cells/audit.
8989
# 0 means disabled.
90-
orion_preheat_shallow_depth = 0
91-
92-
# Orion worker: base directory for buck2 --isolation-dir.
93-
# Empty means use the system temp directory.
94-
orion_buck2_isolation_dir_base = ""
90+
orion_preheat_shallow_depth = 3
9591

9692

9793
[pack]
@@ -249,3 +245,24 @@ db_url = "postgres://postgres:postgres@localhost/orion"
249245

250246
# Mono server base URL for file/blob API
251247
monobase_url = "http://localhost:8000"
248+
249+
# Default sidebar menu items.
250+
# - Visible = false means the menu is hidden by default.
251+
# - Order_index controls the display order in the UI.
252+
# - Changes here do not affect old environments; only new or empty DBs will use these defaults.
253+
[sidebar]
254+
default_items = [
255+
{ public_id = "home", label = "Home", href = "/posts", visible = true, order_index = 0 },
256+
{ public_id = "inbox", label = "Inbox", href = "/inbox", visible = true, order_index = 1 },
257+
{ public_id = "chat", label = "Chat", href = "/chat", visible = true, order_index = 2 },
258+
{ public_id = "notes", label = "Docs", href = "/notes", visible = true, order_index = 3 },
259+
{ public_id = "calls", label = "Calls", href = "/calls", visible = false, order_index = 4 },
260+
{ public_id = "drafts", label = "Drafts", href = "/drafts", visible = true, order_index = 5 },
261+
{ public_id = "code", label = "Code", href = "/code", visible = true, order_index = 6 },
262+
{ public_id = "tags", label = "Tags", href = "/code/tags", visible = true, order_index = 7 },
263+
{ public_id = "cl", label = "Change List", href = "/cl", visible = true, order_index = 8 },
264+
{ public_id = "mq", label = "Merge Queue", href = "/queue/main", visible = true, order_index = 9 },
265+
{ public_id = "issue", label = "Issue", href = "/issue", visible = true, order_index = 10 },
266+
{ public_id = "rust", label = "Rust", href = "/rust", visible = false, order_index = 11 },
267+
{ public_id = "oc", label = "Orion Client", href = "/oc", visible = true, order_index = 13 },
268+
]

config/config-workflow.toml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ orion_server = "https://orion.gitmega.com"
8383

8484
# Orion worker: shallow preheat depth before buck2 cells/audit.
8585
# 0 means disabled.
86-
orion_preheat_shallow_depth = 0
87-
88-
# Orion worker: base directory for buck2 --isolation-dir.
89-
# Empty means use the system temp directory.
90-
orion_buck2_isolation_dir_base = ""
86+
orion_preheat_shallow_depth = 3
9187

9288

9389
[pack]
@@ -163,3 +159,24 @@ db_url = "postgres://postgres:postgres@localhost/orion"
163159

164160
# Mono server base URL for file/blob API
165161
monobase_url = "http://localhost:8000"
162+
163+
# Default sidebar menu items.
164+
# - Visible = false means the menu is hidden by default.
165+
# - Order_index controls the display order in the UI.
166+
# - Changes here do not affect old environments; only new or empty DBs will use these defaults.
167+
[sidebar]
168+
default_items = [
169+
{ public_id = "home", label = "Home", href = "/posts", visible = true, order_index = 0 },
170+
{ public_id = "inbox", label = "Inbox", href = "/inbox", visible = true, order_index = 1 },
171+
{ public_id = "chat", label = "Chat", href = "/chat", visible = true, order_index = 2 },
172+
{ public_id = "notes", label = "Docs", href = "/notes", visible = true, order_index = 3 },
173+
{ public_id = "calls", label = "Calls", href = "/calls", visible = false, order_index = 4 },
174+
{ public_id = "drafts", label = "Drafts", href = "/drafts", visible = true, order_index = 5 },
175+
{ public_id = "code", label = "Code", href = "/code", visible = true, order_index = 6 },
176+
{ public_id = "tags", label = "Tags", href = "/code/tags", visible = true, order_index = 7 },
177+
{ public_id = "cl", label = "Change List", href = "/cl", visible = true, order_index = 8 },
178+
{ public_id = "mq", label = "Merge Queue", href = "/queue/main", visible = true, order_index = 9 },
179+
{ public_id = "issue", label = "Issue", href = "/issue", visible = true, order_index = 10 },
180+
{ public_id = "rust", label = "Rust", href = "/rust", visible = false, order_index = 11 },
181+
{ public_id = "oc", label = "Orion Client", href = "/oc", visible = true, order_index = 13 },
182+
]

config/config.toml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ orion_server = "https://orion.gitmega.com"
8888

8989
# Orion worker: shallow preheat depth before buck2 cells/audit.
9090
# 0 means disabled.
91-
orion_preheat_shallow_depth = 0
92-
93-
# Orion worker: base directory for buck2 --isolation-dir.
94-
# Empty means use the system temp directory.
95-
orion_buck2_isolation_dir_base = ""
91+
orion_preheat_shallow_depth = 3
9692

9793

9894
[pack]
@@ -253,3 +249,24 @@ db_url = "postgres://postgres:postgres@localhost/orion"
253249

254250
# Mono server base URL for file/blob API (file blob endpoint)
255251
monobase_url = "http://git.gitmega.com"
252+
253+
# Default sidebar menu items.
254+
# - Visible = false means the menu is hidden by default.
255+
# - Order_index controls the display order in the UI.
256+
# - Changes here do not affect old environments; only new or empty DBs will use these defaults.
257+
[sidebar]
258+
default_items = [
259+
{ public_id = "home", label = "Home", href = "/posts", visible = true, order_index = 0 },
260+
{ public_id = "inbox", label = "Inbox", href = "/inbox", visible = true, order_index = 1 },
261+
{ public_id = "chat", label = "Chat", href = "/chat", visible = true, order_index = 2 },
262+
{ public_id = "notes", label = "Docs", href = "/notes", visible = true, order_index = 3 },
263+
{ public_id = "calls", label = "Calls", href = "/calls", visible = false, order_index = 4 },
264+
{ public_id = "drafts", label = "Drafts", href = "/drafts", visible = true, order_index = 5 },
265+
{ public_id = "code", label = "Code", href = "/code", visible = true, order_index = 6 },
266+
{ public_id = "tags", label = "Tags", href = "/code/tags", visible = true, order_index = 7 },
267+
{ public_id = "cl", label = "Change List", href = "/cl", visible = true, order_index = 8 },
268+
{ public_id = "mq", label = "Merge Queue", href = "/queue/main", visible = true, order_index = 9 },
269+
{ public_id = "issue", label = "Issue", href = "/issue", visible = true, order_index = 10 },
270+
{ public_id = "rust", label = "Rust", href = "/rust", visible = false, order_index = 11 },
271+
{ public_id = "oc", label = "Orion Client", href = "/oc", visible = true, order_index = 13 },
272+
]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! Migration to Clean Up Historical Default Data in `dynamic_sidebar` Table
2+
//!
3+
//! This migration exists solely to address a historical technical debt in
4+
//! `jupiter/src/migration/m20251203_013745_add_dynamic_sidebar.rs`.
5+
//! In that original migration, default menu items were hard-coded and inserted
6+
//! into the `dynamic_sidebar` table. This approach mixes schema definition
7+
//! with data initialization, which is no longer the desired practice.
8+
//!
9+
//! Key principles applied in this migration:
10+
//!
11+
//! 1. **Schema vs. Data Separation**
12+
//! - Migrations should only define or modify database **schema** (tables, columns, indexes).
13+
//! - They should **not** insert default or seed data.
14+
//! - Default menu data is now managed at **runtime** via a bootstrap method (`DynamicSidebarStorage::bootstrap_sidebar`) that reads from configuration (e.g., `sidebar.default.toml`).
15+
//!
16+
//! 2. **Purpose of This Migration**
17+
//! - Remove historical default data inserted by the old migration.
18+
//! - Keep the table structure and indexes intact, so the table is empty but ready for runtime seeding.
19+
//! - This ensures **new environments** or **fresh deployments** do not carry legacy hard-coded menu items.
20+
//!
21+
//! 3. **Future Default Menu Management**
22+
//! - Default menu items are now fully configurable and maintained via `sidebar.default.toml` or application config.
23+
//! - `DynamicSidebarStorage::bootstrap_sidebar` is responsible for checking if the table is empty and inserting defaults at runtime.
24+
//! - This approach provides flexibility, maintains backward compatibility, and separates schema migrations from dynamic, configurable data.
25+
26+
use sea_orm::DatabaseBackend;
27+
use sea_orm_migration::prelude::*;
28+
29+
#[derive(DeriveMigrationName)]
30+
pub struct Migration;
31+
32+
#[async_trait::async_trait]
33+
impl MigrationTrait for Migration {
34+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
35+
let backend = manager.get_database_backend();
36+
37+
match backend {
38+
DatabaseBackend::Postgres => {
39+
let sql = r#"DELETE FROM dynamic_sidebar;"#;
40+
manager.get_connection().execute_unprepared(sql).await?;
41+
}
42+
DatabaseBackend::Sqlite | DatabaseBackend::MySql => {}
43+
}
44+
45+
Ok(())
46+
}
47+
48+
async fn down(&self, _: &SchemaManager) -> Result<(), DbErr> {
49+
Ok(())
50+
}
51+
}

jupiter/src/migration/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ mod m20260127_081517_create_build_triggers;
8282
mod m20260128_080549_add_mega_code_review_anchor_and_position;
8383
mod m20260130_065535_refactor_orion_module;
8484
mod m20260208_012349_change_build_events;
85+
mod m20260209_064016_remove_default_dynamic_sidebar;
8586

8687
/// Creates a primary key column definition with big integer type.
8788
///
@@ -154,6 +155,7 @@ impl MigratorTrait for Migrator {
154155
Box::new(m20260128_080549_add_mega_code_review_anchor_and_position::Migration),
155156
Box::new(m20260130_065535_refactor_orion_module::Migration),
156157
Box::new(m20260208_012349_change_build_events::Migration),
158+
Box::new(m20260209_064016_remove_default_dynamic_sidebar::Migration),
157159
]
158160
}
159161
}

jupiter/src/storage/dynamic_sidebar_storage.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::{collections::HashSet, ops::Deref};
22

33
use callisto::dynamic_sidebar;
4-
use common::errors::MegaError;
4+
use common::{config::SidebarConfig, errors::MegaError};
55
use sea_orm::{
66
ActiveModelTrait,
77
ActiveValue::{NotSet, Set},
8-
EntityTrait, QueryOrder, TransactionTrait,
8+
EntityTrait, PaginatorTrait, QueryOrder, TransactionTrait,
99
};
1010

1111
use crate::{
@@ -26,6 +26,33 @@ impl Deref for DynamicSidebarStorage {
2626
}
2727

2828
impl DynamicSidebarStorage {
29+
/// Initialize default sidebars from config if the table is empty.
30+
/// This is idempotent: only inserts if no rows exist.
31+
pub async fn init_default_sidebars(&self, config: &SidebarConfig) -> Result<(), MegaError> {
32+
let count = dynamic_sidebar::Entity::find()
33+
.count(self.get_connection())
34+
.await?;
35+
if count > 0 {
36+
return Ok(());
37+
}
38+
39+
let default_items = &config.default_items;
40+
41+
for item in default_items {
42+
let active_model = dynamic_sidebar::ActiveModel {
43+
public_id: Set(item.public_id.clone()),
44+
label: Set(item.label.clone()),
45+
href: Set(item.href.clone()),
46+
visible: Set(item.visible),
47+
order_index: Set(item.order_index),
48+
..Default::default()
49+
};
50+
active_model.insert(self.get_connection()).await?;
51+
}
52+
53+
Ok(())
54+
}
55+
2956
pub async fn get_sidebar_by_id(
3057
&self,
3158
id: i32,

jupiter/src/storage/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,12 @@ impl Storage {
151151
let reviewer_storage = ClReviewerStorage { base: base.clone() };
152152
let merge_queue_storage = MergeQueueStorage::new(base.clone());
153153
let buck_storage = BuckStorage { base: base.clone() };
154+
154155
let dynamic_sidebar_storage = DynamicSidebarStorage { base: base.clone() };
156+
dynamic_sidebar_storage
157+
.init_default_sidebars(&config.sidebar)
158+
.await?;
159+
155160
let code_review_comment_storage = CodeReviewCommentStorage { base: base.clone() };
156161
let code_review_thread_storage = CodeReviewThreadStorage { base: base.clone() };
157162
let build_trigger_storage = BuildTriggerStorage { base: base.clone() };

orion/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,4 @@ ORION_WORKER_START_SCORPIO=true
6868
# ---------------------------------------------------------------------------
6969
# Buck2 Configuration
7070
# ---------------------------------------------------------------------------
71-
BUCK2_ISOLATION_DIR=/tmp/buck2-isolation
7271

orion/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@ ENV PATH="/app/bin:/usr/local/bin:${PATH}" \
171171
RUST_LOG=info \
172172
# Scorpio defaults
173173
SCORPIO_STORE_PATH=/data/scorpio/store \
174-
SCORPIO_WORKSPACE=/workspace/mount \
175-
# Buck2 defaults
176-
BUCK2_ISOLATION_DIR=/tmp/buck2-isolation
174+
SCORPIO_WORKSPACE=/workspace/mount
177175

178176
WORKDIR /workspace
179177

0 commit comments

Comments
 (0)