-
Notifications
You must be signed in to change notification settings - Fork 265
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
Conversation
* 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgAuditDb.scala
Outdated
Show resolved
Hide resolved
Rebased. |
eclair-core/src/main/scala/fr/acinq/eclair/db/jdbc/JdbcUtils.scala
Outdated
Show resolved
Hide resolved
* 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. |
There was a problem hiding this comment.
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.
(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 <[email protected]>
Rebased. |
(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 unintuitiveand led to comments like the following in tests:
The reason is that we treat unitialized databases and up-to-date
databases exactly the same way. That is why a
getVersion
will set theversion 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
thatonly, you know, gets the version (or returns
None
if no versionexists). 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.