Skip to content

Commit 8bbb778

Browse files
authored
feat: add orion refactor modules (#1904)
* feat: add orion refactor modules Signed-off-by: Wangyan <topshihun@foxmail.com> * style: cargo fmt Signed-off-by: Wangyan <topshihun@foxmail.com> * fix: remove local files Signed-off-by: Wangyan <topshihun@foxmail.com> * fix: migration module entity Signed-off-by: Wangyan <topshihun@foxmail.com> * style: cargo fmt Signed-off-by: Wangyan <topshihun@foxmail.com> * feat: add down for refactor orion module Signed-off-by: Wangyan <topshihun@foxmail.com> * style: rename orion modules Signed-off-by: Wangyan <topshihun@foxmail.com> * style: cargo fmt Signed-off-by: Wangyan <topshihun@foxmail.com> * fix: recovery some files Signed-off-by: Wangyan <topshihun@foxmail.com> --------- Signed-off-by: Wangyan <topshihun@foxmail.com>
1 parent 3660f64 commit 8bbb778

7 files changed

Lines changed: 310 additions & 8 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "build_events")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
pub index: i32,
12+
pub task_id: Uuid,
13+
pub exit_code: Option<i32>,
14+
pub log_output_file: String,
15+
pub start_at: Option<DateTimeWithTimeZone>,
16+
pub end_at: Option<DateTimeWithTimeZone>,
17+
}
18+
19+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20+
pub enum Relation {
21+
#[sea_orm(
22+
belongs_to = "super::orion_tasks::Entity",
23+
from = "Column::TaskId",
24+
to = "super::orion_tasks::Column::Id",
25+
on_update = "Cascade",
26+
on_delete = "Cascade"
27+
)]
28+
OrionTasks,
29+
}
30+
31+
impl Related<super::orion_tasks::Entity> for Entity {
32+
fn to() -> RelationDef {
33+
Relation::OrionTasks.def()
34+
}
35+
}
36+
37+
impl ActiveModelBehavior for ActiveModel {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "build_targets")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
pub task_id: Uuid,
12+
#[sea_orm(column_type = "JsonBinary")]
13+
pub path: Json,
14+
#[sea_orm(column_type = "Text")]
15+
pub target_state: String,
16+
}
17+
18+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
19+
pub enum Relation {
20+
#[sea_orm(
21+
belongs_to = "super::orion_tasks::Entity",
22+
from = "Column::TaskId",
23+
to = "super::orion_tasks::Column::Id",
24+
on_update = "Cascade",
25+
on_delete = "Cascade"
26+
)]
27+
OrionTasks,
28+
}
29+
30+
impl Related<super::orion_tasks::Entity> for Entity {
31+
fn to() -> RelationDef {
32+
Relation::OrionTasks.def()
33+
}
34+
}
35+
36+
impl ActiveModelBehavior for ActiveModel {}

jupiter/callisto/src/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pub mod prelude;
55
pub mod access_token;
66
pub mod buck_session;
77
pub mod buck_session_file;
8+
pub mod build_events;
9+
pub mod build_targets;
810
pub mod build_triggers;
911
pub mod builds;
1012
pub mod check_result;
@@ -42,6 +44,7 @@ pub mod mega_tag;
4244
pub mod mega_tree;
4345
pub mod merge_queue;
4446
pub mod notes;
47+
pub mod orion_tasks;
4548
pub mod path_check_configs;
4649
pub mod reactions;
4750
pub mod sea_orm_active_enums;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
2+
3+
use sea_orm::entity::prelude::*;
4+
use serde::{Deserialize, Serialize};
5+
6+
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
7+
#[sea_orm(table_name = "orion_tasks")]
8+
pub struct Model {
9+
#[sea_orm(primary_key, auto_increment = false)]
10+
pub id: Uuid,
11+
#[sea_orm(column_type = "JsonBinary")]
12+
pub changes: Json,
13+
pub repo_name: String,
14+
pub cl: String,
15+
pub created_at: DateTimeWithTimeZone,
16+
}
17+
18+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
19+
pub enum Relation {
20+
#[sea_orm(has_many = "super::build_events::Entity")]
21+
BuildEvents,
22+
#[sea_orm(has_many = "super::build_targets::Entity")]
23+
BuildTargets,
24+
}
25+
26+
impl Related<super::build_events::Entity> for Entity {
27+
fn to() -> RelationDef {
28+
Relation::BuildEvents.def()
29+
}
30+
}
31+
32+
impl Related<super::build_targets::Entity> for Entity {
33+
fn to() -> RelationDef {
34+
Relation::BuildTargets.def()
35+
}
36+
}
37+
38+
impl ActiveModelBehavior for ActiveModel {}

