From a95dda095c0b7050f06cba601cd285b6083c514a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 13:54:56 +0000 Subject: [PATCH 1/7] Add the alembic folder to store the alembic migration files --- 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..712b616 --- /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, target_metadata=target_metadata) + + 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/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"} From 3be7d6278e298bec0e95a3cda42624117338cd58 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 13:57:18 +0000 Subject: [PATCH 2/7] Ignore the .pyo files as well --- diff --git a/.gitignore b/.gitignore index 1071d13..c697722 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ requests/ dist/ build/ *.pyc +*.pyo *.swp *.egg-info *.conf From 39975d41c1a05580e0c3f3091b40542a5c60e8e8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 13:57:56 +0000 Subject: [PATCH 3/7] Add the alembic.ini file to the files folder --- diff --git a/files/alembic.ini b/files/alembic.ini new file mode 100644 index 0000000..a519090 --- /dev/null +++ b/files/alembic.ini @@ -0,0 +1,60 @@ +# 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 + +# max length of characters to apply to the +# "slug" field +#truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +#sqlalchemy.url = driver://user:pass@localhost/dbname +sqlalchemy.url = sqlite:////var/tmp/pagure_dev.sqlite + + +# 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 From ac2043f526d02e5aa36559eb7b113e9301b3b5a2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 14:00:32 +0000 Subject: [PATCH 4/7] Include the alembic folder in the sources when making a release --- diff --git a/MANIFEST.in b/MANIFEST.in index 80b15c4..8ccc23c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,3 +5,4 @@ recursive-include files * recursive-include milters * recursive-include tests * recursive-include doc * +recursive-include alembic * From 907dd1405838908beb66f73be0c99eb3431619e4 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 14:00:43 +0000 Subject: [PATCH 5/7] Install the alembic configuration file and revisions via the spec file --- diff --git a/files/pagure.spec b/files/pagure.spec index 2fdd02f..e20263b 100644 --- a/files/pagure.spec +++ b/files/pagure.spec @@ -122,6 +122,12 @@ install -m 644 files/pagure.wsgi $RPM_BUILD_ROOT/%{_datadir}/pagure/pagure.wsgi # Install the createdb script install -m 644 createdb.py $RPM_BUILD_ROOT/%{_datadir}/pagure/pagure_createdb.py +# Install the alembic configuration file +install -m 644 files/alembic.ini $RPM_BUILD_ROOT/%{_sysconfdir}/pagure/alembic.ini + +# Install the alembic revisions +cp alembic $RPM_BUILD_ROOT/%{_datadir}/pagure + # Install the milter files mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/run/pagure @@ -150,6 +156,7 @@ install -m 644 milters/comment_email_milter.py \ %license LICENSE %config(noreplace) %{_sysconfdir}/httpd/conf.d/pagure.conf %config(noreplace) %{_sysconfdir}/pagure/pagure.cfg +%config(noreplace) %{_sysconfdir}/pagure/alembic.ini %dir %{_sysconfdir}/pagure/ %dir %{_datadir}/pagure/ %{_datadir}/pagure/pagure* From 6c551c0d8baa30eaa13b956f0dfe87a108133e58 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 14:01:44 +0000 Subject: [PATCH 6/7] Adjust the default location of the alembic revisions in the configuration --- diff --git a/files/alembic.ini b/files/alembic.ini index a519090..e0dc1d2 100644 --- a/files/alembic.ini +++ b/files/alembic.ini @@ -2,7 +2,7 @@ [alembic] # path to migration scripts -script_location = alembic +script_location = /usr/share/pagure/alembic # template used to generate migration files # file_template = %%(rev)s_%%(slug)s From 6f23c3c1e100c7c7a018864c87b29bb757d9b901 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 02 2015 14:27:51 +0000 Subject: [PATCH 7/7] Drop the README from alembic --- diff --git a/alembic/README b/alembic/README deleted file mode 100644 index 98e4f9c..0000000 --- a/alembic/README +++ /dev/null @@ -1 +0,0 @@ -Generic single-database configuration. \ No newline at end of file