Skip to content
Clone

refactor: drop local git mirror models

Branches, tags, commits, commit statuses, languages, and LFS objects are
already authoritative in KenShell, so the local mirror tables only risked
drifting out of sync.

Keep git_lfs_lock: KenShell has no LFS locking RPC, so that table still
belongs here. Its BelongsTo to the removed git_lfs model is dropped.
ZhenYi committed
parent 7735071 commit 3153ac6 Browse files

8 files changed

+5 −212

File tree 8
Deleted lib/share/models/src/git/git_branches.rs
@@ -1,26 +0,0 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "git_branch")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "repo_name")]
12 pub repo_id: Uuid,
13 #[sea_orm(unique_key = "repo_name")]
14 pub name: String,
15 pub commit_sha: String,
16 pub is_deleted: bool,
17 // 由 repo_branch_protection_policy 是否有匹配策略派生,写策略时必须同步该缓存标志
18 pub is_protected: bool,
19 pub deleted_at: Option<OffsetDateTime>,
20 pub created_at: OffsetDateTime,
21 pub updated_at: OffsetDateTime,
22 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
23 pub repo: BelongsTo<super::super::repo::repos::Entity>,
24}
25
26impl ActiveModelBehavior for ActiveModel {}
Deleted lib/share/models/src/git/git_commit_status.rs
@@ -1,56 +0,0 @@
1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use uuid::Uuid;
5
6#[derive(
7 Debug,
8 Clone,
9 Copy,
10 PartialEq,
11 Eq,
12 Default,
13 EnumIter,
14 DeriveActiveEnum,
15 Serialize,
16 Deserialize,
17 utoipa::ToSchema,
18)]
19#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
20pub enum CommitStatusState {
21 #[default]
22 #[sea_orm(num_value = 0)]
23 Pending,
24 #[sea_orm(num_value = 1)]
25 Success,
26 #[sea_orm(num_value = 2)]
27 Failure,
28 #[sea_orm(num_value = 3)]
29 Error,
30}
31
32#[sea_orm::model]
33#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
34#[sea_orm(table_name = "git_commit_status")]
35pub struct Model {
36 #[sea_orm(primary_key, auto_increment = false)]
37 pub id: Uuid,
38 #[sea_orm(unique_key = "commit")]
39 pub repo_id: Uuid,
40 #[sea_orm(unique_key = "commit")]
41 pub sha: String,
42 pub state: CommitStatusState,
43 #[sea_orm(unique_key = "commit")]
44 pub context: String,
45 pub description: Option<String>,
46 pub target_url: Option<String>,
47 pub creator_id: i64,
48 pub created_at: OffsetDateTime,
49 pub updated_at: Option<OffsetDateTime>,
50 #[sea_orm(belongs_to, from = "(repo_id, sha)", to = "(repo_id, sha)")]
51 pub commit: BelongsTo<super::git_commits::Entity>,
52 #[sea_orm(belongs_to, from = "creator_id", to = "uid")]
53 pub creator: BelongsTo<super::super::users::user::Entity>,
54}
55
56impl ActiveModelBehavior for ActiveModel {}
Deleted lib/share/models/src/git/git_commits.rs
@@ -1,28 +0,0 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "git_commit")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub repo_id: Uuid,
11 #[sea_orm(primary_key, auto_increment = false)]
12 pub sha: String,
13 pub message: String,
14 pub author_id: Option<i64>,
15 pub author_name: String,
16 pub author_email: String,
17 pub authored_at: OffsetDateTime,
18 pub committer_name: String,
19 pub committer_email: String,
20 pub committed_at: OffsetDateTime,
21 pub created_at: OffsetDateTime,
22 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
23 pub repo: BelongsTo<super::super::repo::repos::Entity>,
24 #[sea_orm(belongs_to, from = "author_id", to = "uid")]
25 pub author: BelongsTo<Option<super::super::users::user::Entity>>,
26}
27
28impl ActiveModelBehavior for ActiveModel {}
Deleted lib/share/models/src/git/git_languages.rs
@@ -1,23 +0,0 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
7#[sea_orm(table_name = "git_language")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "repo_language")]
12 pub repo_id: Uuid,
13 #[sea_orm(unique_key = "repo_language")]
14 pub language: String,
15 // 百分比以基点(basis points,0-10000)存储,避免浮点精度问题
16 pub percentage_bp: i32,
17 pub size: i64,
18 pub created_at: OffsetDateTime,
19 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
20 pub repo: BelongsTo<super::super::repo::repos::Entity>,
21}
22
23impl ActiveModelBehavior for ActiveModel {}
Deleted lib/share/models/src/git/git_lfs.rs
@@ -1,23 +0,0 @@
1use sea_orm::entity::prelude::*;
2use time::OffsetDateTime;
3use uuid::Uuid;
4
5#[sea_orm::model]
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "git_lfs")]
8pub struct Model {
9 #[sea_orm(primary_key, auto_increment = false)]
10 pub id: Uuid,
11 #[sea_orm(unique_key = "repo_oid")]
12 pub repo_id: Uuid,
13 // 唯一约束按(仓库, oid)建立:同一对象可被多个仓库引用
14 #[sea_orm(unique_key = "repo_oid")]
15 pub oid: String,
16 pub size: i64,
17 pub content_type: Option<String>,
18 pub created_at: OffsetDateTime,
19 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
20 pub repo: BelongsTo<super::super::repo::repos::Entity>,
21}
22
23impl ActiveModelBehavior for ActiveModel {}
Modified lib/share/models/src/git/git_lfs_lock.rs View lib/share/models/src/git/git_lfs_lock.rs
@@ -17,8 +17,6 @@
1717 pub created_at: OffsetDateTime,
1818 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
1919 pub repo: BelongsTo<super::super::repo::repos::Entity>,
20 #[sea_orm(belongs_to, from = "(repo_id, oid)", to = "(repo_id, oid)")]
21 pub lfs: BelongsTo<Option<super::git_lfs::Entity>>,
2220 #[sea_orm(belongs_to, from = "owner_id", to = "uid")]
2321 pub owner: BelongsTo<super::super::users::user::Entity>,
2422}
Deleted lib/share/models/src/git/git_tags.rs
@@ -1,48 +0,0 @@
1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use uuid::Uuid;
5
6#[derive(
7 Debug,
8 Clone,
9 Copy,
10 PartialEq,
11 Eq,
12 Default,
13 EnumIter,
14 DeriveActiveEnum,
15 Serialize,
16 Deserialize,
17 utoipa::ToSchema,
18)]
19#[sea_orm(rs_type = "i16", db_type = "SmallInteger")]
20pub enum TagType {
21 #[default]
22 #[sea_orm(num_value = 0)]
23 Lightweight,
24 #[sea_orm(num_value = 1)]
25 Annotated,
26}
27
28#[sea_orm::model]
29#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
30#[sea_orm(table_name = "git_tag")]
31pub struct Model {
32 #[sea_orm(primary_key, auto_increment = false)]
33 pub id: Uuid,
34 #[sea_orm(unique_key = "repo_name")]
35 pub repo_id: Uuid,
36 #[sea_orm(unique_key = "repo_name")]
37 pub name: String,
38 pub tag_type: TagType,
39 pub commit_sha: String,
40 pub message: Option<String>,
41 pub tagger_name: Option<String>,
42 pub tagger_email: Option<String>,
43 pub created_at: OffsetDateTime,
44 #[sea_orm(belongs_to, from = "repo_id", to = "id")]
45 pub repo: BelongsTo<super::super::repo::repos::Entity>,
46}
47
48impl ActiveModelBehavior for ActiveModel {}
Modified lib/share/models/src/git/mod.rs View lib/share/models/src/git/mod.rs
@@ -1,7 +1,6 @@
1pub mod git_branches;
2pub mod git_commit_status;
3pub mod git_commits;
4pub mod git_languages;
5pub mod git_lfs;
1//! Git 相关的平台侧模型。
2//!
3//! 除 LFS 锁之外,分支、标签、提交、语言、提交状态等数据都由 KenShell 持有,
4//! 这里不再保留镜像表。LFS 锁没有对应的 KenShell RPC,仍由本服务持久化。
5
66pub mod git_lfs_lock;
7pub mod git_tags;