usgo / usgo-sql-schemas

Schema's for some of the USGO Databases
4 stars 3 forks source link

Add DATETIME Support for Tables #10

Open michaelhiiva opened 3 years ago

michaelhiiva commented 3 years ago

Summary

There is a combination of DATE and DATETIME used within the schema. In order to support time zones within the AGAGD usgo/agagd#131, one needs DATETIME; however, there are several instances of DATE within the database which need change in order to support Django's datetimes and time zones. Problematic, when trying to use django-tables2's DateTimeColumn, as it results in a error:

app_1  | Internal Server Error: /
app_1  | Traceback (most recent call last):
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 41, in inner
app_1  |     response = get_response(request)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
app_1  |     response = self._get_response(request)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
app_1  |     response = self.process_exception_by_middleware(e, request)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
app_1  |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
app_1  |   File "./agagd_core/views/core.py", line 44, in index
app_1  |     'tournaments': t_table,
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/shortcuts.py", line 30, in render
app_1  |     content = loader.render_to_string(template_name, context, request, using=using)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader.py", line 68, in render_to_string
app_1  |     return template.render(context, request)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/backends/django.py", line 66, in render
app_1  |     return self.template.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 207, in render
app_1  |     return self._render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 199, in _render
app_1  |     return self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader_tags.py", line 177, in render
app_1  |     return compiled_parent._render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 199, in _render
app_1  |     return self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader_tags.py", line 72, in render
app_1  |     result = block.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/defaulttags.py", line 322, in render
app_1  |     return nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django_tables2/templatetags/django_tables2.py", line 169, in render
app_1  |     return template.render(context={'table': table}, request=request)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/backends/django.py", line 66, in render
app_1  |     return self.template.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 207, in render
app_1  |     return self._render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 199, in _render
app_1  |     return self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader_tags.py", line 63, in render
app_1  |     result = self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader_tags.py", line 63, in render
app_1  |     result = self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/loader_tags.py", line 63, in render
app_1  |     result = self.nodelist.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 990, in render
app_1  |     bit = node.render_annotated(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/base.py", line 957, in render_annotated
app_1  |     return self.render(context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/template/defaulttags.py", line 173, in render
app_1  |     len_values = len(values)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django_tables2/rows.py", line 340, in __len__
app_1  |     length = len(self.data)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/models/query.py", line 232, in __len__
app_1  |     self._fetch_all()
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/models/query.py", line 1121, in _fetch_all
app_1  |     self._result_cache = list(self._iterable_class(self))
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/models/query.py", line 62, in __iter__
app_1  |     for row in compiler.results_iter(results):
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 847, in results_iter
app_1  |     row = self.apply_converters(row, converters)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 832, in apply_converters
app_1  |     value = converter(value, expression, self.connection, self.query.context)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 239, in convert_datetimefield_value
app_1  |     value = timezone.make_aware(value, self.connection.timezone)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/django/utils/timezone.py", line 285, in make_aware
app_1  |     return timezone.localize(value, is_dst=is_dst)
app_1  |   File "/home/django/.local/lib/python3.7/site-packages/pytz/__init__.py", line 244, in localize
app_1  |     if dt.tzinfo is not None:
app_1  | AttributeError: 'datetime.date' object has no attribute 'tzinfo'

schema.sql - DATE

95:    `Game_Date` DATE NOT NULL,
110:    `Elab_Date` DATE NOT NULL,
116:    `legacy_updated` DATE DEFAULT NULL,
117:    `legacy_web_updated` DATE DEFAULT NULL,
125:    `renewal_due` DATE DEFAULT NULL,
126:    `join_date` DATE DEFAULT NULL,
127:    `dob` DATE DEFAULT NULL,
261:    `Elab_Date` DATE NOT NULL,
263:    `MExp` DATE NOT NULL DEFAULT '1900-01-01',
296:    `Elab_Date` DATE DEFAULT NULL,
337:    `entrydate` DATE DEFAULT NULL
343:    `Tournament_Date` DATE NOT NULL,
350:    `Elab_Date` DATE NOT NULL,

Expected Behaviour

DATE columns are converted to DATETIME columns

Notes

vash3g commented 3 years ago

If we change to DATETIME for the specified columns will the dates write the same or will we be displaying time data with the dates?