From 56d46c533ee6560798964b17cf24498d53b2143b Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Sat, 19 Oct 2013 22:28:46 -0400 Subject: [PATCH] Midstream --- alembic.ini | 49 ++++++++++ alembic/README | 1 + alembic/env.py | 71 ++++++++++++++ alembic/env.pyc | Bin 0 -> 1754 bytes alembic/script.py.mako | 22 +++++ .../58f6a99bd6ec_create_fda_product_t.py | 91 ++++++++++++++++++ .../58f6a99bd6ec_create_fda_product_t.py~ | 22 +++++ puppet/mercy/manifests/#init.pp# | 31 ++++++ puppet/mercy/manifests/init.pp | 22 +++++ puppet/mercy/manifests/params.pp | 4 + puppet/mercy/manifests/params.pp~ | 23 +++++ puppet/mercy/templates/apache/vhost.erb | 12 +++ puppet/mercy/templates/apache/vhost.erb~ | 12 +++ puppet/mercy/templates/python/alembic.ini.erb | 49 ++++++++++ .../mercy/templates/python/alembic.ini.erb~ | 49 ++++++++++ scripts/mercy.wsgi | 14 +++ 16 files changed, 472 insertions(+) create mode 100644 alembic.ini create mode 100644 alembic/README create mode 100644 alembic/env.py create mode 100644 alembic/env.pyc create mode 100644 alembic/script.py.mako create mode 100644 alembic/versions/58f6a99bd6ec_create_fda_product_t.py create mode 100644 alembic/versions/58f6a99bd6ec_create_fda_product_t.py~ create mode 100644 puppet/mercy/manifests/#init.pp# create mode 100644 puppet/mercy/manifests/init.pp create mode 100644 puppet/mercy/manifests/params.pp create mode 100644 puppet/mercy/manifests/params.pp~ create mode 100644 puppet/mercy/templates/apache/vhost.erb create mode 100644 puppet/mercy/templates/apache/vhost.erb~ create mode 100644 puppet/mercy/templates/python/alembic.ini.erb create mode 100644 puppet/mercy/templates/python/alembic.ini.erb~ create mode 100644 scripts/mercy.wsgi diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 0000000..f15b1d7 --- /dev/null +++ b/alembic.ini @@ -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 diff --git a/alembic/README b/alembic/README new file mode 100644 index 0000000..98e4f9c --- /dev/null +++ b/alembic/README @@ -0,0 +1 @@ +Generic single-database configuration. \ No newline at end of file diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 0000000..f72400b --- /dev/null +++ b/alembic/env.py @@ -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() + diff --git a/alembic/env.pyc b/alembic/env.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5068e060ba89c8a16dbcaa461391fd155dc0a857 GIT binary patch literal 1754 zcmaKsUymC#5WvT~`QPL&oS-Ui?$a#-x|W1{?v7p`5^5wl##+ z6pB9l1hASxF$j|*;N8dY7NGeBaK;m1hk!?6Mu*Om5k;o|q)#Gf=8tH&)_$8guRK<0 zeWxFiKCi9E8=vs4{0R+cH`-#hZt5zd#kJn}9;tVAZMstvlGfVbSy&8dVK069oxP#7 zJfVpPC)JZ0tvs#QYeONP%Bn7KF_}pEe6!U~cHy=SI_bB_B417N)n(Z_FO~c@{W|Pdwve_a zjg?=93x7gK>UOg|Xe3!wd5$};E)9lLTWnA&C$G_%g_KWkrTbp*cG_-&!_Jb-8w}Bg zBiAU4+MareS7@b0EGUXEo__xPne?^1By(3v8}_ij$(b^S;;-+*U*HYqt;gge8Qf!~ zeekx?Y|;59xUX3kJi5HmJ1^_j?^?e%>KFm{gHa~mVs*P{8{=bA(f=|TaKU)km;0Ee z8}wPFw9V=rCq4}vjqmqRj{SQiT_VAf`9@i%a^4tNYg(HfY8I$T8IOd1-4NnY2CGY* ze~0#JvAgvTY4M*YvwfvMq!q_Z!}M6pqnXHg&ct%m0XhPUq4NUDD2y?qM*tFZ1Qa1$ z5@RAF7-?%cVBTH}@Ixp^Q1svx?d*delRgqZJ`M}ig?mD2*8>*BOKQRw7d+B|avF3O zB%LSROYUbH-UY1v53kQG)r$agIa<}|nvm+?;KDOM1jZej_rNOW>Rg94ro&=LdB^wP zfZx|VlyukNTHm+_9NnS(bkDA%b3-;gcl5!Y=lXlq1O(8lLV2}JW~59x$1l7_gUf>G_$J0@VYK*i(L{pu_?DgD1&x) vJ&^HZcer_&y{n5jouAU)*5GH{w2p1f#auiT^WL~O8w`fylkuaem_&a8_!gl$ literal 0 HcmV?d00001 diff --git a/alembic/script.py.mako b/alembic/script.py.mako new file mode 100644 index 0000000..9570201 --- /dev/null +++ b/alembic/script.py.mako @@ -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"} diff --git a/alembic/versions/58f6a99bd6ec_create_fda_product_t.py b/alembic/versions/58f6a99bd6ec_create_fda_product_t.py new file mode 100644 index 0000000..22f88ee --- /dev/null +++ b/alembic/versions/58f6a99bd6ec_create_fda_product_t.py @@ -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 diff --git a/alembic/versions/58f6a99bd6ec_create_fda_product_t.py~ b/alembic/versions/58f6a99bd6ec_create_fda_product_t.py~ new file mode 100644 index 0000000..161b8c3 --- /dev/null +++ b/alembic/versions/58f6a99bd6ec_create_fda_product_t.py~ @@ -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 diff --git a/puppet/mercy/manifests/#init.pp# b/puppet/mercy/manifests/#init.pp# new file mode 100644 index 0000000..28a67ba --- /dev/null +++ b/puppet/mercy/manifests/#init.pp# @@ -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' + } + } +} diff --git a/puppet/mercy/manifests/init.pp b/puppet/mercy/manifests/init.pp new file mode 100644 index 0000000..fae1c76 --- /dev/null +++ b/puppet/mercy/manifests/init.pp @@ -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' +} diff --git a/puppet/mercy/manifests/params.pp b/puppet/mercy/manifests/params.pp new file mode 100644 index 0000000..03c6d0e --- /dev/null +++ b/puppet/mercy/manifests/params.pp @@ -0,0 +1,4 @@ +class mercy::params +{ + +} diff --git a/puppet/mercy/manifests/params.pp~ b/puppet/mercy/manifests/params.pp~ new file mode 100644 index 0000000..3f9e754 --- /dev/null +++ b/puppet/mercy/manifests/params.pp~ @@ -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' + ) +{ + +} diff --git a/puppet/mercy/templates/apache/vhost.erb b/puppet/mercy/templates/apache/vhost.erb new file mode 100644 index 0000000..a47ec70 --- /dev/null +++ b/puppet/mercy/templates/apache/vhost.erb @@ -0,0 +1,12 @@ +> + 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 + + + WSGIProcessGroup mercy + WSGIApplicationGroup %{GLOBAL} + Order deny, allow + Allow from all + + \ No newline at end of file diff --git a/puppet/mercy/templates/apache/vhost.erb~ b/puppet/mercy/templates/apache/vhost.erb~ new file mode 100644 index 0000000..ad3bc5f --- /dev/null +++ b/puppet/mercy/templates/apache/vhost.erb~ @@ -0,0 +1,12 @@ +> + 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 + + + WSGIProcessGroup mercy + WSGIApplicationGroup %{GLOBAL} + Order deny, allow + Allow from all + + \ No newline at end of file diff --git a/puppet/mercy/templates/python/alembic.ini.erb b/puppet/mercy/templates/python/alembic.ini.erb new file mode 100644 index 0000000..dafb558 --- /dev/null +++ b/puppet/mercy/templates/python/alembic.ini.erb @@ -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 diff --git a/puppet/mercy/templates/python/alembic.ini.erb~ b/puppet/mercy/templates/python/alembic.ini.erb~ new file mode 100644 index 0000000..88a9e8a --- /dev/null +++ b/puppet/mercy/templates/python/alembic.ini.erb~ @@ -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 diff --git a/scripts/mercy.wsgi b/scripts/mercy.wsgi new file mode 100644 index 0000000..7348088 --- /dev/null +++ b/scripts/mercy.wsgi @@ -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()