Skip to content

Commit

Permalink
closes clld/wals-data#58, closes clld/wals-data#57, closes clld/wals-…
Browse files Browse the repository at this point in the history
…data#56, closes clld/wals-data#55, closes clld/wals-data#51
  • Loading branch information
xrotwang committed Oct 9, 2015
1 parent cbd1fc1 commit 7b4ce7e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
47 changes: 47 additions & 0 deletions migrations/versions/13b08c8d306b_fix_glottocodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# coding=utf-8
"""fix glottocodes
Revision ID: 13b08c8d306b
Revises: 42f4c3147ade
Create Date: 2015-10-09 10:54:19.096927
"""
from __future__ import unicode_literals

# revision identifiers, used by Alembic.
revision = '13b08c8d306b'
down_revision = u'42f4c3147ade'

import datetime

from alembic import op
import sqlalchemy as sa

from clld.db.models import common
from wals3.migration import Connection


def upgrade():
conn = Connection(op.get_bind())

# https://github.com/clld/wals-data/issues/58
conn.update_glottocode('uhi', 'atam1239')

# https://github.com/clld/wals-data/issues/57
conn.update_glottocode('mdm', 'west2443')
conn.update_glottocode('wem', 'west2443')

# https://github.com/clld/wals-data/issues/56
conn.update_glottocode('wdo', 'pitj1243')

# https://github.com/clld/wals-data/issues/55
conn.update_glottocode('wir', 'wira1265')

# https://github.com/clld/wals-data/issues/51
lpk = conn.pk(common.Language, 'gno')
ipk = conn.insert(common.Identifier, name='Kotiria', description='other', type='name')
conn.insert(common.LanguageIdentifier, identifier_pk=ipk, language_pk=lpk)


def downgrade():
pass
15 changes: 15 additions & 0 deletions wals3/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def insert_if_missing(self, model, where, values=None):
values.update(where)
return self.insert(model, **values)

def update_glottocode(self, lid, gc):
lpk = self.pk(Language, lid)

for li in self.select(LanguageIdentifier, language_pk=lpk):
i = self.get(Identifier, li.identifier_pk)
if i.type == 'glottolog':
self.update(Identifier, dict(name=gc), pk=i.pk)
break
else:
ipk = self.insert_if_missing(
Identifier,
dict(id=gc),
dict(name=gc, description=gc, type='glottolog'))
self.insert(LanguageIdentifier, identifier_pk=ipk, language_pk=lpk)

def update_iso(self, lid, *obsolete, **new): # pragma: no cover
lpk = self.pk(Language, lid)

Expand Down

0 comments on commit 7b4ce7e

Please sign in to comment.