diff --git a/legacy/migration.py b/legacy/migration.py index 83a43b7c4..097728896 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -11,19 +11,11 @@ from model_mommy import mommy from comissoes.models import Composicao, Participacao from parlamentares.models import Parlamentar +from sapl.utils import appconfs # BASE ###################################################################### -# this order is important for the migration -appconfs = [apps.get_app_config(n) for n in [ - 'parlamentares', - 'comissoes', - 'materia', - 'norma', - 'sessao', - 'lexml', - 'protocoloadm', ]] name_sets = [set(m.__name__ for m in ac.get_models()) for ac in appconfs] # apps do not overlap diff --git a/legacy/run_legacy_tests.sh b/legacy/run_legacy_tests.sh new file mode 100755 index 000000000..da8a79410 --- /dev/null +++ b/legacy/run_legacy_tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# All tests under this directory are excluded in default pytest.ini +# To run them use this script in this directory + +py.test --ds=sapl.legacy_migration_settings diff --git a/pytest.ini b/pytest.ini index 1f4c0d1df..3480351c1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,6 @@ [pytest] DJANGO_SETTINGS_MODULE=sapl.settings +norecursedirs = legacy # REUSING DATABASE BY DEFAULT (as a performance optimization) # http://pytest-django.readthedocs.org/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db diff --git a/requirements/migration-requirements.txt b/requirements/migration-requirements.txt new file mode 100644 index 000000000..25d226602 --- /dev/null +++ b/requirements/migration-requirements.txt @@ -0,0 +1,2 @@ +-r dev-requirements.txt +mysqlclient diff --git a/requirements/requirements.txt b/requirements/requirements.txt index fd1f5fbb9..d5004fd7d 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -3,7 +3,6 @@ django-admin-bootstrapped django-bootstrap3 django-braces django-crispy-forms -mysqlclient psycopg2 pytz PyYAML diff --git a/sapl/legacy_migration_settings.py b/sapl/legacy_migration_settings.py new file mode 100644 index 000000000..f90da1f9e --- /dev/null +++ b/sapl/legacy_migration_settings.py @@ -0,0 +1,18 @@ +# Settings for data migration from mysql legacy to new postgres database + +from .settings import * + +INSTALLED_APPS += ( + 'legacy', # legacy reversed model definitions +) + +DATABASES['legacy'] = { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'sapl25', + 'USER': 'root', + 'PASSWORD': 'admin', + 'HOST': 'localhost', # Or an IP Address that your DB is hosted on + 'PORT': '3306', +} + +DATABASE_ROUTERS = ['legacy.router.LegacyRouter', ] diff --git a/sapl/settings.py b/sapl/settings.py index 62f7a69c8..dde59ee01 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -39,9 +39,6 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', - # legacy reversed model definitions (temporary) - 'legacy', - # sapl modules 'base', 'parlamentares', @@ -89,7 +86,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'sapl.wsgi.application' - # Database # https://docs.djangoproject.com/en/1.8/ref/settings/#databases @@ -101,19 +97,9 @@ DATABASES = { 'PASSWORD': 'sapl', 'HOST': 'localhost', 'PORT': '5432', - }, - 'legacy': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'sapl25', - 'USER': 'root', - 'PASSWORD': 'admin', - 'HOST': 'localhost', # Or an IP Address that your DB is hosted on - 'PORT': '3306', } } -DATABASE_ROUTERS = ['legacy.router.LegacyRouter', ] - # Internationalization # https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'pt-br' diff --git a/sapl/test_general.py b/sapl/test_general.py index fc2331997..82492cfcc 100644 --- a/sapl/test_general.py +++ b/sapl/test_general.py @@ -1,7 +1,7 @@ import pytest from model_mommy import mommy -from legacy.migration import appconfs +from .utils import appconfs pytestmark = pytest.mark.django_db diff --git a/sapl/utils.py b/sapl/utils.py index 7039f6947..60a93f64f 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -2,6 +2,19 @@ from django.apps import apps from django.contrib import admin +# SAPL business apps +# This is a dependency order: each entry depends only on previous ones +# The order is important for migration code +appconfs = [apps.get_app_config(n) for n in [ + 'parlamentares', + 'comissoes', + 'materia', + 'norma', + 'sessao', + 'lexml', + 'protocoloadm', ]] + + def register_all_models_in_admin(module_name): appname = module_name.split('.')[0] app = apps.get_app_config(appname)