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

feat(server): add postgres major version check #6213

Merged
merged 6 commits into from
Jan 7, 2024

Conversation

maxer137
Copy link
Contributor

@maxer137 maxer137 commented Jan 6, 2024

The pgvecto.rs extension, though not distributed, can be built for PostgreSQL 12 and 13.
An installation of PostgreSQL 12 with the pgvecto.rs extensions installed will not be caught by immich.
This causes immich to attempt to run the database migrations without having a proper environment.
With assertPostgresql the server will throw an error if the PostgreSQL version is not within the supported range.

…upported versions

The pgvecto.rs extension, though not distributed, can be built for PostgreSQL 12 and 13.
An installation of PostgreSQL 12 with the pgvecto.rs extensions installed will not be caught by immich.
This causes immich to attempt to run the database migrations without having a proper environment.
With assertPostgresql the server will throw an error if the PostgreSQL version is not within the supported range.
@zackpollard
Copy link
Contributor

Hey, thanks for the PR, I think I would prefer if we did this as a greater than comparison rather than an explicit list, would you be able to make that change? 😊

max added 2 commits January 6, 2024 14:45
If we define one we might as well use it. makes changing the versioning later easier
Copy link
Contributor

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

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

LGTM

@maxer137
Copy link
Contributor Author

maxer137 commented Jan 6, 2024

I have replaced the list with the comparison.
My original reasoning was that if PostgreSQL 17 would bring breaking changes we would also thrown an error.
But I think that this might be better.

@zackpollard
Copy link
Contributor

Yea, my reasoning is basically that we don't actually officially support any version other than 14 now anyway. So limiting the versions almost feels like we have tested with versions over 14 which we don't. Running anything other than 14 is at your own risk basically, but I agree we shouldn't let people run versions under 14 as it's likely to use features that don't yet exist in those versions.

@zackpollard
Copy link
Contributor

You have a failing test but once that is fixed I'll get this merged in 😊

@maxer137
Copy link
Contributor Author

maxer137 commented Jan 6, 2024

The problem is that in the tests, we use mockResolvedValueOnce.
With my addition, the postgres version is being read out twice.
Shall I replace the databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0))) calls with
databaseMock.getPostgresVersion.mockResolvedValue(new Version(major, 0, 0)))?

@zackpollard
Copy link
Contributor

The problem is that in the tests, we use mockResolvedValueOnce. With my addition, the postgres version is being read out twice. Shall I replace the databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0))) calls with databaseMock.getPostgresVersion.mockResolvedValue(new Version(major, 0, 0)))?

Works for me

@zackpollard
Copy link
Contributor

Would maybe be good also to add a test specifically testing this functionality, so a test that asserts the correct error is thrown when postgres version is less than 14 😄

max added 3 commits January 6, 2024 15:51
`should return if minimum supported PostgreSQL and vectors version are installed`:
Check if init returns properly and that getPostgresVersion is called twice

`should thrown an error if PostgreSQL version is below minimum supported version`:
Checks if the init function correctly returns an error

`should suggest image with postgres ${major} if database is ${major}`:
Modified to set MockResolvedValue instead of MockResolvedValueOnce. With the new check we get the PostgreSQL version twice. So it needs to be set during the entire test.

`should not suggest image if postgres version is not in 14, 15 or 16`:
Modified the bounds to [14, 18]. Because values below 14 now will not get called.
Also Modified to call `getPostgresVersion.MockResolvedValueOnce` for twice, because it gets called twice.
`should thrown an error if PostgreSQL version is below minimum supported version`:
The regex function I wrote mistakingly used the negate function which check that the error *did not* contain the phrase "PostgreSQL". Which is the opposite

`should not suggest image if postgres version is not in 14, 15 or 16`:
confused bounds for a normal javascript array. Changed the test to only check for values above 16. As values below 14 will get thrown out by test `should return if minimum supported PostgreSQL and vectors version are installed`

I apologise for the mistakes in my previous commit.
@zackpollard
Copy link
Contributor

I haven't merged this yet as I wanted to double check the tests on my PC, won't be able to do that until this evening

@jrasm91 jrasm91 changed the title feat(server): Throw error when PostgreSQL version is 13 or older feat(server): add postgres major version check Jan 7, 2024
@jrasm91
Copy link
Contributor

jrasm91 commented Jan 7, 2024

I checked with 13 and it threw and error. Then I check with 14 and it worked as expected.

@jrasm91 jrasm91 merged commit 6835d45 into immich-app:main Jan 7, 2024
20 checks passed
martabal pushed a commit that referenced this pull request Jan 9, 2024
* feat(server): Throw error when PostgreSQL version is not within the supported versions
The pgvecto.rs extension, though not distributed, can be built for PostgreSQL 12 and 13.
An installation of PostgreSQL 12 with the pgvecto.rs extensions installed will not be caught by immich.
This causes immich to attempt to run the database migrations without having a proper environment.
With assertPostgresql the server will throw an error if the PostgreSQL version is not within the supported range.

* Replaced assertion with lesser than comparison
As requested by @zackpollard

* Changed the comparison to use the minPostgresVersion variable.
If we define one we might as well use it. makes changing the versioning later easier

* Added two new tests, modified two existing tests

`should return if minimum supported PostgreSQL and vectors version are installed`:
Check if init returns properly and that getPostgresVersion is called twice

`should thrown an error if PostgreSQL version is below minimum supported version`:
Checks if the init function correctly returns an error

`should suggest image with postgres ${major} if database is ${major}`:
Modified to set MockResolvedValue instead of MockResolvedValueOnce. With the new check we get the PostgreSQL version twice. So it needs to be set during the entire test.

`should not suggest image if postgres version is not in 14, 15 or 16`:
Modified the bounds to [14, 18]. Because values below 14 now will not get called.
Also Modified to call `getPostgresVersion.MockResolvedValueOnce` for twice, because it gets called twice.

* Fixed two mistakes in the jest functions from previous commit #2abcb60

`should thrown an error if PostgreSQL version is below minimum supported version`:
The regex function I wrote mistakingly used the negate function which check that the error *did not* contain the phrase "PostgreSQL". Which is the opposite

`should not suggest image if postgres version is not in 14, 15 or 16`:
confused bounds for a normal javascript array. Changed the test to only check for values above 16. As values below 14 will get thrown out by test `should return if minimum supported PostgreSQL and vectors version are installed`

I apologise for the mistakes in my previous commit.

* Format fix

---------

Co-authored-by: max <wak@vanling.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants