From ae435a31654cfc5e2447c7dca757c1e40a45bbb9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 12 Dec 2020 20:11:23 -0800 Subject: [PATCH] =?UTF-8?q?Removes=20sqlite=20support=20=F0=9F=98=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RIP, things have gotten too complicated for this I think --- bookwyrm/models/import_job.py | 2 +- bookwyrm/settings.py | 4 --- bookwyrm/utils/fields.py | 67 ----------------------------------- 3 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 bookwyrm/utils/fields.py diff --git a/bookwyrm/models/import_job.py b/bookwyrm/models/import_job.py index 8b09216f..bf5d5caf 100644 --- a/bookwyrm/models/import_job.py +++ b/bookwyrm/models/import_job.py @@ -2,12 +2,12 @@ import re import dateutil.parser +from django.contrib.postgres.fields import JSONField from django.db import models from django.utils import timezone from bookwyrm import books_manager from bookwyrm.models import ReadThrough, User, Book -from bookwyrm.utils.fields import JSONField from .base_model import PrivacyLevels diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 3784158c..c42215b4 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -99,10 +99,6 @@ BOOKWYRM_DBS = { 'HOST': env('POSTGRES_HOST', ''), 'PORT': 5432 }, - 'sqlite': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'fedireads.db') - } } DATABASES = { diff --git a/bookwyrm/utils/fields.py b/bookwyrm/utils/fields.py deleted file mode 100644 index 8978f4bc..00000000 --- a/bookwyrm/utils/fields.py +++ /dev/null @@ -1,67 +0,0 @@ -'''Quick and dirty shim for JSONField and ArrayField compatibility on sqlite. - -For more info and original code, see: -- https://medium.com/@philamersune/using-postgresql-jsonfield-in-sqlite-95ad4ad2e5f1 -- https://gist.github.com/pvsune/2e5f9f9ae356d0bff633d896bc7d168b#file-django-sqlite-fields-py -''' - -import json - -from django.conf import settings -from django.contrib.postgres.fields import ( - JSONField as DjangoJSONField, - ArrayField as DjangoArrayField, -) -from django.db.models import Field - - -class JSONField(DjangoJSONField): - pass - - -class ArrayField(DjangoArrayField): - pass - - -if 'sqlite' in settings.DATABASES['default']['ENGINE']: - class JSONField(Field): - def db_type(self, connection): - return 'text' - - def from_db_value(self, value, expression, connection): - if value is not None: - return self.to_python(value) - return value - - def to_python(self, value): - if value is not None: - try: - return json.loads(value) - except (TypeError, ValueError): - return value - return value - - def get_prep_value(self, value): - if value is not None: - return str(json.dumps(value)) - return value - - def value_to_string(self, obj): - return self.value_from_object(obj) - - - class ArrayField(JSONField): - def __init__(self, base_field, size=None, **kwargs): - """Care for DjangoArrayField's kwargs.""" - self.base_field = base_field - self.size = size - super().__init__(**kwargs) - - def deconstruct(self): - """Need to create migrations properly.""" - name, path, args, kwargs = super().deconstruct() - kwargs.update({ - 'base_field': self.base_field.clone(), - 'size': self.size, - }) - return name, path, args, kwargs