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
5 changes: 2 additions & 3 deletions aria/contents/docs/development/database/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ title: Database
---

## Database maintenance
Currently, the tables of database are created by `.sql` file.
Currently, the tables of database are created by [SeaORM migration](https://www.sea-ql.org/SeaORM/docs/migration/setting-up-migration).

If you want to add a new table or modify the existing table, you need to update the `.sql` files which are located in the `sql` directory.
If you want to add a new table or modify the existing table, you need to update the `migration` files which are located in the `jupiter/migration/src` directory.

### Attention
- Each database corresponds to one `.sql` file, you must modify all of them if you want to update the tables in order to keep the consistency of the database.
- DO NOT use `Array` Type in PostgreSQL but use `JSON` instead, for compatibility with SQLite & MySQL. (`JSON` <==> `serde_json::Value`)

---
Expand Down
15 changes: 1 addition & 14 deletions aria/contents/docs/development/quick-start/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ description: Quick start manuel to developing or testing.
postgres=# \q
```

```bash
$ cd mega/sql/postgres
$ psql mega < pg_YYYYMMDD_init.sql
```

3. Create user and grant privileges.

```sql
Expand Down Expand Up @@ -136,14 +131,7 @@ description: Quick start manuel to developing or testing.
postgres=# \q
```

3.Import `mega/sql/postgres/pg_<time>_init.sql` to `mega`.

```bash
$ cd mega/sql/postgres
$ sudo -u postgres psql mega < pg_YYYYMMDD__init.sql
```

4.Create user and grant privileges.
3.Create user and grant privileges.

```sql
$ sudo -u postgres psql postgres
Expand Down Expand Up @@ -202,7 +190,6 @@ When the codespace is ready, the PostgreSQL will be installed and started automa
/etc/init.d/postgresql start

sudo -u postgres psql mega -c "CREATE DATABASE mega;"
sudo -u postgres psql mega < /workspaces/mega/sql/pg_YYYYMMDD__init.sql
sudo -u postgres psql mega -c "CREATE USER mega WITH ENCRYPTED PASSWORD 'mega';"
sudo -u postgres psql mega -c "GRANT ALL PRIVILEGES ON DATABASE mega TO mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
Expand Down
6 changes: 3 additions & 3 deletions common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<T> CommonResult<T> {
}
}

#[derive(Deserialize)]
#[derive(Deserialize, ToSchema)]
pub struct Pagination {
pub page: u64,
pub per_page: u64,
Expand All @@ -62,13 +62,13 @@ impl Default for Pagination {
}
}

#[derive(Deserialize)]
#[derive(Deserialize, ToSchema)]
pub struct PageParams<T> {
pub pagination: Pagination,
pub additional: T,
}

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize, ToSchema)]

