Skip to content

Commit

Permalink
test: ✅ able to connected to backend!
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Dec 7, 2023
1 parent b1a61e0 commit 810426c
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 137 deletions.
4 changes: 2 additions & 2 deletions backend/entity/src/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub struct Model {
pub id: i32,
pub title: String,
pub content: String,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub create_at: chrono::NaiveDateTime,
#[sea_orm(column_type = "Timestamp", on_update = "current_timestamp")]
#[sea_orm(column_type = "Time", on_update = "current_timestamp")]
pub update_at: chrono::NaiveDateTime,
}

Expand Down
14 changes: 6 additions & 8 deletions backend/entity/src/contest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub hoster: i32,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub begin: chrono::NaiveDateTime,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub end: chrono::NaiveDateTime,
pub title: String,
pub content: String,
pub tags: String,
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))", nullable)]
pub password: Option<Vec<u8>>,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub create_at: chrono::NaiveDateTime,
#[sea_orm(column_type = "Timestamp", on_update = "current_timestamp")]
#[sea_orm(column_type = "Time", on_update = "current_timestamp")]
pub update_at: chrono::NaiveDateTime,
pub public: bool,
}
Expand All @@ -28,10 +28,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(has_many = "super::user_contest::Entity")]
UserContest,
#[sea_orm(
has_one = "super::problem::Entity"
)]
Problem
#[sea_orm(has_one = "super::problem::Entity")]
Problem,
}

impl Related<super::user_contest::Entity> for Entity {
Expand Down
10 changes: 5 additions & 5 deletions backend/entity/src/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub struct Model {
pub submit_count: u32,
#[sea_orm(column_type = "Float")]
pub ac_rate: f32,
pub memory: u64,
pub time: u64,
pub memory: i64,
pub time: i64,
pub difficulty: u32,
pub public: bool,
pub tags: String,
pub title: String,
pub content: String,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub create_at: chrono::NaiveDateTime,
#[sea_orm(column_type = "Timestamp", on_update = "current_timestamp")]
#[sea_orm(column_type = "Time", on_update = "current_timestamp")]
pub update_at: chrono::NaiveDateTime,
pub match_rule: i32,
}
Expand All @@ -48,7 +48,7 @@ pub enum Relation {
from = "Column::ContestId",
to = "super::contest::Column::Id"
)]
Contest
Contest,
}

