-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from dimagi/sk/alembic
switch to using alembic for migrations
- Loading branch information
Showing
27 changed files
with
495 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
dist: precise # https://github.com/travis-ci/travis-ci/issues/8331 | ||
language: python | ||
sudo: required | ||
python: | ||
- "2.7" | ||
- "3.6" | ||
env: | ||
global: | ||
- MSSQL_SA_PASSWORD=Password@123 | ||
before_install: | ||
- docker pull microsoft/mssql-server-linux:2017-latest | ||
- docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=$MSSQL_SA_PASSWORD" -p 1433:1433 --name mssql1 -d microsoft/mssql-server-linux:2017-latest | ||
- curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - | ||
- echo "deb [arch=amd64] https://packages.microsoft.com/ubuntu/14.04/prod trusty main" | sudo tee /etc/apt/sources.list.d/mssql-release.list | ||
- sudo apt-get update -qq | ||
install: | ||
- pip install -e . | ||
- pip install pymysql psycopg2 | ||
- pip install pymysql psycopg2 pyodbc | ||
- pip install coverage coveralls | ||
- sudo ACCEPT_EULA=Y apt-get install msodbcsql17 | ||
before_script: | ||
- mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'travis'@'%';"; | ||
- docker ps -a | ||
- odbcinst -q -d | ||
- .travis/wait.sh | ||
script: coverage run setup.py test | ||
after_success: | ||
- coveralls | ||
services: | ||
- postgres | ||
- mysql | ||
- docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
echo "Waiting MSSQL docker to launch on 1433..." | ||
|
||
while ! nc -z localhost 1433; do | ||
sleep 0.1 | ||
done | ||
|
||
echo "MSSQL launched" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
recursive-include migrations *.py *.cfg | ||
recursive-include migrations *.py *.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Migrations | ||
|
||
Migrations use [alembic](http://alembic.zzzcomputing.com/en/latest). | ||
|
||
**Create new migration** | ||
|
||
``` | ||
$ alembic -c migrations/alembic.ini revision -m "description" | ||
``` | ||
|
||
|
||
**Run migrations from command line** | ||
|
||
``` | ||
$ alembic -c migrations/alembic.ini -x "url=<db url>" upgrade <version e.g. 'head'> | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[alembic] | ||
script_location = migrations | ||
|
||
# Logging configuration | ||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import with_statement | ||
from alembic import context | ||
from sqlalchemy import engine_from_config, pool | ||
from logging.config import fileConfig | ||
from sqlalchemy import create_engine | ||
|
||
config = context.config | ||
fileConfig(config.config_file_name) | ||
target_metadata = None | ||
|
||
|
||
def run_migrations_online(): | ||
connectable = config.attributes.get('connection', None) | ||
|
||
if connectable is None: | ||
cmd_line_url = context.get_x_argument(as_dictionary=True).get('url') | ||
if cmd_line_url: | ||
connectable = create_engine(cmd_line_url) | ||
else: | ||
raise Exception("No connection URL. Use '-x url=<url>'") | ||
|
||
with connectable.connect() as connection: | ||
context.configure( | ||
connection=connection, | ||
target_metadata=target_metadata | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
|
||
run_migrations_online() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
|
||
def upgrade(): | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade(): | ||
${downgrades if downgrades else "pass"} |
Oops, something went wrong.