pub struct CommonPage<T> {
pub total: u64,
Expand Down
19 changes: 1 addition & 18 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
postgres=# \q
```

```bash
$ cd mega/sql/postgres
$ psql mega < pg_YYYYMMDD_init.sql
```

3. Create user and grant privileges.

Expand Down Expand Up @@ -138,14 +134,7 @@
postgres=# \q
```

3.Import `mega/sql/postgres/pg_<time>_init.sql` to `mega`.

```bash
$ cd mega/sql/postgres
$ sudo -u postgres psql mega < pg_YYYYMMDD__init.sql
```

4.Create user and grant privileges.
3.Create user and grant privileges.

```sql
$ sudo -u postgres psql postgres
Expand Down Expand Up @@ -204,7 +193,6 @@ When the codespace is ready, the PostgreSQL will be installed and started automa
/etc/init.d/postgresql start

sudo -u postgres psql mega -c "CREATE DATABASE mega;"
sudo -u postgres psql mega < /workspaces/mega/sql/pg_YYYYMMDD__init.sql
sudo -u postgres psql mega -c "CREATE USER mega WITH ENCRYPTED PASSWORD 'mega';"
sudo -u postgres psql mega -c "GRANT ALL PRIVILEGES ON DATABASE mega TO mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
Expand Down Expand Up @@ -235,13 +223,8 @@ Currently, the mono bin and mega bin use two different files, each with a differ
- see codes in [config.rs](/common/src/config.rs)

---
## Database maintenance
Currently, the tables of database are created by `.sql` file.

If you want to add a new table or modify the existing table, you need to update the `.sql` files which are located in the `sql` directory.

### Attention
- Each database corresponds to one `.sql` file, you must modify all of them if you want to update the tables in order to keep the consistency of the database.
- DO NOT use `Array` Type in PostgreSQL but use `JSON` instead, for compatibility with SQLite & MySQL. (`JSON` <==> `serde_json::Value`)
---
## Tests
Expand Down
1 change: 1 addition & 0 deletions jupiter/callisto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
chrono = { workspace = true }
sea-orm = { workspace = true, features = ["sqlx-postgres", "sqlx-mysql", "sqlx-sqlite"] }
utoipa = { workspace = true, features = ["axum_extras"] }
9 changes: 7 additions & 2 deletions jupiter/callisto/src/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[derive(
Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "conv_type_enum")]
pub enum ConvTypeEnum {
#[sea_orm(string_value = "comment")]
Expand All @@ -29,7 +32,9 @@ pub enum ConvTypeEnum {
#[sea_orm(string_value = "reopen")]
Reopen,
}
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[derive(
Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "merge_status_enum")]
pub enum MergeStatusEnum {
#[sea_orm(string_value = "open")]
Expand Down
1 change: 0 additions & 1 deletion jupiter/sqlite_20241204_init.sql

This file was deleted.

29 changes: 1 addition & 28 deletions jupiter/src/storage/init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use common::errors::MegaError;
use migration::{Migrator, MigratorTrait};
use sea_orm::{
ConnectOptions, ConnectionTrait, Database, DatabaseConnection, DbErr, Statement,
TransactionError, TransactionTrait,
};
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use std::{path::Path, time::Duration};
use tracing::log;

Expand Down Expand Up @@ -55,33 +52,9 @@ async fn sqlite_connection(db_config: &DbConfig) -> Result<DatabaseConnection, M
let opt = setup_option(db_url);
let conn = Database::connect(opt).await?;

// setup sqlite database (execute .sql)
// if db_config.db_path.metadata()?.len() == 0 {
// log::info!("Setting up sqlite database");
// setup_sql(&conn)
// .await
// .map_err(|e| sea_orm::DbErr::Custom(e.to_string()))?;
// }
Ok(conn)
}

/// create table from .sql file
#[allow(unused)]
async fn setup_sql(conn: &DatabaseConnection) -> Result<(), TransactionError<DbErr>> {
conn.transaction::<_, _, DbErr>(|txn| {
Box::pin(async move {
let backend = txn.get_database_backend();

// `include_str!` will expand the file while compiling, so `.sql` is not needed after that
const SETUP_SQL: &str = include_str!("../../sqlite_20241204_init.sql");
txn.execute(Statement::from_string(backend, SETUP_SQL))
.await?;
Ok(())
})
})
.await
}

fn setup_option(db_url: impl Into<String>) -> ConnectOptions {
let mut opt = ConnectOptions::new(db_url);
opt.max_connections(5)
Expand Down
2 changes: 1 addition & 1 deletion jupiter/src/storage/mono_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl MonoStorage {
pub async fn get_refs(&self, path: &str) -> Result<Vec<mega_refs::Model>, MegaError> {
let result = mega_refs::Entity::find()
.filter(mega_refs::Column::Path.eq(path))
.filter(mega_refs::Column::IsMr.eq(false))
// .filter(mega_refs::Column::IsMr.eq(false))
.order_by_asc(mega_refs::Column::RefName)
.all(self.get_connection())
.await?;
Expand Down
2 changes: 1 addition & 1 deletion mono/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn life_cycle_check() -> Result<impl IntoResponse, ApiError> {

/// Create file in web UI
#[utoipa::path(
get,
post,
path = "/create-file",
request_body = CreateFileInfo,
responses(
Expand Down
Loading