Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #66 from willbarton/django18-migrations
Browse files Browse the repository at this point in the history
Django 1.8 migrations
  • Loading branch information
hillaryj committed Apr 11, 2016
2 parents aa8307b + d48fcdc commit 44008b6
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 1,264 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
sudo: false
python:
- "2.6"
- "2.7"
install:
- pip install -r requirements.txt
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ Requirements are retrieved and/or build automatically via pip (see below).
* pyelasticsearch - required if using Elastic Search
* flake8 - while not strictly required, we try to meet its standards
* pysolr - required if using solr as a search backend
* south - Django's migration helper. Needed if using Django Models for
storage

## API Docs

Expand All @@ -57,7 +55,7 @@ $ pip install -r requirements_dev.txt # helpful modules for developers

With that, you just need a few additional commands to get up and running:
```bash
$ python manage.py syncdb --migrate
$ python manage.py migrate
$ python manage.py runserver
```

Expand Down Expand Up @@ -121,13 +119,13 @@ BACKENDS = {
}
```

Remember to run south migrations.
Remember to run migrations.

### Django Models For Data, Elastic Search For Search

If *pyelasticsearch* and *south* are installed, you can combine Django
models and Elastic Search. Use the *regcore_read.views.es_search.search* and
use the following backend configuration:
If *pyelasticsearch* is installed, you can combine Django models and Elastic
Search. Use the *regcore_read.views.es_search.search* and use the following
backend configuration:

```python
BACKENDS = {
Expand All @@ -138,7 +136,7 @@ BACKENDS = {
}
```

Be sure to also run south migration
Be sure to also run migrations

### Elastic Search For Data and Search

Expand Down
3 changes: 1 addition & 2 deletions regcore/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
the associated backend class instead (e.g. for Django, elastic search, or
the splitter backend)."""

import sys
from importlib import import_module

from django.conf import settings
from django.utils.importlib import import_module


def _select(key):
Expand Down
7 changes: 4 additions & 3 deletions regcore/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.db import models
from django.db.models.fields.subclassing import Creator
from south.modelsinspector import add_introspection_rules


class PatchedSubFieldBase(type):
Expand Down Expand Up @@ -73,5 +72,7 @@ def __get__(self, instance, instance_type=None):
if instance is None:
return self


add_introspection_rules([], ["^regcore\.fields\.CompressedJSONField"])
def deconstruct(self):
name, path, args, kwargs = super(
CompressedJSONField, self).deconstruct()
return name, path, args, kwargs
233 changes: 91 additions & 142 deletions regcore/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,143 +1,92 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'Regulation'
db.create_table(u'regcore_regulation', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('version', self.gf('django.db.models.fields.SlugField')(max_length=20)),
('label_string', self.gf('django.db.models.fields.SlugField')(max_length=50)),
('text', self.gf('django.db.models.fields.TextField')()),
('title', self.gf('django.db.models.fields.TextField')(blank=True)),
('node_type', self.gf('django.db.models.fields.SlugField')(max_length=10)),
('children', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal(u'regcore', ['Regulation'])

# Adding unique constraint on 'Regulation', fields ['version', 'label_string']
db.create_unique(u'regcore_regulation', ['version', 'label_string'])

# Adding index on 'Regulation', fields ['version', 'label_string']
db.create_index(u'regcore_regulation', ['version', 'label_string'])

# Adding model 'Layer'
db.create_table(u'regcore_layer', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('version', self.gf('django.db.models.fields.SlugField')(max_length=20)),
('name', self.gf('django.db.models.fields.SlugField')(max_length=20)),
('label', self.gf('django.db.models.fields.SlugField')(max_length=50)),
('layer', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal(u'regcore', ['Layer'])

# Adding unique constraint on 'Layer', fields ['version', 'name', 'label']
db.create_unique(u'regcore_layer', ['version', 'name', 'label'])

# Adding index on 'Layer', fields ['version', 'name', 'label']
db.create_index(u'regcore_layer', ['version', 'name', 'label'])

# Adding model 'Notice'
db.create_table(u'regcore_notice', (
('document_number', self.gf('django.db.models.fields.SlugField')(max_length=20, primary_key=True)),
('effective_on', self.gf('django.db.models.fields.DateField')(null=True)),
('fr_url', self.gf('django.db.models.fields.CharField')(max_length=200)),
('publication_date', self.gf('django.db.models.fields.DateField')()),
('notice', self.gf('django.db.models.fields.TextField')()),
('cfr_part', self.gf('django.db.models.fields.SlugField')(max_length=10)),
))
db.send_create_signal(u'regcore', ['Notice'])

# Adding model 'Diff'
db.create_table(u'regcore_diff', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('label', self.gf('django.db.models.fields.SlugField')(max_length=50)),
('old_version', self.gf('django.db.models.fields.SlugField')(max_length=20)),
('new_version', self.gf('django.db.models.fields.SlugField')(max_length=20)),
('diff', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal(u'regcore', ['Diff'])

# Adding unique constraint on 'Diff', fields ['label', 'old_version', 'new_version']
db.create_unique(u'regcore_diff', ['label', 'old_version', 'new_version'])

# Adding index on 'Diff', fields ['label', 'old_version', 'new_version']
db.create_index(u'regcore_diff', ['label', 'old_version', 'new_version'])


def backwards(self, orm):
# Removing index on 'Diff', fields ['label', 'old_version', 'new_version']
db.delete_index(u'regcore_diff', ['label', 'old_version', 'new_version'])

# Removing unique constraint on 'Diff', fields ['label', 'old_version', 'new_version']
db.delete_unique(u'regcore_diff', ['label', 'old_version', 'new_version'])

# Removing index on 'Layer', fields ['version', 'name', 'label']
db.delete_index(u'regcore_layer', ['version', 'name', 'label'])

# Removing unique constraint on 'Layer', fields ['version', 'name', 'label']
db.delete_unique(u'regcore_layer', ['version', 'name', 'label'])

# Removing index on 'Regulation', fields ['version', 'label_string']
db.delete_index(u'regcore_regulation', ['version', 'label_string'])

# Removing unique constraint on 'Regulation', fields ['version', 'label_string']
db.delete_unique(u'regcore_regulation', ['version', 'label_string'])

# Deleting model 'Regulation'
db.delete_table(u'regcore_regulation')

# Deleting model 'Layer'
db.delete_table(u'regcore_layer')

# Deleting model 'Notice'
db.delete_table(u'regcore_notice')

# Deleting model 'Diff'
db.delete_table(u'regcore_diff')


models = {
u'regcore.diff': {
'Meta': {'unique_together': "(('label', 'old_version', 'new_version'),)", 'object_name': 'Diff', 'index_together': "(('label', 'old_version', 'new_version'),)"},
'diff': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'new_version': ('django.db.models.fields.SlugField', [], {'max_length': '20'}),
'old_version': ('django.db.models.fields.SlugField', [], {'max_length': '20'})
},
u'regcore.layer': {
'Meta': {'unique_together': "(('version', 'name', 'label'),)", 'object_name': 'Layer', 'index_together': "(('version', 'name', 'label'),)"},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'layer': ('django.db.models.fields.TextField', [], {}),
'name': ('django.db.models.fields.SlugField', [], {'max_length': '20'}),
'version': ('django.db.models.fields.SlugField', [], {'max_length': '20'})
},
u'regcore.notice': {
'Meta': {'object_name': 'Notice'},
'cfr_part': ('django.db.models.fields.SlugField', [], {'max_length': '10'}),
'document_number': ('django.db.models.fields.SlugField', [], {'max_length': '20', 'primary_key': 'True'}),
'effective_on': ('django.db.models.fields.DateField', [], {'null': 'True'}),
'fr_url': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
'notice': ('django.db.models.fields.TextField', [], {}),
'publication_date': ('django.db.models.fields.DateField', [], {})
},
u'regcore.regulation': {
'Meta': {'unique_together': "(('version', 'label_string'),)", 'object_name': 'Regulation', 'index_together': "(('version', 'label_string'),)"},
'children': ('django.db.models.fields.TextField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label_string': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'node_type': ('django.db.models.fields.SlugField', [], {'max_length': '10'}),
'text': ('django.db.models.fields.TextField', [], {}),
'title': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'version': ('django.db.models.fields.SlugField', [], {'max_length': '20'})
}
}

complete_apps = ['regcore']
from __future__ import unicode_literals

from django.db import models, migrations
import regcore.fields


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Diff',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('label', models.SlugField(max_length=200)),
('old_version', models.SlugField(max_length=20)),
('new_version', models.SlugField(max_length=20)),
('diff', regcore.fields.CompressedJSONField()),
],
),
migrations.CreateModel(
name='Layer',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('version', models.SlugField(max_length=20)),
('name', models.SlugField(max_length=20)),
('label', models.SlugField(max_length=200)),
('layer', regcore.fields.CompressedJSONField()),
],
),
migrations.CreateModel(
name='Notice',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('document_number', models.SlugField(max_length=20)),
('cfr_part', models.SlugField(max_length=200)),
('effective_on', models.DateField(null=True)),
('fr_url', models.CharField(max_length=200)),
('publication_date', models.DateField()),
('notice', regcore.fields.CompressedJSONField()),
],
),
migrations.CreateModel(
name='Regulation',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('version', models.SlugField(max_length=20)),
('label_string', models.SlugField(max_length=200)),
('text', models.TextField()),
('title', models.TextField(blank=True)),
('node_type', models.SlugField(max_length=10)),
('children', regcore.fields.CompressedJSONField()),
('root', models.BooleanField(default=False, db_index=True)),
('marker', models.CharField(default=b'', max_length=10)),
],
),
migrations.AlterUniqueTogether(
name='regulation',
unique_together=set([('version', 'label_string')]),
),
migrations.AlterIndexTogether(
name='regulation',
index_together=set([('version', 'label_string')]),
),
migrations.AlterUniqueTogether(
name='notice',
unique_together=set([('document_number', 'cfr_part')]),
),
migrations.AlterIndexTogether(
name='notice',
index_together=set([('document_number', 'cfr_part')]),
),
migrations.AlterUniqueTogether(
name='layer',
unique_together=set([('version', 'name', 'label')]),
),
migrations.AlterIndexTogether(
name='layer',
index_together=set([('version', 'name', 'label')]),
),
migrations.AlterUniqueTogether(
name='diff',
unique_together=set([('label', 'old_version', 'new_version')]),
),
migrations.AlterIndexTogether(
name='diff',
index_together=set([('label', 'old_version', 'new_version')]),
),
]

This file was deleted.

Loading

0 comments on commit 44008b6

Please sign in to comment.