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
f952ec3a
Commit
f952ec3a
authored
Jul 05, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADMIN] Configure Alembic for Gargantext
parent
1fc4719d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
4 deletions
+39
-4
alembic.ini
alembic.ini
+4
-1
env.py
alembic/env.py
+34
-3
script.py.mako
alembic/script.py.mako
+1
-0
No files found.
alembic.ini
View file @
f952ec3a
...
@@ -35,8 +35,11 @@ script_location = alembic
...
@@ -35,8 +35,11 @@ script_location = alembic
# are written from script.py.mako
# are written from script.py.mako
# output_encoding = utf-8
# output_encoding = utf-8
sqlalchemy.url
=
driver://user:pass@localhost/dbname
# XXX For database access configuration, see alembic/env.py
#sqlalchemy.url = driver://user:pass@localhost/dbname
[alembic:exclude]
tables
=
django_* celery_* djcelery_* auth_*
# Logging configuration
# Logging configuration
[loggers]
[loggers]
...
...
alembic/env.py
View file @
f952ec3a
...
@@ -2,10 +2,23 @@ from __future__ import with_statement
...
@@ -2,10 +2,23 @@ from __future__ import with_statement
from
alembic
import
context
from
alembic
import
context
from
sqlalchemy
import
engine_from_config
,
pool
from
sqlalchemy
import
engine_from_config
,
pool
from
logging.config
import
fileConfig
from
logging.config
import
fileConfig
import
re
# Add projet root directory in path and setup Django...
import
os
import
django
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'gargantext.settings'
)
django
.
setup
()
# ...to be able to import gargantext.
from
gargantext
import
settings
,
models
# this is the Alembic Config object, which provides
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
# access to the values within the .ini file in use.
config
=
context
.
config
config
=
context
.
config
config
.
set_main_option
(
"sqlalchemy.url"
,
settings
.
DATABASES
[
'default'
][
'URL'
])
# Interpret the config file for Python logging.
# Interpret the config file for Python logging.
# This line sets up loggers basically.
# This line sets up loggers basically.
...
@@ -15,7 +28,7 @@ fileConfig(config.config_file_name)
...
@@ -15,7 +28,7 @@ fileConfig(config.config_file_name)
# for 'autogenerate' support
# for 'autogenerate' support
# from myapp import mymodel
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = mymodel.Base.metadata
target_metadata
=
None
target_metadata
=
models
.
Base
.
metadata
# other values from the config, defined by the needs of env.py,
# other values from the config, defined by the needs of env.py,
# can be acquired:
# can be acquired:
...
@@ -23,6 +36,22 @@ target_metadata = None
...
@@ -23,6 +36,22 @@ target_metadata = None
# ... etc.
# ... etc.
# Inspired from https://gist.github.com/utek/6163250
def
exclude_tables_from_config
(
config
):
tables
=
config
.
get
(
"tables"
,
''
)
.
replace
(
'*'
,
'.*'
)
.
split
(
' '
)
pattern
=
'|'
.
join
(
tables
)
return
re
.
compile
(
pattern
)
exclude_tables
=
exclude_tables_from_config
(
config
.
get_section
(
'alembic:exclude'
))
def
include_object
(
obj
,
name
,
typ
,
reflected
,
compare_to
):
if
typ
==
"table"
and
exclude_tables
.
match
(
name
):
return
False
else
:
return
True
def
run_migrations_offline
():
def
run_migrations_offline
():
"""Run migrations in 'offline' mode.
"""Run migrations in 'offline' mode.
...
@@ -37,7 +66,8 @@ def run_migrations_offline():
...
@@ -37,7 +66,8 @@ def run_migrations_offline():
"""
"""
url
=
config
.
get_main_option
(
"sqlalchemy.url"
)
url
=
config
.
get_main_option
(
"sqlalchemy.url"
)
context
.
configure
(
context
.
configure
(
url
=
url
,
target_metadata
=
target_metadata
,
literal_binds
=
True
)
url
=
url
,
target_metadata
=
target_metadata
,
literal_binds
=
True
,
include_object
=
include_object
)
with
context
.
begin_transaction
():
with
context
.
begin_transaction
():
context
.
run_migrations
()
context
.
run_migrations
()
...
@@ -58,7 +88,8 @@ def run_migrations_online():
...
@@ -58,7 +88,8 @@ def run_migrations_online():
with
connectable
.
connect
()
as
connection
:
with
connectable
.
connect
()
as
connection
:
context
.
configure
(
context
.
configure
(
connection
=
connection
,
connection
=
connection
,
target_metadata
=
target_metadata
target_metadata
=
target_metadata
,
include_object
=
include_object
)
)
with
context
.
begin_transaction
():
with
context
.
begin_transaction
():
...
...
alembic/script.py.mako
View file @
f952ec3a
...
@@ -7,6 +7,7 @@ Create Date: ${create_date}
...
@@ -7,6 +7,7 @@ Create Date: ${create_date}
"""
"""
from alembic import op
from alembic import op
import sqlalchemy as sa
import sqlalchemy as sa
import gargantext
${imports if imports else ""}
${imports if imports else ""}
# revision identifiers, used by Alembic.
# revision identifiers, used by Alembic.
...
...
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