Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Change name to owner and db inernally #1392 #1412

Merged
merged 6 commits into from
Dec 28, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/agdb_server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
- uses: taiki-e/install-action@cargo-llvm-cov
- run: rustup component add llvm-tools-preview
- run: cargo llvm-cov --package agdb_server --all-features --ignore-filename-regex "agdb(.|..)src|agdb_derive|agdb_api|api.rs" --fail-uncovered-functions 18 --show-missing-lines
- run: cargo llvm-cov --package agdb_server --all-features --ignore-filename-regex "agdb(.|..)src|agdb_derive|agdb_api|api.rs" --fail-uncovered-functions 21 --show-missing-lines

agdb_server_test:
runs-on: ubuntu-latest
Expand Down
11 changes: 3 additions & 8 deletions agdb_server/src/action/db_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_db::Database;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbType;
use serde::Deserialize;
Expand All @@ -19,19 +18,15 @@ pub(crate) struct DbAdd {

impl Action for DbAdd {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);

let backup = db_pool
.add_db(&self.owner, &self.db, &name, self.db_type)
.await?;

let backup = db_pool.add_db(&self.owner, &self.db, self.db_type).await?;
let owner = db.user_id(&self.owner).await?;

db.insert_db(
owner,
Database {
db_id: None,
name,
db: self.db,
owner: self.owner,
db_type: self.db_type,
backup,
},
Expand Down
8 changes: 3 additions & 5 deletions agdb_server/src/action/db_backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -16,11 +15,10 @@ pub(crate) struct DbBackup {

impl Action for DbBackup {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let owner = db.user_id(&self.owner).await?;
let name = db_name(&self.owner, &self.db);
let mut database = db.user_db(owner, &name).await?;
let user = db.user_id(&self.owner).await?;
let mut database = db.user_db(user, &self.owner, &self.db).await?;
database.backup = db_pool
.backup_db(&self.owner, &self.db, &name, database.db_type)
.backup_db(&self.owner, &self.db, database.db_type)
.await?;
db.save_db(&database).await?;
Ok(ClusterActionResult::None)
Expand Down
6 changes: 2 additions & 4 deletions agdb_server/src/action/db_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbResource;
use serde::Deserialize;
Expand All @@ -18,9 +17,8 @@ pub(crate) struct DbClear {

impl Action for DbClear {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let owner = db.user_id(&self.owner).await?;
let name = db_name(&self.owner, &self.db);
let mut database = db.user_db(owner, &name).await?;
let user = db.user_id(&self.owner).await?;
let mut database = db.user_db(user, &self.owner, &self.db).await?;
db_pool
.clear_db(&self.owner, &self.db, &mut database, self.resource)
.await?;
Expand Down
8 changes: 3 additions & 5 deletions agdb_server/src/action/db_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbType;
use serde::Deserialize;
Expand All @@ -18,11 +17,10 @@ pub(crate) struct DbConvert {

impl Action for DbConvert {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let owner = db.user_id(&self.owner).await?;
let name = db_name(&self.owner, &self.db);
let mut database = db.user_db(owner, &name).await?;
let user = db.user_id(&self.owner).await?;
let mut database = db.user_db(user, &self.owner, &self.db).await?;
db_pool
.convert_db(&self.owner, &self.db, &name, database.db_type, self.db_type)
.convert_db(&self.owner, &self.db, database.db_type, self.db_type)
.await?;
database.db_type = self.db_type;
db.save_db(&database).await?;
Expand Down
8 changes: 3 additions & 5 deletions agdb_server/src/action/db_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_db::Database;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbType;
use serde::Deserialize;
Expand All @@ -21,17 +20,16 @@ pub(crate) struct DbCopy {

impl Action for DbCopy {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
let target_name = db_name(&self.new_owner, &self.new_db);
let new_owner_id = db.user_id(&self.new_owner).await?;
db_pool
.copy_db(&name, &self.new_owner, &self.new_db, &target_name)
.copy_db(&self.owner, &self.db, &self.new_owner, &self.new_db)
.await?;
db.insert_db(
new_owner_id,
Database {
db_id: None,
name: target_name,
db: self.new_db,
owner: self.new_owner,
db_type: self.db_type,
backup: 0,
},
Expand Down
6 changes: 2 additions & 4 deletions agdb_server/src/action/db_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -16,10 +15,9 @@ pub(crate) struct DbDelete {

impl Action for DbDelete {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
let user_id = db.user_id(&self.owner).await?;
db.remove_db(user_id, &name).await?;
db_pool.delete_db(&self.owner, &self.db, &name).await?;
db.remove_db(user_id, &self.owner, &self.db).await?;
db_pool.delete_db(&self.owner, &self.db).await?;
Ok(ClusterActionResult::None)
}
}
4 changes: 1 addition & 3 deletions agdb_server/src/action/db_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::DbUserValue;
use agdb::QueryResult;
use agdb_api::Queries;
Expand All @@ -20,10 +19,9 @@ pub(crate) struct DbExec {

impl Action for DbExec {
async fn exec(self, _db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
Ok(ClusterActionResult::QueryResults(
db_pool
.exec_mut(&self.owner, &self.db, &name, &self.user, self.queries)
.exec_mut(&self.owner, &self.db, &self.user, self.queries)
.await?,
))
}
Expand Down
4 changes: 1 addition & 3 deletions agdb_server/src/action/db_optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -16,8 +15,7 @@ pub(crate) struct DbOptimize {

impl Action for DbOptimize {
async fn exec(self, _db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
db_pool.optimize_db(&name).await?;
db_pool.optimize_db(&self.owner, &self.db).await?;

Ok(ClusterActionResult::None)
}
Expand Down
6 changes: 2 additions & 4 deletions agdb_server/src/action/db_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -16,10 +15,9 @@ pub(crate) struct DbRemove {

impl Action for DbRemove {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
let user_id = db.user_id(&self.owner).await?;
db.remove_db(user_id, &name).await?;
db_pool.remove_db(&name).await?;
db.remove_db(user_id, &self.owner, &self.db).await?;
db_pool.remove_db(&self.owner, &self.db).await?;
Ok(ClusterActionResult::None)
}
}
17 changes: 4 additions & 13 deletions agdb_server/src/action/db_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbUserRole;
use serde::Deserialize;
Expand All @@ -20,20 +19,12 @@ pub(crate) struct DbRename {
impl Action for DbRename {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let owner_id = db.user_id(&self.owner).await?;
let name = db_name(&self.owner, &self.db);
let new_name = db_name(&self.new_owner, &self.new_db);
let mut database = db.user_db(owner_id, &name).await?;
let mut database = db.user_db(owner_id, &self.owner, &self.db).await?;
db_pool
.rename_db(
&self.owner,
&self.db,
&name,
&self.new_owner,
&self.new_db,
&new_name,
)
.rename_db(&self.owner, &self.db, &self.new_owner, &self.new_db)
.await?;
database.name = new_name;
database.owner = self.new_owner.clone();
database.db = self.new_db.to_string();
db.save_db(&database).await?;

if self.owner != self.new_owner {
Expand Down
8 changes: 3 additions & 5 deletions agdb_server/src/action/db_restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -16,12 +15,11 @@ pub(crate) struct DbRestore {

impl Action for DbRestore {
async fn exec(self, db: ServerDb, db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let owner = db.user_id(&self.owner).await?;
let name = db_name(&self.owner, &self.db);
let mut database = db.user_db(owner, &name).await?;
let user = db.user_id(&self.owner).await?;
let mut database = db.user_db(user, &self.owner, &self.db).await?;

if let Some(backup) = db_pool
.restore_db(&self.owner, &self.db, &name, database.db_type)
.restore_db(&self.owner, &self.db, database.db_type)
.await?
{
database.backup = backup;
Expand Down
4 changes: 1 addition & 3 deletions agdb_server/src/action/db_user_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use agdb_api::DbUserRole;
use serde::Deserialize;
Expand All @@ -19,9 +18,8 @@ pub(crate) struct DbUserAdd {

impl Action for DbUserAdd {
async fn exec(self, db: ServerDb, _db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
let owner_id = db.user_id(&self.owner).await?;
let db_id = db.user_db_id(owner_id, &name).await?;
let db_id = db.user_db_id(owner_id, &self.owner, &self.db).await?;
let user_id = db.user_id(&self.user).await?;
db.insert_db_user(db_id, user_id, self.db_role).await?;

Expand Down
4 changes: 1 addition & 3 deletions agdb_server/src/action/db_user_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use super::ServerDb;
use crate::action::Action;
use crate::action::ClusterActionResult;
use crate::server_error::ServerResult;
use crate::utilities::db_name;
use agdb::UserValue;
use serde::Deserialize;
use serde::Serialize;
Expand All @@ -17,9 +16,8 @@ pub(crate) struct DbUserRemove {

impl Action for DbUserRemove {
async fn exec(self, db: ServerDb, _db_pool: DbPool) -> ServerResult<ClusterActionResult> {
let name = db_name(&self.owner, &self.db);
let owner_id = db.user_id(&self.owner).await?;
let db_id = db.user_db_id(owner_id, &name).await?;
let db_id = db.user_db_id(owner_id, &self.owner, &self.db).await?;
let user_id = db.user_id(&self.user).await?;
db.remove_db_user(db_id, user_id).await?;

Expand Down
Loading
Loading