aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/quarg/database/tables.py
diff options
context:
space:
mode:
Diffstat (limited to 'quarg/database/tables.py')
-rw-r--r--quarg/database/tables.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/quarg/database/tables.py b/quarg/database/tables.py
index 10e6057..743ffa2 100644
--- a/quarg/database/tables.py
+++ b/quarg/database/tables.py
@@ -1,10 +1,26 @@
+import datetime
+
from sqlalchemy.schema import Column, ForeignKey
-from sqlalchemy.types import BigInteger, Boolean, DateTime, Integer, Text
+from sqlalchemy.types import BigInteger, Boolean, DateTime, Integer, Text, TypeDecorator
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
# pylint: disable=too-few-public-methods
+# Timestamps are saved in the database in UTC without timezone info, so attach
+# a UTC timezone to the datetime object
+class DateTimeUTC(TypeDecorator):
+ # pylint complains that process_{bind,literal}_param and python_type are
+ # abstract but not overriden. This seems to not be necessary with
+ # SQLAlchemy, so squash those warnings
+ # pylint: disable=abstract-method
+ impl = DateTime
+
+ def process_result_value(self, value, dialect):
+ if value is not None:
+ value = value.replace(tzinfo=datetime.timezone.utc)
+ return value
+
Base = declarative_base()
# Note: We have commented out unused columns to keep SQLAlchemy from selecting
@@ -13,7 +29,7 @@ Base = declarative_base()
class Backlog(Base):
__tablename__ = 'backlog'
messageid = Column(BigInteger, primary_key=True)
- time = Column(DateTime)
+ time = Column(DateTimeUTC)
bufferid = Column(Integer, ForeignKey('buffer.bufferid'))
type = Column(Integer)
flags = Column(Integer)