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

Add PostgreSQL as DB Option #275

Merged
merged 8 commits into from
Oct 16, 2023
Merged

Conversation

nickmurray47
Copy link
Contributor

@nickmurray47 nickmurray47 commented Oct 10, 2023

Testing steps:

  • go mod vendor
  • update config.yaml to have postgres as database type
  • from fasten-onprem/backend/pkg/models/database run go run generate.go and verify that all the database models have swapped out datetime for timestamptz

Discussion with @AnalogJ and @nickmurray47 about followup work

  • updates to the generate.go file
  • postgres functionality working similar to Sqlite
    • start by getting the backend test suite passing for postgres
    • Github Actions support for Postgres

@nickmurray47 nickmurray47 self-assigned this Oct 10, 2023
We add a database type, which is defaulted to sqlite
@nickmurray47 nickmurray47 force-pushed the nickmurray/add-postgres-db-option branch from 6e5f395 to 816d823 Compare October 10, 2023 17:51
We need to swap out datetime with timestamptz in order to properly allow for a postgres DB provider
@nickmurray47
Copy link
Contributor Author

to-do:

  • create common Gorm file for sqlite/postgres versions to inherit from
  • create factory file for generating database/postrgres/ folder

AnalogJ and others added 2 commits October 12, 2023 14:19
Users can select database type using database.type configuration when calling NewRepository()
Select(strings.Join(selectClauses, ", ")).
Where(strings.Join(whereClauses, " AND "), whereNamedParameters).
Group(groupClause).
Order(orderClause).

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query depends on a
user-provided value
.
@AnalogJ
Copy link
Member

AnalogJ commented Oct 14, 2023

Hey Nick, I'm worried that this PR might end up requiring a long-lived branch if we start making the "common" repository changes and adding the Postgres repository stuff now
Can we move that to another PR, and merge just the Factory pattern + model changes?

@nickmurray47
Copy link
Contributor Author

I'm worried that this PR might end up requiring a long-lived branch if we start making the "common" repository changes and adding the Postgres repository stuff now
Can we move that to another PR, and merge just the Factory pattern + model changes?

Yes, I was actually going to stop here and ping you for a review. Do you still want to move the "common" + postgres changes out? I just re-tested with SQlite as default and everything appeared operational.

@AnalogJ
Copy link
Member

AnalogJ commented Oct 15, 2023 via email

@nickmurray47
Copy link
Contributor Author

nickmurray47 commented Oct 16, 2023

Yeah, can chat Monday morning!

I’ll just worried that there are changes in the main branch that
may not be reflected in yours.

re: will talk further on this in chat, but any preference on merge commit vs. rebase?

@AnalogJ
Copy link
Member

AnalogJ commented Oct 16, 2023

I think the merge commit is fine.

Picked up on most recent change with DeleteSource func
@nickmurray47 nickmurray47 changed the title [WIP] Add PostgreSQL as DB Option Add PostgreSQL as DB Option Oct 16, 2023
@nickmurray47
Copy link
Contributor Author

nickmurray47 commented Oct 16, 2023

Merged main and made sure we picked up on most recent commit c590663537faab12d4416edd3f7756b678ee5460 to sqlite_repository.go for adding the DeleteResource func.

@@ -47,6 +51,22 @@ PLEASE DO NOT EDIT BY HAND
`, "\n"), "\n")

func main() {
// Read config file for database type
appconfig, err := config.Create()
Copy link
Member

@AnalogJ AnalogJ Oct 16, 2023

Choose a reason for hiding this comment

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

Compile time vs runtime.
The user's configuration file will not be present during compilation time, so the database type choice has not been made yet.
We need to generate both Sqlite & Postgres compatible structs (in different directories).
The generated utils.NewFhirResourceModelByType fn should take in the DatabaseRepositoryType as a parameter, and conditionally point to a different set of generated structs.

We'll make this change in a follow up PR.

@AnalogJ AnalogJ merged commit 8861e4b into main Oct 16, 2023
4 of 6 checks passed
@AnalogJ AnalogJ deleted the nickmurray/add-postgres-db-option branch October 21, 2023 18: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.

None yet

2 participants