jupiter/callisto/src/prelude.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
pub use super::{
44
access_token::Entity as AccessToken, buck_session::Entity as BuckSession,
5-
buck_session_file::Entity as BuckSessionFile, builds::Entity as Builds,
6-
check_result::Entity as CheckResult, commit_auths::Entity as CommitAuths,
7-
dynamic_sidebar::Entity as DynamicSidebar, git_blob::Entity as GitBlob,
8-
git_commit::Entity as GitCommit, git_issue::Entity as GitIssue, git_pr::Entity as GitPr,
9-
git_repo::Entity as GitRepo, git_tag::Entity as GitTag, git_tree::Entity as GitTree,
10-
gpg_key::Entity as GpgKey, import_refs::Entity as ImportRefs,
5+
buck_session_file::Entity as BuckSessionFile, build_events::Entity as BuildEvents,
6+
build_targets::Entity as BuildTargets, build_triggers::Entity as BuildTriggers,
7+
builds::Entity as Builds, check_result::Entity as CheckResult,
8+
commit_auths::Entity as CommitAuths, dynamic_sidebar::Entity as DynamicSidebar,
9+
git_blob::Entity as GitBlob, git_commit::Entity as GitCommit, git_issue::Entity as GitIssue,
10+
git_pr::Entity as GitPr, git_repo::Entity as GitRepo, git_tag::Entity as GitTag,
11+
git_tree::Entity as GitTree, gpg_key::Entity as GpgKey, import_refs::Entity as ImportRefs,
1112
issue_cl_references::Entity as IssueClReferences, item_assignees::Entity as ItemAssignees,
1213
item_labels::Entity as ItemLabels, label::Entity as Label, lfs_locks::Entity as LfsLocks,
1314
lfs_objects::Entity as LfsObjects, mega_blob::Entity as MegaBlob, mega_cl::Entity as MegaCl,
@@ -18,7 +19,7 @@ pub use super::{
1819
mega_code_review_thread::Entity as MegaCodeReviewThread, mega_commit::Entity as MegaCommit,
1920
mega_conversation::Entity as MegaConversation, mega_issue::Entity as MegaIssue,
2021
mega_refs::Entity as MegaRefs, mega_tag::Entity as MegaTag, mega_tree::Entity as MegaTree,
21-
merge_queue::Entity as MergeQueue, notes::Entity as Notes,
22+
merge_queue::Entity as MergeQueue, notes::Entity as Notes, orion_tasks::Entity as OrionTasks,
2223
path_check_configs::Entity as PathCheckConfigs, reactions::Entity as Reactions,
23-
ssh_keys::Entity as SshKeys, tasks::Entity as Tasks, vault::Entity as Vault,
24+
ssh_keys::Entity as SshKeys, vault::Entity as Vault,
2425
};
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
// Create OrionTasks
10+
manager
11+
.create_table(
12+
Table::create()
13+
.table(OrionTasks::Table)
14+
.if_not_exists()
15+
.col(
16+
ColumnDef::new(OrionTasks::Id)
17+
.uuid()
18+
.not_null()
19+
.primary_key(),
20+
)
21+
.col(ColumnDef::new(OrionTasks::Changes).json_binary().not_null())
22+
.col(ColumnDef::new(OrionTasks::RepoName).string().not_null())
23+
.col(ColumnDef::new(OrionTasks::CL).string().not_null())
24+
.col(
25+
ColumnDef::new(OrionTasks::CreatedAt)
26+
.timestamp_with_time_zone()
27+
.default(Expr::current_timestamp())
28+
.not_null(),
29+
)
30+
.to_owned(),
31+
)
32+
.await?;
33+
34+
// Create BuildEvents
35+
manager
36+
.create_table(
37+
Table::create()
38+
.table(BuildEvents::Table)
39+
.if_not_exists()
40+
.col(
41+
ColumnDef::new(BuildEvents::Id)
42+
.uuid()
43+
.not_null()
44+
.primary_key(),
45+
)
46+
.col(ColumnDef::new(BuildEvents::Index).integer().not_null())
47+
.col(ColumnDef::new(BuildEvents::TaskId).uuid().not_null())
48+
.col(ColumnDef::new(BuildEvents::ExitCode).integer().null())
49+
.col(
50+
ColumnDef::new(BuildEvents::LogOutputFile)
51+
.string()
52+
.not_null(),
53+
)
54+
.col(
55+
ColumnDef::new(BuildEvents::StartAt)
56+
.timestamp_with_time_zone()
57+
.default(Expr::current_timestamp()),
58+
)
59+
.col(
60+
ColumnDef::new(BuildEvents::EndAt)
61+
.timestamp_with_time_zone()
62+
.null(),
63+
)
64+
.foreign_key(
65+
ForeignKey::create()
66+
.from(BuildEvents::Table, BuildEvents::TaskId)
67+
.to(OrionTasks::Table, OrionTasks::Id)
68+
.on_delete(ForeignKeyAction::Cascade)
69+
.on_update(ForeignKeyAction::Cascade),
70+
)
71+
.to_owned(),
72+
)
73+
.await?;
74+
75+
// Create BuildTargets
76+
manager
77+
.create_table(
78+
Table::create()
79+
.table(BuildTargets::Table)
80+
.if_not_exists()
81+
.col(
82+
ColumnDef::new(BuildTargets::Id)
83+
.uuid()
84+
.not_null()
85+
.primary_key(),
86+
)
87+
.col(ColumnDef::new(BuildTargets::TaskId).uuid().not_null())
88+
.col(ColumnDef::new(BuildTargets::Path).json_binary().not_null())
89+
.col(ColumnDef::new(BuildTargets::TargetState).text().not_null())
90+
.foreign_key(
91+
ForeignKey::create()
92+
.from(BuildTargets::Table, BuildTargets::TaskId)
93+
.to(OrionTasks::Table, OrionTasks::Id)
94+
.on_delete(ForeignKeyAction::Cascade)
95+
.on_update(ForeignKeyAction::Cascade),
96+
)
97+
.to_owned(),
98+
)
99+
.await?;
100+
101+
// Create indexes on foreign key columns for better join performance
102+
manager
103+
.create_index(
104+
Index::create()
105+
.name("idx_build_events_task_id")
106+
.table(BuildEvents::Table)
107+
.col(BuildEvents::TaskId)
108+
.to_owned(),
109+
)
110+
.await?;
111+
manager
112+
.create_index(
113+
Index::create()
114+
.name("idx_build_targets_task_id")
115+
.table(BuildTargets::Table)
116+
.col(BuildTargets::TaskId)
117+
.to_owned(),
118+
)
119+
.await?;
120+
121+
Ok(())
122+
}
123+
124+
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
125+
// Drop indexes created in `up`
126+
manager
127+
.drop_index(
128+
Index::drop()
129+
.name("idx_build_targets_task_id")
130+
.table(BuildTargets::Table)
131+
.to_owned(),
132+
)
133+
.await?;
134+
manager
135+
.drop_index(
136+
Index::drop()
137+
.name("idx_build_events_task_id")
138+
.table(BuildEvents::Table)
139+
.to_owned(),
140+
)
141+
.await?;
142+
// Drop tables created in `up` (children before parent)
143+
manager
144+
.drop_table(Table::drop().table(BuildTargets::Table).to_owned())
145+
.await?;
146+
manager
147+
.drop_table(Table::drop().table(BuildEvents::Table).to_owned())
148+
.await?;
149+
manager
150+
.drop_table(Table::drop().table(OrionTasks::Table).to_owned())
151+
.await?;
152+
Ok(())
153+
}
154+
}
155+
156+
#[derive(DeriveIden)]
157+
enum OrionTasks {
158+
Table,
159+
Id,
160+
Changes,
161+
RepoName,
162+
CL,
163+
CreatedAt,
164+
}
165+
166+
#[derive(DeriveIden)]
167+
enum BuildEvents {
168+
Table,
169+
Index,
170+
Id,
171+
TaskId,
172+
ExitCode,
173+
LogOutputFile,
174+
StartAt,
175+
EndAt,
176+
}
177+
178+
#[derive(DeriveIden)]
179+
enum BuildTargets {
180+
Table,
181+
Id,
182+
TaskId,
183+
Path,
184+
TargetState,
185+
}

jupiter/src/migration/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ mod m20260115_000000_create_targets_table;
8080
mod m20260119_060233_add_mega_code_review;
8181
mod m20260127_081517_create_build_triggers;
8282
mod m20260128_080549_add_mega_code_review_anchor_and_position;
83+
mod m20260130_065535_refactor_orion_module;
8384

8485
/// Creates a primary key column definition with big integer type.
8586
///
@@ -150,6 +151,7 @@ impl MigratorTrait for Migrator {
150151
Box::new(m20260119_060233_add_mega_code_review::Migration),
151152
Box::new(m20260127_081517_create_build_triggers::Migration),
152153
Box::new(m20260128_080549_add_mega_code_review_anchor_and_position::Migration),
154+
Box::new(m20260130_065535_refactor_orion_module::Migration),
153155
]
154156
}
155157
}

0 commit comments

Comments
 (0)