impl Related<super::education::Entity> for Entity {
Expand Down
8 changes: 4 additions & 4 deletions backend/entity/src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ pub struct Model {
pub id: i32,
pub user_id: Option<i32>,
pub problem_id: i32,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub upload_at: chrono::NaiveDateTime,
pub time: Option<u64>,
pub accuracy: Option<u64>,
pub time: Option<i64>,
pub accuracy: Option<i64>,
pub committed: bool,
pub lang: String,
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
pub code: Vec<u8>,
pub memory: Option<u64>,
pub memory: Option<i64>,
pub pass_case: i32,
pub status: Option<u32>,
pub accept: bool,
Expand Down
4 changes: 2 additions & 2 deletions backend/entity/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Model {
pub user_id: i32,
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
pub rand: Vec<u8>,
pub permission: u64,
#[sea_orm(column_type = "Timestamp")]
pub permission: u32,
#[sea_orm(column_type = "Time")]
pub expiry: chrono::NaiveDateTime,
}

Expand Down
4 changes: 2 additions & 2 deletions backend/entity/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use sea_orm::entity::prelude::*;
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub permission: u64,
pub permission: u32,
pub score: u32,
pub username: String,
#[sea_orm(column_type = "Binary(BlobSize::Blob(None))")]
pub password: Vec<u8>,
#[sea_orm(column_type = "Timestamp")]
#[sea_orm(column_type = "Time")]
pub create_at: chrono::NaiveDateTime,
}

Expand Down
7 changes: 2 additions & 5 deletions backend/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ prepare:
sea-orm-cli migrate -u sqlite://database/backend.sqlite?mode=rwc

entity-codegen:
rm database/backend.sqlite
sea-orm-cli migrate -u sqlite://database/backend.sqlite?mode=rwc
sea-orm-cli generate entity -u sqlite://database/backend.sqlite?mode=rwc -o entity/src
rm entity/src/mod.rs
rm entity/src/prelude.rs
Expand All @@ -20,10 +22,5 @@ release-docker:
cp ../cert/*.pem .
docker build . --build-arg ARCH=$(uname -m) -t mdoj-backend

refresh:
rm database/backend.sqlite
sea-orm-cli migrate -u sqlite://database/backend.sqlite?mode=rwc
just entity-codegen

run:
cargo run
159 changes: 122 additions & 37 deletions backend/migration/src/m20231207_000001_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,21 @@ impl MigrationTrait for Migration {
.primary_key(),
)
.col(ColumnDef::new(Announcement::Title).string().not_null())
.col(ColumnDef::new(Announcement::Content).string().not_null().default(""))
.col(
ColumnDef::new(Announcement::CreateAt).date_time()
ColumnDef::new(Announcement::Content)
.string()
.not_null()
.default(""),
)
.col(
ColumnDef::new(Announcement::CreateAt)
.date_time()
.not_null()
.extra(CREATE_AT.to_string()),
)
.col(
ColumnDef::new(Announcement::UpdateAt).date_time()
ColumnDef::new(Announcement::UpdateAt)
.date_time()
.not_null()
.extra(UPDATE_AT.to_string()),
)
Expand All @@ -163,31 +170,35 @@ impl MigrationTrait for Migration {
.primary_key(),
)
.col(ColumnDef::new(Contest::Hoster).integer().not_null())
.col(ColumnDef::new(Contest::Begin).date_time().not_null())
.col(ColumnDef::new(Contest::End).date_time().not_null())
.col(ColumnDef::new(Contest::Title).text().not_null())
.col(
ColumnDef::new(Contest::Begin)
.date_time()
.not_null(),
)
.col(
ColumnDef::new(Contest::End)
.date_time()
.not_null(),
ColumnDef::new(Contest::Content)
.text()
.not_null()
.default(""),
)
.col(ColumnDef::new(Contest::Title).text().not_null())
.col(ColumnDef::new(Contest::Content).text().not_null().default(""))
.col(ColumnDef::new(Contest::Tags).text().not_null().default(""))
.col(ColumnDef::new(Contest::Password).binary().null())
.col(
ColumnDef::new(Contest::CreateAt).date_time()
ColumnDef::new(Contest::CreateAt)
.date_time()
.not_null()
.extra(CREATE_AT.to_string()),
)
.col(
ColumnDef::new(Contest::UpdateAt).date_time()
ColumnDef::new(Contest::UpdateAt)
.date_time()
.not_null()
.extra(UPDATE_AT.to_string()),
)
.col(ColumnDef::new(Contest::Public).boolean().not_null().default(false))
.col(
ColumnDef::new(Contest::Public)
.boolean()
.not_null()
.default(false),
)
.to_owned(),
)
.await?;
Expand Down Expand Up @@ -217,9 +228,19 @@ impl MigrationTrait for Migration {
.from(Education::Table, Education::UserId)
.to(User::Table, User::Id),
)
.col(ColumnDef::new(Education::Tags).text().not_null().default(""))
.col(
ColumnDef::new(Education::Tags)
.text()
.not_null()
.default(""),
)
.col(ColumnDef::new(Education::Title).text().not_null())
.col(ColumnDef::new(Education::Content).text().not_null().default(""))
.col(
ColumnDef::new(Education::Content)
.text()
.not_null()
.default(""),
)
.to_owned(),
)
.await?;
Expand All @@ -243,23 +264,55 @@ impl MigrationTrait for Migration {
.to(User::Table, User::Id),
)
.col(ColumnDef::new(Problem::ContestId).integer().null())
.col(ColumnDef::new(Problem::AcceptCount).integer().not_null().default(0))
.col(ColumnDef::new(Problem::SubmitCount).integer().not_null().default(0))
.col(ColumnDef::new(Problem::AcRate).float().not_null().default(0.0))
.col(
ColumnDef::new(Problem::AcceptCount)
.integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Problem::SubmitCount)
.integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Problem::AcRate)
.float()
.not_null()
.default(0.0),
)
.col(ColumnDef::new(Problem::Memory).big_unsigned().not_null())
.col(ColumnDef::new(Problem::Time).big_unsigned().not_null())
.col(ColumnDef::new(Problem::Difficulty).unsigned().not_null().default(512))
.col(ColumnDef::new(Problem::Public).boolean().not_null().default(false))
.col(
ColumnDef::new(Problem::Difficulty)
.unsigned()
.not_null()
.default(512),
)
.col(
ColumnDef::new(Problem::Public)
.boolean()
.not_null()
.default(false),
)
.col(ColumnDef::new(Problem::Tags).text().not_null().default(""))
.col(ColumnDef::new(Problem::Title).text().not_null())
.col(ColumnDef::new(Problem::Content).text().not_null().default(""))
.col(
ColumnDef::new(Problem::CreateAt).date_time()
ColumnDef::new(Problem::Content)
.text()
.not_null()
.default(""),
)
.col(
ColumnDef::new(Problem::CreateAt)
.date_time()
.not_null()
.extra(CREATE_AT.to_string()),
)
.col(
ColumnDef::new(Problem::UpdateAt).date_time()
ColumnDef::new(Problem::UpdateAt)
.date_time()
.not_null()
.extra(UPDATE_AT.to_string()),
)
Expand Down Expand Up @@ -300,14 +353,34 @@ impl MigrationTrait for Migration {
)
.col(ColumnDef::new(Submit::Time).big_unsigned().null())
.col(ColumnDef::new(Submit::Accuracy).big_unsigned().null())
.col(ColumnDef::new(Submit::Committed).boolean().not_null().default(false))
.col(
ColumnDef::new(Submit::Committed)
.boolean()
.not_null()
.default(false),
)
.col(ColumnDef::new(Submit::Lang).text().not_null())
.col(ColumnDef::new(Submit::Code).not_null().binary())
.col(ColumnDef::new(Submit::Memory).big_unsigned().null())
.col(ColumnDef::new(Submit::PassCase).integer().not_null().default(0))
.col(
ColumnDef::new(Submit::PassCase)
.integer()
.not_null()
.default(0),
)
.col(ColumnDef::new(Submit::Status).unsigned().null())
.col(ColumnDef::new(Submit::Accept).boolean().not_null().default(false))
.col(ColumnDef::new(Submit::Score).unsigned().not_null().default(0))
.col(
ColumnDef::new(Submit::Accept)
.boolean()
.not_null()
.default(false),
)
.col(
ColumnDef::new(Submit::Score)
.unsigned()
.not_null()
.default(0),
)
.to_owned(),
)
.await?;
Expand Down Expand Up @@ -363,12 +436,13 @@ impl MigrationTrait for Migration {
.to(User::Table, User::Id),
)
.col(ColumnDef::new(Token::Rand).binary().not_null())
.col(ColumnDef::new(Token::Permission).big_unsigned().not_null().default(0))
.col(
ColumnDef::new(Token::Expiry)
.date_time()
.not_null(),
ColumnDef::new(Token::Permission)
.big_unsigned()
.not_null()
.default(0),
)
.col(ColumnDef::new(Token::Expiry).date_time().not_null())
.to_owned(),
)
.await?;
Expand All @@ -384,12 +458,18 @@ impl MigrationTrait for Migration {
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(User::Permission).big_unsigned().not_null().default(0))
.col(
ColumnDef::new(User::Permission)
.big_unsigned()
.not_null()
.default(0),
)
.col(ColumnDef::new(User::Score).unsigned().not_null().default(0))
.col(ColumnDef::new(User::Username).text().not_null())
.col(ColumnDef::new(User::Password).binary().not_null())
.col(
ColumnDef::new(User::CreateAt).date_time()
ColumnDef::new(User::CreateAt)
.date_time()
.not_null()
.extra(CREATE_AT.to_string()),
)
Expand Down Expand Up @@ -422,7 +502,12 @@ impl MigrationTrait for Migration {
.from(UserContest::Table, UserContest::UserId)
.to(User::Table, User::Id),
)
.col(ColumnDef::new(UserContest::Score).integer().not_null().default(0))
.col(
ColumnDef::new(UserContest::Score)
.integer()
.not_null()
.default(0),
)
.to_owned(),
)
.await?;
Expand Down
Loading

0 comments on commit 810426c

Please sign in to comment.