Skip to content

Commit

Permalink
pmrmodel: db access for remaining exposure types
Browse files Browse the repository at this point in the history
- Just the core implementation for the existing methods.
- Change the exposure schema to reference the view instead of just
  setting a potentially dangling text reference.
- Also updated the foreign key definitions for the exposure for the
  default reference, along with a rename of the field to make it
  consistent.
  • Loading branch information
metatoaster committed Jul 12, 2023
1 parent 50b156d commit b819af4
Show file tree
Hide file tree
Showing 17 changed files with 669 additions and 39 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

10 changes: 6 additions & 4 deletions pmrmodel/migrations/pmrapp/20230329081133_exposure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ CREATE TABLE IF NOT EXISTS exposure (
workspace_tag_id INTEGER,
commit_id TEXT NOT NULL, -- this is actually duplicate with tag
created_ts INTEGER NOT NULL,
root_exposure_file_id INTEGER, -- TODO figure out how to do this link to the exposure_file table.
default_file_id INTEGER,
FOREIGN KEY(workspace_id) REFERENCES workspace(id),
FOREIGN KEY(workspace_tag_id) REFERENCES workspace_tag(id)
FOREIGN KEY(workspace_tag_id) REFERENCES workspace_tag(id),
FOREIGN KEY(default_file_id) REFERENCES exposure_file(id)
);

CREATE INDEX IF NOT EXISTS exposure__workspace_id ON exposure(workspace_id);
Expand All @@ -17,8 +18,9 @@ CREATE TABLE IF NOT EXISTS exposure_file (
id INTEGER PRIMARY KEY NOT NULL,
exposure_id INTEGER NOT NULL,
workspace_file_path TEXT NOT NULL,
default_view TEXT,
FOREIGN KEY(exposure_id) REFERENCES exposure(id)
default_view_id INTEGER,
FOREIGN KEY(exposure_id) REFERENCES exposure(id),
FOREIGN KEY(default_view_id) REFERENCES exposure_file_view(id)
);

CREATE INDEX IF NOT EXISTS exposure_file__exposure_id ON exposure_file(exposure_id);
Expand Down
2 changes: 2 additions & 0 deletions pmrmodel/src/model/db/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod exposure;
mod exposure_file;
mod exposure_file_view;

mod workspace;
mod workspace_alias;
Expand Down
24 changes: 10 additions & 14 deletions pmrmodel/src/model/db/sqlite/exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ use pmrmodel_base::{
exposure::{
Exposure,
Exposures,
// ExposureFile,
// ExposureFiles,
// ExposureFileView,
// ExposureFileViews,
traits::ExposureBackend,
},
};
Expand All @@ -25,7 +21,7 @@ async fn insert_exposure_sqlite(
workspace_id: i64,
workspace_tag_id: Option<i64>,
commit_id: &str,
root_exposure_file_id: Option<i64>,
default_file_id: Option<i64>,
) -> Result<i64, BackendError> {
let created_ts = Utc::now().timestamp();
let id = sqlx::query!(
Expand All @@ -35,15 +31,15 @@ INSERT INTO exposure (
workspace_tag_id,
commit_id,
created_ts,
root_exposure_file_id
default_file_id
)
VALUES ( ?1, ?2, ?3, ?4, ?5 )
"#,
workspace_id,
workspace_tag_id,
commit_id,
created_ts,
root_exposure_file_id,
default_file_id,
)
.execute(&*sqlite.pool)
.await?
Expand All @@ -62,7 +58,7 @@ SELECT
workspace_tag_id,
commit_id,
created_ts,
root_exposure_file_id
default_file_id
FROM exposure
WHERE id = ?1
"#,
Expand All @@ -74,7 +70,7 @@ WHERE id = ?1
workspace_tag_id: row.workspace_tag_id,
commit_id: row.commit_id,
created_ts: row.created_ts,
root_exposure_file_id: row.root_exposure_file_id,
default_file_id: row.default_file_id,
// TODO map to files.
files: None,
})
Expand All @@ -94,7 +90,7 @@ SELECT
workspace_tag_id,
commit_id,
created_ts,
root_exposure_file_id
default_file_id
FROM exposure
WHERE workspace_id = ?1
"#,
Expand All @@ -106,7 +102,7 @@ WHERE workspace_id = ?1
workspace_tag_id: row.workspace_tag_id,
commit_id: row.commit_id,
created_ts: row.created_ts,
root_exposure_file_id: row.root_exposure_file_id,
default_file_id: row.default_file_id,
// won't have files.
files: None,
})
Expand All @@ -122,14 +118,14 @@ impl ExposureBackend for SqliteBackend {
workspace_id: i64,
workspace_tag_id: Option<i64>,
commit_id: &str,
root_exposure_file_id: Option<i64>,
default_file_id: Option<i64>,
) -> Result<i64, BackendError>{
insert_exposure_sqlite(
&self,
workspace_id,
workspace_tag_id,
commit_id,
root_exposure_file_id,
default_file_id,
).await
}

Expand Down Expand Up @@ -194,7 +190,7 @@ pub(crate) mod testing {
workspace_tag_id: None,
commit_id: "abcdef".into(),
created_ts: 1234567890,
root_exposure_file_id: None,
default_file_id: None,
files: None,
// files: Some([].to_vec().into()),
});
Expand Down
Loading

0 comments on commit b819af4

Please sign in to comment.