Midstream

This commit is contained in:
2013-10-19 22:28:46 -04:00
parent 86e8db6c43
commit 56d46c533e
16 changed files with 472 additions and 0 deletions

49
alembic.ini Normal file
View File

@@ -0,0 +1,49 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
script_location = alembic
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
sqlalchemy.url = postgresql://mercy:mercy@postgresql.aklabs.net/mercy
# 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

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,
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, ForeignKey('fda_products.id'), nullable=True),
sa.Column('wikipedia', sa.String, nullable=True)
)
op.create_table(
'drugbank_prices',
sa.Column('id', sa.String, 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, ForeignKey('drugbank_drugs.id'), nullable=False),
sa.Column('category_id', sa.Integer, ForeignKey('drugbank_categories.id'), nullable=False)
)
op.create_table(
'drugbank_packagers',
sa.Column('id', sa.String, 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, 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, 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, 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

View File

@@ -0,0 +1,31 @@
class mercy(
$environment,
$version,
$ensure,
$rabbitmq_uri,
$process_user => 'mercy',
$process_group => 'mercy',
$process_threads => 5,
$servername => $::fqdn,
$rabbitmq_user => 'mercy',
$rabbitmq_pw => 'mercy',
$rabbitmq_vhost => 'mercy',
$vhost_dir => '/etc/apache/httpd/conf.d',
$apache_service => 'httpd',
$port => 443,
$postgres_uri => 'localhost',
$postgres_user => 'mercy',
$postgres_pw => 'mercy',
$postgres_db => 'mercy')
{
if ! defined(User[$process_user]) {
user { $process_user:
ensure => 'present'
}
}
if ! defined(Group[$process_group]) {
user { $process_group:
ensure => 'present'
}
}
}

View File

@@ -0,0 +1,22 @@
class mercy(
$environment,
$version,
$ensure,
$rabbitmq_uri,
$process_user => 'mercy',
$process_group => 'mercy',
$process_threads => 5,
$servername => $::fqdn,
$rabbitmq_user => 'mercy',
$rabbitmq_pw => 'mercy',
$rabbitmq_vhost => 'mercy',
$vhost_dir => '/etc/apache/httpd/conf.d',
$apache_service => 'httpd',
$port => 443,
$postgres_uri => 'localhost',
$postgres_user => 'mercy',
$postgres_pw => 'mercy',
$postgres_db => 'mercy')
{
include 'mercy::params'
}

View File

@@ -0,0 +1,4 @@
class mercy::params
{
}

View File

@@ -0,0 +1,23 @@
class mercy::params ( $environment,
$version,
$ensure,
$rabbitmq_uri,
# ---- Everything below is optional
$process_user => 'mercy',
$process_group => 'mercy',
$process_threads => 5,
$servername => $::fqdn,
$rabbitmq_user => 'mercy',
$rabbitmq_pw => 'mercy',
$rabbitmq_vhost => 'mercy',
$vhost_dir => '/etc/apache/httpd/conf.d',
$apache_service => 'httpd',
$port => 443,
$postgres_uri => 'localhost',
$postgres_user => 'mercy',
$postgres_pw => 'mercy',
$postgres_db => 'mercy'
)
{
}

View File

@@ -0,0 +1,12 @@
<VirtualHost * :<%= scope.lookupvar('::mercy::port') %>>
ServerName <%= scope.lookupvar('::fqdn') %>
WSGIDaemonProcess mercy user=<%= scope.lookupvar('::mercy::process_user') %> group=<%= scope.lookupvar('::mercy::process_group') %> threads=<%= scope.lookupvar('::mercy::process_threads') %>
WSGIScriptAlias / /opt/mercy/scripts/mercy.wsgi
<Directory /opt/mercy>
WSGIProcessGroup mercy
WSGIApplicationGroup %{GLOBAL}
Order deny, allow
Allow from all
</Directory>
</VirtualHost>

View File

@@ -0,0 +1,12 @@
<VirtualHost *:<%= scope.lookupvar('::mercy::params::port') %>>
ServerName <%= scope.lookupvar('::fqdn') %>
WSGIDaemonProcess mercy user=<%= scope.lookupvar('::mercy::params::process_user') %> group=<%= scope.lookupvar('::mercy::params::process_group') %> threads=<%= scope.lookupvar('::mercy::params::process_threads') %>
WSGIScriptAlias / /opt/mercy/scripts/mercy.wsgi
<Directory /opt/mercy>
WSGIProcessGroup mercy
WSGIApplicationGroup %{GLOBAL}
Order deny, allow
Allow from all
</Directory>
</VirtualHost>

View File

@@ -0,0 +1,49 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
script_location = /opt/mercy/alembic
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
sqlalchemy.url = postgresql://<%= scope.lookupvar('::mercy::postgres_user') %>:<%+ scope.lookupvar('::mercy::postgres_pw') %>@<%= scope.lookupvar('::mercy::postgres_uri') %>/<%= scope.lookupvar('::mercy::postgres_db') %>
# 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

View File

@@ -0,0 +1,49 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
script_location = alembic
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
sqlalchemy.url = driver://mercy:mercy@postgresql.aklabs.net/mercy
# 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

14
scripts/mercy.wsgi Normal file
View File

@@ -0,0 +1,14 @@
from mercy.MercyApplication import MercyApplication
class ScriptNameStripper(object):
def __init__(self, app):
self.app = app
def __call_(self, environ, start_response):
environ['SCRIPT_NAME'] = ''
return self.app(environ, start_response)
app = ScriptNameStripper(MercyApplication())
if __name__ == "__main__":
app.run()