Use proper data type for timestamps in Postgres#1778
Conversation
Did some refactoring in tests and introduced a new `migrationCheck` helper method. Note that the change of data type in sqlite for the `commitment_number` field (from `BLOB` to `INTEGER`) is not a migration. If the table has been created before, it will stay like it was. It doesn't matter due to how sqlite stores data, and we make sure in tests that there is no regression.
|
I didn't add a specific v5->v6 migration test because existing tests already make sure that there are no issues with the edit: also, v5 was not part of a release. |
| } | ||
|
|
||
| def migration56(statement: Statement): Unit = { | ||
| statement.executeUpdate("ALTER TABLE sent ALTER COLUMN timestamp SET DATA TYPE TIMESTAMP WITH TIME ZONE USING timestamp with time zone 'epoch' + timestamp * interval '1 millisecond'") |
There was a problem hiding this comment.
This was provided as an example in the postgres documentation.
There was a problem hiding this comment.
I don't think the spaces are very useful, I don't see a good reason to align these statements together.
There was a problem hiding this comment.
The idea was to make similarities obvious between lines. Removed in 641abae.
There was a problem hiding this comment.
It's still there in this file...?
I agree that the migration is already covered by the other tests. However I find it awkward that the sqlite and postgres databases are now using different versions, I would bump the version for sqlite too just to stay consistent. |
Codecov Report
@@ Coverage Diff @@
## master #1778 +/- ##
==========================================
+ Coverage 89.27% 89.29% +0.01%
==========================================
Files 144 144
Lines 10903 10923 +20
Branches 475 458 -17
==========================================
+ Hits 9734 9754 +20
Misses 1169 1169
|
The reason is that sqlite has not been migrated, it still stores timestamps as |
eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgAuditDb.scala
Outdated
Show resolved
Hide resolved
t-bast
left a comment
There was a problem hiding this comment.
Ok I can see why having the version numbers diverge between sqlite and postgres make the migration tests quite harder to read...
But I think there's no way around it, we will want to make them evolve independently. I think it's ok to have completely separate migration tests for each DB type in the future. The important tests to share between DB types are the functional tests of the behavior of the latest DB version (e.g. add/remove/list channels for the channels DB).
| } | ||
|
|
||
| def migration56(statement: Statement): Unit = { | ||
| statement.executeUpdate("ALTER TABLE sent ALTER COLUMN timestamp SET DATA TYPE TIMESTAMP WITH TIME ZONE USING timestamp with time zone 'epoch' + timestamp * interval '1 millisecond'") |
There was a problem hiding this comment.
I don't think the spaces are very useful, I don't see a good reason to align these statements together.
eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgAuditDb.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/db/sqlite/SqliteChannelsDb.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/db/AuditDbSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/db/ChannelsDbSpec.scala
Outdated
Show resolved
Hide resolved
|
🤟 |
For some reason, the payments database was forgotten by #1778.
For some reason, the payments database was forgotten by #1778.
For some reason, the payments database was forgotten by #1778.
For some reason, the payments database was forgotten by #1778.
For some reason, the payments database was forgotten by #1778.
Did some refactoring in tests and introduced a new
migrationCheckhelper method.
Note that the change of data type in sqlite for the
commitment_numberfield (from
BLOBtoINTEGER) is not a migration. If the table hasbeen created before, it will stay like it was. It doesn't matter due to
how sqlite stores data, and we make sure in tests that there is no
regression.