Skip to content

Commit

Permalink
Merge pull request #48 from HBS-HBX/#6_support_django_2
Browse files Browse the repository at this point in the history
closes #6 support django 2
  • Loading branch information
codekiln authored Nov 13, 2018
2 parents a247cf4 + 86d5729 commit 3cfa2fd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ matrix:
python: 3.5
- env: TOX_ENV=py35-django111-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
python: 3.5
# TBD support - will be implemented in #5
# allow_failures:
# - env: TOX_ENV=py27-django19-es62 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
# python: 2.7
# - env: TOX_ENV=py36-django19-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
# python: 3.6
# - env: TOX_ENV=py36-django18-es61 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
# python: 3.6
- env: TOX_ENV=py35-django20-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
python: 3.5
- env: TOX_ENV=py35-django21-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
python: 3.5

before_install:
- pip install --upgrade pip
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-11-12 09:37
from __future__ import unicode_literals
# Generated by Django 2.1.3 on 2018-11-13 09:58

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand All @@ -15,6 +14,11 @@ class Migration(migrations.Migration):
migrations.DeleteModel(
name='DeactivateIndexAction',
),
migrations.AlterField(
model_name='index',
name='active_version',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='django_elastic_migrations.IndexVersion'),
),
migrations.AlterField(
model_name='indexaction',
name='action',
Expand Down
10 changes: 5 additions & 5 deletions django_elastic_migrations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Index(models.Model):
# See https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.ForeignKey.related_name
active_version = models.ForeignKey(
'django_elastic_migrations.IndexVersion',
related_name="+", null=True)
related_name="+", null=True, on_delete=models.SET_NULL)

def __str__(self):
"""
Expand Down Expand Up @@ -110,7 +110,7 @@ class IndexVersion(models.Model):
a IndexVersion is added to the table, and a new Elasticsearch
index is created with that schema.
"""
index = models.ForeignKey(Index)
index = models.ForeignKey(Index, models.CASCADE)
prefix = models.CharField(verbose_name="Environment Prefix", max_length=32, blank=True)
# store the JSON sent to Elasticsearch to configure the index
# note: the index name field in this field does NOT include the IndexVersion id
Expand Down Expand Up @@ -220,11 +220,11 @@ class IndexAction(models.Model):
DEFAULT_ACTION = ACTION_CREATE_INDEX

# linked models
index = models.ForeignKey(Index)
index_version = models.ForeignKey(IndexVersion, null=True)
index = models.ForeignKey(Index, on_delete=models.CASCADE)
index_version = models.ForeignKey(IndexVersion, null=True, on_delete=models.CASCADE)

# if this IndexAction has a parent IndexAction, its id is here
parent = models.ForeignKey("self", null=True, related_name="children")
parent = models.ForeignKey("self", null=True, related_name="children", on_delete=models.CASCADE)

# which management command was run
action = models.CharField(choices=ACTIONS_ALL_CHOICES, max_length=64)
Expand Down
4 changes: 2 additions & 2 deletions django_elastic_migrations/utils/es_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def get_index_hash_and_json(index):
spec = index.to_dict()
json_str = json.dumps(spec, sort_keys=True).encode('utf-8')
json_str = json.dumps(spec, sort_keys=True)
md5_hash = hashlib.md5()
md5_hash.update(json_str)
md5_hash.update(json_str.encode('utf-8'))
return md5_hash.hexdigest(), json_str
7 changes: 3 additions & 4 deletions django_elastic_migrations/utils/multiprocessing_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# coding=utf-8

# noinspection PyCompatibility
import queue
import time
import traceback
from multiprocessing import Process, cpu_count, Manager
# noinspection PyCompatibility
from queue import Empty

from django import db
from django.conf import settings
Expand Down Expand Up @@ -236,7 +235,7 @@ def results(self):
try:
while True:
rv.append(self.queue.get(block=False))
except Empty:
except queue.Empty:
return rv

def __exit__(self, type, value, traceback):
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[tox]
envlist =
{py35}-{django110,django111}-{es61}
; not implemented yet - DocType Changes in es62 pending - see github issue #3 Support elasticsearch-dsl 6.2
; {py35}-django19-{es62}
{py35}-{django110,django111,django20,django21}-{es61}

[doc8]
max-line-length = 120
Expand Down

0 comments on commit 3cfa2fd

Please sign in to comment.