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

Rework the db version management #1775

Merged
merged 4 commits into from Apr 20, 2021
Merged

Rework the db version management #1775

merged 4 commits into from Apr 20, 2021

Conversation

pm47
Copy link
Member

@pm47 pm47 commented Apr 19, 2021

(This part of the code is sensitive, but not critical, because bugs
should be obvious, and their impact should be limited to the app
refusing to start.)

No SQL code has been modified, this is just a refactoring.
edit: second commit does remove IF NOT EXISTS statements.

The way our getVersion/setVersion worked was very unintuitive
and led to comments like the following in tests:

dbs.getVersion(statement, "network", 1) // this will set version to 1

The reason is that we treat unitialized databases and up-to-date
databases exactly the same way. That is why a getVersion will set the
version to the most up-to-date if none is found. It's also why we use
CREATE IF NOT EXISTS statements for tables and indices.

I think that is misleading and we should have a getVersion that
only, you know, gets the version (or returns None if no version
exists). We would then treat unitialized databases and up-to-date
databases differently.

Also, there was some variations in the layout between files, which have
been fixed. There is also less repetition.

I'm curious to have your opinion on this @thomash-acinq, since you had to deal with
db migration recently.

Comment on lines +82 to +83
* NB: we could define this method in [[fr.acinq.eclair.db.sqlite.SqliteUtils]] and [[fr.acinq.eclair.db.pg.PgUtils]]
* but it would make testing more complicated because we need to use one or the other depending on the backend.
Copy link
Member Author

Choose a reason for hiding this comment

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

This design choice is debatable but I think it's worthwhile, less duplication and simpler tests.

Copy link
Member

Choose a reason for hiding this comment

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

Since this is a shared mechanism for all DB types, I think it's perfectly fine to have it here, especially if it makes testing easier.

thomash-acinq
thomash-acinq previously approved these changes Apr 19, 2021
@pm47
Copy link
Member Author

pm47 commented Apr 19, 2021

Rebased.

Comment on lines +82 to +83
* NB: we could define this method in [[fr.acinq.eclair.db.sqlite.SqliteUtils]] and [[fr.acinq.eclair.db.pg.PgUtils]]
* but it would make testing more complicated because we need to use one or the other depending on the backend.
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a shared mechanism for all DB types, I think it's perfectly fine to have it here, especially if it makes testing easier.

t-bast
t-bast previously approved these changes Apr 20, 2021
pm47 and others added 4 commits April 20, 2021 13:42
(This part of the code is sensitive, but not critical, because bugs
should be obvious, and their impact should be limited to the app
refusing to start.)

No SQL code has been modified, this is just a refactoring.

The way our `getVersion`/`setVersion` was very unintuitive and led to
comments like the following in tests:
```scala
dbs.getVersion(statement, "network", 1) // this will set version to 1
```

The reason is that we treat unitialized databases and up-to-date
databases exactly the same way. That is why a `getVersion` will set the
version to the most up-to-date if none is found. It's also why we use
`CREATE IF NOT EXISTS` statements for tables and indices.

I think that is very misleading and we should have a `getVersion` that
only, you know, _gets_ the version (or returns `None` if no version
exists). We would then treat unitialized databases and up-to-date
databases differently.

Also, there as some variations in the layout between files, which have
been fixed. There is also less repetition.
Since we now differentiate between uninitialized and up-to-date, we
don't need to make the create statements idempotent. This makes the code
more strict, and we will see errors if our versioning system has bugs.

Note that the `IF NOT EXISTS` statement do not bring any guarantee about
the existing table (pg documentation):

> A notice is issued in this case. Note that there is no guarantee that
the existing relation is anything like the one that would have been
created.

Internal tables (used for versioning, locking, etc.) have been left
unchanged.
Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
@pm47
Copy link
Member Author

pm47 commented Apr 20, 2021

Rebased.

@pm47 pm47 merged commit e092677 into master Apr 20, 2021
@pm47 pm47 deleted the rework-db-version branch April 20, 2021 12:10
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

3 participants