Working on #6. I think I should break out the puppet module stuff into a

separate issue, since that risks really putting this all off target.
This commit is contained in:
2013-10-19 22:28:46 -04:00
parent 86e8db6c43
commit dbf64e8035
19 changed files with 517 additions and 16 deletions

1
alembic/README Normal file
View File

@@ -0,0 +1 @@
Generic single-database configuration.

71
alembic/env.py Normal file
View File

@@ -0,0 +1,71 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = None
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

BIN
alembic/env.pyc Normal file

Binary file not shown.

22
alembic/script.py.mako Normal file
View File

@@ -0,0 +1,22 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision}
Create Date: ${create_date}
"""
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,91 @@
"""create fda_product table
Revision ID: 58f6a99bd6ec
Revises: None
Create Date: 2013-10-19 21:21:03.977000
"""
# revision identifiers, used by Alembic.
revision = '58f6a99bd6ec'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table(
'fda_products',
sa.Column('id', sa.String, primary_key=True),
sa.Column('ndc', sa.String, nullable=False),
sa.Column('type', sa.String, nullable=False),
sa.Column('proprietaryName', sa.String, nullable=False, index=True),
sa.Column('proprietaryNameSuffix', sa.String),
sa.Column('genericName', sa.String, nullable=False),
sa.Column('marketingCategoryName', sa.String, nullable=False),
sa.Column('labelerName', sa.String, nullable=False),
sa.Column('deaSchedule', sa.String, nullable=False)
)
op.create_table(
'fda_product_substances',
sa.Column('fda_product_id',
sa.String,
sa.ForeignKey('fda_products.id'),
nullable=False),
sa.Column('substanceName', sa.String, nullable=False),
sa.Column('strengthNumber', sa.String, nullable=False),
sa.Column('strengthUnit', sa.String, nullable=False),
sa.Column('pharmaClasses', sa.String, nullable=False)
)
op.create_table(
'drugbank_drugs',
sa.Column('id', sa.String, primary_key=True, unique=True),
sa.Column('name', sa.String, nullable=False, index=True),
sa.Column('indication', sa.String, nullable=False),
sa.Column('ndc_id', sa.String, sa.ForeignKey('fda_products.id'), nullable=True),
sa.Column('wikipedia', sa.String, nullable=True)
)
op.create_table(
'drugbank_prices',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('description', sa.String, nullable=False),
sa.Column('currency', sa.String, nullable=False),
sa.Column('cost', sa.Float, nullable=False, index=True),
sa.Column('unit', sa.String, nullable=False)
)
op.create_table(
'drugbank_categories',
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
sa.Column('name', sa.String, nullable=False)
)
op.create_table(
'drugbank_drug_categories',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('category_id', sa.Integer, sa.ForeignKey('drugbank_categories.id'), nullable=False)
)
op.create_table(
'drugbank_packagers',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('name', sa.String, nullable=False),
sa.Column('url', sa.String, nullable=False)
)
op.create_table(
'drugbank_manufacturers',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('name', sa.String, nullable=False),
sa.Column('generic', sa.Boolean, nullable=False)
)
op.create_table(
'drugbank_genericnames',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('name', sa.String, index=True, nullable=False)
)
op.create_table(
'drugbank_synonyms',
sa.Column('id', sa.String, sa.ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('name', sa.String, index=True, nullable=False)
)
def downgrade():
pass

View File

@@ -0,0 +1,22 @@
"""create fda_product table
Revision ID: 58f6a99bd6ec
Revises: None
Create Date: 2013-10-19 21:21:03.977000
"""
# revision identifiers, used by Alembic.
revision = '58f6a99bd6ec'
down_revision = None
from alembic import op
import sqlalchemy as sa
def upgrade():
pass
def downgrade():
pass