-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Check and store package dependencies in database
- Loading branch information
Showing
23 changed files
with
1,294 additions
and
155 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
address = "0.0.0.0" | ||
port = 8080 | ||
workers = 16 | ||
|
||
[default.limits] | ||
file = "10 MB" # Set file upload limit to 10 MB |
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
15 changes: 15 additions & 0 deletions
15
migrations/2025-01-28-173445_move_readme_license_cols/down.sql
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,15 @@ | ||
-- Add `readme` column back to the `package_versions` table | ||
ALTER TABLE package_versions | ||
ADD COLUMN readme VARCHAR; | ||
|
||
-- Migrate data back from `uploads` to `package_versions` | ||
UPDATE package_versions | ||
SET | ||
readme = u.readme | ||
FROM uploads u | ||
WHERE package_versions.upload_id = u.id; | ||
|
||
-- Remove `readme` and `forc_manifest` columns from `uploads` | ||
ALTER TABLE uploads | ||
DROP COLUMN readme, | ||
DROP COLUMN forc_manifest; |
15 changes: 15 additions & 0 deletions
15
migrations/2025-01-28-173445_move_readme_license_cols/up.sql
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,15 @@ | ||
-- Add `readme` and `forc_manifest` columns to the `uploads` table | ||
ALTER TABLE uploads | ||
ADD COLUMN readme VARCHAR, | ||
ADD COLUMN forc_manifest VARCHAR; | ||
|
||
-- Migrate data from `package_versions` to `uploads` | ||
UPDATE uploads | ||
SET | ||
readme = pv.readme | ||
FROM package_versions pv | ||
WHERE uploads.id = pv.upload_id; | ||
|
||
-- Remove `readme` column from `package_versions` | ||
ALTER TABLE package_versions | ||
DROP COLUMN readme; |
1 change: 1 addition & 0 deletions
1
migrations/2025-01-28-173831_create_package_dependencies/down.sql
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 @@ | ||
DROP TABLE package_dependencies; |
9 changes: 9 additions & 0 deletions
9
migrations/2025-01-28-173831_create_package_dependencies/up.sql
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 package_dependencies ( | ||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | ||
dependent_package_version_id UUID NOT NULL, | ||
dependency_package_name VARCHAR NOT NULL, | ||
dependency_version_req VARCHAR NOT NULL, | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
FOREIGN KEY (dependent_package_version_id) REFERENCES package_versions(id) ON DELETE CASCADE | ||
); |
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
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,32 @@ | ||
use super::error::DatabaseError; | ||
use super::{models, schema, DbConn}; | ||
use crate::models::NewPackageDep; | ||
use diesel::prelude::*; | ||
use uuid::Uuid; | ||
|
||
impl DbConn { | ||
/// Insert package dependencies into the database and return the number of rows inserted. | ||
pub fn insert_dependencies( | ||
&mut self, | ||
new_dependencies: Vec<NewPackageDep>, | ||
) -> Result<usize, DatabaseError> { | ||
diesel::insert_into(schema::package_dependencies::table) | ||
.values(&new_dependencies) | ||
.execute(self.inner()) | ||
.map_err(DatabaseError::InsertPackageDepFailed) | ||
} | ||
|
||
/// Fetch the dependencies for a given package version. | ||
pub fn get_dependencies_for_package_version( | ||
&mut self, | ||
package_version_id: Uuid, | ||
) -> Result<Vec<models::PackageDep>, DatabaseError> { | ||
schema::package_dependencies::table | ||
.filter( | ||
schema::package_dependencies::dependent_package_version_id.eq(package_version_id), | ||
) | ||
.select(models::PackageDep::as_returning()) | ||
.load::<models::PackageDep>(self.inner()) | ||
.map_err(|err| DatabaseError::NotFound(package_version_id.to_string(), err)) | ||
} | ||
} |
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,2 @@ | ||
pub mod publish; | ||
pub mod upload; |
Oops, something went wrong.