-
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
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. |
@@ -52,15 +53,25 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging { | |||
statement.executeUpdate("CREATE INDEX relayed_trampoline_payment_hash_idx ON relayed_trampoline(payment_hash)") | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was provided as an example in the postgres documentation.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to make similarities obvious between lines. Removed in 641abae.
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.
It's still there in this file...?
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.
Oops, forgot one file. Fixed with 1ff9b7b.
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
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.
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).
@@ -52,15 +53,25 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging { | |||
statement.executeUpdate("CREATE INDEX relayed_trampoline_payment_hash_idx ON relayed_trampoline(payment_hash)") | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
migrationCheck
helper method.
Note that the change of data type in sqlite for the
commitment_number
field (from
BLOB
toINTEGER
) 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.