Skip to content

Commit 3cfa2fd

Browse files
authored
Merge pull request #48 from HBS-HBX/#6_support_django_2
closes #6 support django 2
2 parents a247cf4 + 86d5729 commit 3cfa2fd

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ matrix:
1515
python: 3.5
1616
- env: TOX_ENV=py35-django111-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
1717
python: 3.5
18-
# TBD support - will be implemented in #5
19-
# allow_failures:
20-
# - env: TOX_ENV=py27-django19-es62 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
21-
# python: 2.7
22-
# - env: TOX_ENV=py36-django19-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
23-
# python: 3.6
24-
# - env: TOX_ENV=py36-django18-es61 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
25-
# python: 3.6
18+
- env: TOX_ENV=py35-django20-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
19+
python: 3.5
20+
- env: TOX_ENV=py35-django21-es60 ES_APT_URL=https://artifacts.elastic.co/packages/6.x/apt
21+
python: 3.5
2622

2723
before_install:
2824
- pip install --upgrade pip

django_elastic_migrations/migrations/0007_auto_20181112_0937.py renamed to django_elastic_migrations/migrations/0007_auto_20181113_0958.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
# Generated by Django 1.11 on 2018-11-12 09:37
3-
from __future__ import unicode_literals
1+
# Generated by Django 2.1.3 on 2018-11-13 09:58
42

53
from django.db import migrations, models
4+
import django.db.models.deletion
65

76

87
class Migration(migrations.Migration):
@@ -15,6 +14,11 @@ class Migration(migrations.Migration):
1514
migrations.DeleteModel(
1615
name='DeactivateIndexAction',
1716
),
17+
migrations.AlterField(
18+
model_name='index',
19+
name='active_version',
20+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='django_elastic_migrations.IndexVersion'),
21+
),
1822
migrations.AlterField(
1923
model_name='indexaction',
2024
name='action',

django_elastic_migrations/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Index(models.Model):
3636
# See https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.ForeignKey.related_name
3737
active_version = models.ForeignKey(
3838
'django_elastic_migrations.IndexVersion',
39-
related_name="+", null=True)
39+
related_name="+", null=True, on_delete=models.SET_NULL)
4040

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

222222
# linked models
223-
index = models.ForeignKey(Index)
224-
index_version = models.ForeignKey(IndexVersion, null=True)
223+
index = models.ForeignKey(Index, on_delete=models.CASCADE)
224+
index_version = models.ForeignKey(IndexVersion, null=True, on_delete=models.CASCADE)
225225

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

229229
# which management command was run
230230
action = models.CharField(choices=ACTIONS_ALL_CHOICES, max_length=64)

django_elastic_migrations/utils/es_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def get_index_hash_and_json(index):
66
spec = index.to_dict()
7-
json_str = json.dumps(spec, sort_keys=True).encode('utf-8')
7+
json_str = json.dumps(spec, sort_keys=True)
88
md5_hash = hashlib.md5()
9-
md5_hash.update(json_str)
9+
md5_hash.update(json_str.encode('utf-8'))
1010
return md5_hash.hexdigest(), json_str

django_elastic_migrations/utils/multiprocessing_utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# coding=utf-8
2-
2+
# noinspection PyCompatibility
3+
import queue
34
import time
45
import traceback
56
from multiprocessing import Process, cpu_count, Manager
6-
# noinspection PyCompatibility
7-
from queue import Empty
87

98
from django import db
109
from django.conf import settings
@@ -236,7 +235,7 @@ def results(self):
236235
try:
237236
while True:
238237
rv.append(self.queue.get(block=False))
239-
except Empty:
238+
except queue.Empty:
240239
return rv
241240

242241
def __exit__(self, type, value, traceback):

tox.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[tox]
22
envlist =
3-
{py35}-{django110,django111}-{es61}
4-
; not implemented yet - DocType Changes in es62 pending - see github issue #3 Support elasticsearch-dsl 6.2
5-
; {py35}-django19-{es62}
3+
{py35}-{django110,django111,django20,django21}-{es61}
64

75
[doc8]
86
max-line-length = 120

0 commit comments

Comments
 (0)