mirror of
https://github.com/evennia/evennia.git
synced 2026-03-26 09:46:32 +01:00
MySQL<v5.6.4 does not support millisecond precision in its DATETIME fields (as opposed to other databases). This meant that Attributes, which do rely on millisecond precision for creating their object hashes, got out of sync in a horrible way on MySQL (Issue 362). This revision fixes the problem by going to second-level precision if a too-low version of MySQL is detected (this should not be an issue since mysql does not reuse its pks anyway).
This commit is contained in:
parent
95268406ab
commit
a533232885
2 changed files with 21 additions and 1 deletions
|
|
@ -39,3 +39,13 @@ class ServerConfigManager(models.Manager):
|
|||
if not conf:
|
||||
return default
|
||||
return conf[0].value
|
||||
|
||||
def get_mysql_db_version(self):
|
||||
"""
|
||||
This is a helper method for getting the version string of a mysql database.
|
||||
"""
|
||||
from django.db import connection
|
||||
conn = connection.cursor()
|
||||
conn.execute("SELECT VERSION()")
|
||||
version = conn.fetchone()
|
||||
return version and str(version[0]) or ""
|
||||
|
|
|
|||
|
|
@ -28,9 +28,13 @@ except ImportError:
|
|||
from django.db import transaction
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from src.utils.utils import to_str
|
||||
from src.utils.utils import to_str, uses_database
|
||||
from src.utils import logger
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
__all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle")
|
||||
|
||||
PICKLE_PROTOCOL = 2
|
||||
|
|
@ -44,6 +48,12 @@ _TO_MODEL_MAP = None
|
|||
_TO_TYPECLASS = lambda o: hasattr(o, 'typeclass') and o.typeclass or o
|
||||
_IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[0] == '__packed_dbobj__'
|
||||
_TO_DATESTRING = lambda o: _GA(o, "db_date_created").strftime("%Y:%m:%d-%H:%M:%S:%f")
|
||||
if uses_database("mysql"):
|
||||
from src.server.models import ServerConfig
|
||||
mysql_version = ServerConfig.objects.get_mysql_db_version()
|
||||
if mysql_version < '5.6.4':
|
||||
# mysql <5.6.4 don't support millisecond precision
|
||||
_TO_DATESTRING = lambda o: _GA(o, "db_date_created").strftime("%Y:%m:%d-%H:%M:%S:000000")
|
||||
|
||||
def _init_globals():
|
||||
"Lazy importing to avoid circular import issues"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue