Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
cc83ffd3
Commit
cc83ffd3
authored
Jul 05, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACT] Separate Django ORM models from other ones
parent
1a821b25
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
13 deletions
+10
-13
dbmigrate.py
dbmigrate.py
+1
-10
base.py
gargantext/models/base.py
+7
-1
users.py
gargantext/models/users.py
+2
-2
No files found.
dbmigrate.py
View file @
cc83ffd3
...
...
@@ -12,21 +12,12 @@ if __name__ == "__main__":
from
django.core.wsgi
import
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
from
gargantext.models
import
Base
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
=
(
Base
.
metadata
.
tables
[
model_name
]
for
model_name
in
sqla_models_names
for
model_name
in
Base
.
metadata
.
tables
.
keys
()
)
print
()
for
model
in
sqla_models
:
...
...
gargantext/models/base.py
View file @
cc83ffd3
...
...
@@ -11,7 +11,13 @@ __all__ = ["Column", "ForeignKey", "UniqueConstraint", "relationship",
"TypeDecorator"
,
"JSONB"
,
"Double"
,
"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
()
# 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
()
gargantext/models/users.py
View file @
cc83ffd3
...
...
@@ -3,12 +3,12 @@ from gargantext.util.db import session, aliased
from
datetime
import
datetime
from
.base
import
Base
,
Column
,
ForeignKey
,
UniqueConstraint
,
\
from
.base
import
DjangoBase
,
Base
,
Column
,
ForeignKey
,
UniqueConstraint
,
\
Integer
,
Boolean
,
DateTime
,
String
__all__
=
[
'User'
,
'Contact'
]
class
User
(
Base
):
class
User
(
Django
Base
):
# The properties below are a reflection of Django's auth module's models.
__tablename__
=
models
.
User
.
_meta
.
db_table
id
=
Column
(
Integer
,
primary_key
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment