diff roundup/backends/back_postgresql.py @ 6806:bdd28b244839

- issue2551223 - fix timestamp truncation in mysql and postgresql The data types used to represent timestamps in pg and mysql for ephemeral tables: sessions and otks don't have enough signifcant digits to work. As a result the timestamps are rounduped (up/down) rsuling in the stored timestamp being 2 minutes (pg) or 2-3 hours(mysql) off from what it should be. Modify db schema to use a numeric type that preserves more significant figures. Implement schema upgrade. Document need for upgrade in upgrading.txt. Write tests for schema upgrade. Implement test for updateTimestamp method on BasicDatabase that showed this issue in the first place. Write overrides for test for anydbm/memorydb which store timestamp properly or not at all.
author John Rouillard <rouilj@ieee.org>
date Mon, 25 Jul 2022 17:20:20 -0400
parents db3f0ba75b4a
children b0dbc13a835a
line wrap: on
line diff
--- a/roundup/backends/back_postgresql.py	Mon Jul 25 16:39:31 2022 -0400
+++ b/roundup/backends/back_postgresql.py	Mon Jul 25 17:20:20 2022 -0400
@@ -234,12 +234,12 @@
     def create_version_2_tables(self):
         # OTK store
         self.sql('''CREATE TABLE otks (otk_key VARCHAR(255),
-            otk_value TEXT, otk_time REAL)''')
+            otk_value TEXT, otk_time float)''')
         self.sql('CREATE INDEX otks_key_idx ON otks(otk_key)')
 
         # Sessions store
         self.sql('''CREATE TABLE sessions (
-            session_key VARCHAR(255), session_time REAL,
+            session_key VARCHAR(255), session_time float,
             session_value TEXT)''')
         self.sql('''CREATE INDEX sessions_key_idx ON
             sessions(session_key)''')
@@ -296,6 +296,14 @@
 
         self._add_fts_table()
 
+    def fix_version_7_tables(self):
+        # Modify type for session.session_time/otk.otk_time column.
+        # float is double precision 15 signifcant digits
+        sql = 'alter table sessions alter column session_time type float'
+        self.sql(sql)
+        sql = 'alter table otks alter column otk_time type float'
+        self.sql(sql)
+
     def add_actor_column(self):
         # update existing tables to have the new actor column
         tables = self.database_schema['tables']

Roundup Issue Tracker: http://roundup-tracker.org/