-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add new database table #251
Merged
Filip-L
merged 2 commits into
main
from
FIL-578-new-table-to-the-database-and-integrate-it
Feb 4, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::get_database_connection; | ||
use crate::models::comparable_applications::{ | ||
ActiveModel, ApplicationComparableData, Entity as ComparableApplication, | ||
Model as ComparableApplicationModel, | ||
}; | ||
use sea_orm::{entity::*, DbErr}; | ||
|
||
pub async fn create_comparable_application( | ||
client_address: &str, | ||
comparable_data: &ApplicationComparableData, | ||
) -> Result<(), sea_orm::DbErr> { | ||
let conn = get_database_connection().await?; | ||
let new_comparable_data = ActiveModel { | ||
client_address: Set(client_address.to_string()), | ||
application: Set(comparable_data.clone()), | ||
}; | ||
new_comparable_data.insert(&conn).await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn get_comparable_applications() -> Result<Vec<ComparableApplicationModel>, DbErr> { | ||
let conn = get_database_connection().await?; | ||
let response = ComparableApplication::find().all(&conn).await?; | ||
Ok(response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use sea_orm::{entity::prelude::*, FromJsonQueryResult}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "comparable_applications")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub client_address: String, | ||
#[sea_orm(column_type = "JsonBinary")] | ||
pub application: ApplicationComparableData, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation {} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)] | ||
pub struct ApplicationComparableData { | ||
pub project_desc: String, | ||
pub stored_data_desc: String, | ||
pub data_owner_name: String, | ||
pub data_set_sample: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE public.comparable_applications | ||
( | ||
client_address text NOT NULL, | ||
application jsonb NOT NULL, | ||
PRIMARY KEY (client_address) | ||
); | ||
|
||
ALTER TABLE IF EXISTS public.comparable_applications | ||
OWNER to postgres; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break in prod, as in prod we use other user (
dbmaster
if I remember correctly).No need to set ownership explicitly, plain create table will be enough and it will be owned by whoever is logged in.