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

Upload API Prep Part 2: Refactor database and api to new table format #35

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

francisduvivier
Copy link
Collaborator

  • Includes adding and using the sql-template-tag package, for increased safety and readability of sql code.
  • Includes putting domain layer between api and db, ddd style

@francisduvivier francisduvivier changed the title Refactor database and api to new table format Refactor database and api to new table format, resolves 26 Nov 27, 2024
@francisduvivier francisduvivier changed the title Refactor database and api to new table format, resolves 26 Refactor database and api to new table format Nov 27, 2024
@francisduvivier francisduvivier changed the title Refactor database and api to new table format Refactor database and api to new table format, resolves #26 Nov 27, 2024
@francisduvivier francisduvivier changed the title Refactor database and api to new table format, resolves #26 Resolves #26, Refactor database and api to new table format Nov 27, 2024
@francisduvivier francisduvivier changed the title Resolves #26, Refactor database and api to new table format Upload API Prep Part 2: Refactor database and api to new table format Nov 27, 2024
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from bbd055c to da8d725 Compare November 27, 2024 23:33
Copy link

github-actions bot commented Nov 27, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 34.54% 524 / 1517
🔵 Statements 34.54% 524 / 1517
🔵 Functions 55% 44 / 80
🔵 Branches 82.14% 46 / 56
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
migrations/20241116085102-initialize.js 0% 0% 0% 0% 1-59
src/auth/jwt.ts 0% 0% 0% 0% 1-110
src/controllers/private-rest.ts 77.77% 100% 0% 77.77% 12-13
src/controllers/public-rest.ts 37.5% 100% 22.22% 37.5% 42-43, 50-61, 68-78, 85-89, 96-101, 108-111, 118-122
src/db/BadgeHubDataPostgresAdapter.ts 28.57% 100% 27.27% 28.57% 35-39, 42-43, 47-79, 82-83, 86-91, 94-98, 120-152, 155-168
src/db/DBTypes.ts 100% 100% 100% 100%
src/db/models/DBBadge.ts 100% 100% 100% 100%
src/db/models/DBProjectStatusOnBadge.ts 100% 100% 100% 100%
src/db/models/app/DBAppMetadataJSON.ts 100% 100% 100% 100%
src/db/models/app/DBCategory.ts 100% 100% 100% 100%
src/db/models/app/DBDatedData.ts 100% 100% 100% 100%
src/db/models/app/DBFileMetadata.ts 100% 100% 100% 100%
src/db/models/app/DBProject.ts 100% 100% 100% 100%
src/db/models/app/DBUser.ts 100% 100% 100% 100%
src/db/models/app/DBVersion.ts 100% 100% 100% 100%
src/db/models/app/DBVersionedDependency.ts 100% 100% 100% 100%
src/db/models/app/DBVote.ts 100% 100% 100% 100%
src/db/models/app/DBVoteFromUser.ts 100% 100% 100% 100%
src/db/models/app/DBWarning.ts 100% 100% 100% 100%
src/db/models/app/DBWarningFromUser.ts 100% 100% 100% 100%
src/db/models/app/relations/ProjectHasCollaborators.ts 100% 100% 100% 100%
src/db/models/app/relations/ProjectHasVotes.ts 100% 100% 100% 100%
src/db/models/app/relations/ProjectHasWarnings.ts 100% 100% 100% 100%
src/db/models/app/relations/VersionHasFiles.ts 100% 100% 100% 100%
src/db/sqlHelpers/dbDates.ts 53.12% 50% 50% 53.12% 11-12, 30-36, 39-44
src/db/sqlHelpers/projectQuery.ts 13.51% 100% 0% 13.51% 12-36, 39-68
src/domain/BadgeHubDataPort.ts 100% 100% 100% 100%
src/domain/readModels/Badge.ts 100% 100% 100% 100%
src/domain/readModels/ProjectStatusOnBadge.ts 100% 100% 100% 100%
src/domain/readModels/app/AppMetadataJSON.ts 100% 100% 100% 100%
src/domain/readModels/app/Category.ts 100% 100% 100% 100%
src/domain/readModels/app/DatedData.ts 100% 100% 100% 100%
src/domain/readModels/app/FileMetadata.ts 100% 100% 100% 100%
src/domain/readModels/app/Project.ts 100% 100% 100% 100%
src/domain/readModels/app/User.ts 100% 100% 100% 100%
src/domain/readModels/app/Version.ts 100% 100% 100% 100%
src/domain/readModels/app/VoteFromUser.ts 100% 100% 100% 100%
src/domain/readModels/app/WarningFromUser.ts 100% 100% 100% 100%
src/generated/routes.ts 60.99% 66.66% 20% 60.99% 375-376, 388-417, 426-460, 469-507, 518-555, 566-609, 620-651, 662-699, 710-741
Generated in workflow #88 for commit 15fdef0 by the Vitest Coverage Report Action

Copy link
Collaborator

@pitastrudl pitastrudl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With some understanding of DBs I did review the DB migration parts which seemed okay and I have not much knowledge of JS to comment on the implementations. As far as I am concerned, this can be merged.

(
id text primary key, -- using text as recommended
email text unique, -- using text as recommended
admin boolean,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still feel like we should use roles for this instead, i.e. a separate table user_roles with an FK to users.id and a 1 -> n relationship, so that users can have multiple roles

Copy link
Collaborator Author

@francisduvivier francisduvivier Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah haven't thought about this at all yet, the users table is actually just taken over from what we already had before this PR. (Except that I changed the user id to a string here in this PR, but then I changed it back to what we had in the next PR.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let;s talk about it on Sunday to tie all this together with the middleware too

password text not null,
remember_token text,
editor text,
public boolean,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between public and show_projects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No Idea honestly.
Did not look into User data at all yet except for being able to relate them to a project.
Maybe @edwinm knows?

email text unique, -- using text as recommended
admin boolean,
name text not null,
password text not null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we salting these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no idea. But actually good point. Gonna remove the user api for now so that this code for user insertion does not get used in production eventually accidentally.

Copy link
Collaborator Author

@francisduvivier francisduvivier Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I disabled the API in the next PR where I added it (#34):
dadfd31

slug text not null primary key,
git text,
allow_team_fixes boolean,
constraint projects_user_id_fk foreign key (user_id) references users (id) on delete cascade -- if user is deleted, delete his projects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete their projects

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes true, if a user really get's deleted out of the DB as opposed to the deleted_at being set, then all the users' projects get deleted as well.
This way we can keep a more clean DB with stronger constraints about the validity of the data.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I meant their as in, singular they (which is gender neutral in English)

Copy link
Collaborator Author

@francisduvivier francisduvivier Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry completely missed that, let me update that.
Edit: added a commit to fix it: it 7f679a1

@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-1 branch from c1330de to a6af53e Compare December 4, 2024 17:18
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from 2a470fd to c290e27 Compare December 4, 2024 17:20
@francisduvivier francisduvivier changed the base branch from feature/26-upload-api-part-1 to main December 9, 2024 12:08
Francis Duvivier added 4 commits December 9, 2024 17:35
…ot duplicating data

We also make a layer between the API and the database in the style of DDD
In order to write more readable queries, we also introduce the sql-template-tag library here
@francisduvivier francisduvivier force-pushed the feature/26-upload-api-part-2 branch from 7f679a1 to 15fdef0 Compare December 9, 2024 16:35
@francisduvivier francisduvivier merged commit cb7ab9a into main Dec 9, 2024
2 checks passed
@francisduvivier francisduvivier deleted the feature/26-upload-api-part-2 branch December 9, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update DB to match proposed App Metadata Schema and Improve type safety
3 participants