Commit cc83ffd3 authored by sim's avatar sim

[REFACT] Separate Django ORM models from other ones

parent 1a821b25
...@@ -12,21 +12,12 @@ if __name__ == "__main__": ...@@ -12,21 +12,12 @@ if __name__ == "__main__":
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
application = get_wsgi_application() application = get_wsgi_application()
# retrieve Django models
import django.apps
django_models = django.apps.apps.get_models()
django_models_names = set(model._meta.db_table for model in django_models)
# migrate SQLAlchemy models # migrate SQLAlchemy models
from gargantext.models import Base from gargantext.models import Base
from gargantext.util.db import engine from gargantext.util.db import engine
sqla_models_names = (
model for model in Base.metadata.tables.keys()
if model not in django_models_names
)
sqla_models = ( sqla_models = (
Base.metadata.tables[model_name] Base.metadata.tables[model_name]
for model_name in sqla_models_names for model_name in Base.metadata.tables.keys()
) )
print() print()
for model in sqla_models: for model in sqla_models:
......
...@@ -11,7 +11,13 @@ __all__ = ["Column", "ForeignKey", "UniqueConstraint", "relationship", ...@@ -11,7 +11,13 @@ __all__ = ["Column", "ForeignKey", "UniqueConstraint", "relationship",
"TypeDecorator", "TypeDecorator",
"JSONB", "Double", "JSONB", "Double",
"MutableDict", "MutableList", "MutableDict", "MutableList",
"Base"] "Base", "DjangoBase"]
# All the models should derive from this base class, so Base.metadata keeps
# all tables handled by Alembic migration scripts.
Base = declarative_base() Base = declarative_base()
# To be used by tables already handled by Django ORM, such as User model. We
# separate them in order to keep those out of Alembic sight.
DjangoBase = declarative_base()
...@@ -3,12 +3,12 @@ from gargantext.util.db import session, aliased ...@@ -3,12 +3,12 @@ from gargantext.util.db import session, aliased
from datetime import datetime from datetime import datetime
from .base import Base, Column, ForeignKey, UniqueConstraint, \ from .base import DjangoBase, Base, Column, ForeignKey, UniqueConstraint, \
Integer, Boolean, DateTime, String Integer, Boolean, DateTime, String
__all__ = ['User', 'Contact'] __all__ = ['User', 'Contact']
class User(Base): class User(DjangoBase):
# The properties below are a reflection of Django's auth module's models. # The properties below are a reflection of Django's auth module's models.
__tablename__ = models.User._meta.db_table __tablename__ = models.User._meta.db_table
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment