{"id":4761,"date":"2013-05-17T12:44:46","date_gmt":"2013-05-17T20:44:46","guid":{"rendered":"http:\/\/www.chesnok.com\/daily\/?p=4761"},"modified":"2013-05-17T12:44:46","modified_gmt":"2013-05-17T20:44:46","slug":"migrations-with-alembic-a-lightspeed-tour","status":"publish","type":"post","link":"https:\/\/www.chesnok.com\/daily\/2013\/05\/17\/migrations-with-alembic-a-lightspeed-tour\/","title":{"rendered":"Migrations with Alembic: a lightspeed tour"},"content":{"rendered":"<p>I&#8217;ve got a <a href=\"https:\/\/wiki.mozilla.org\/Webdev\/Beer_And_Tell\/May2013\">Beer &amp; Tell<\/a> to give about <a href=\"https:\/\/alembic.readthedocs.org\/en\/latest\/\">alembic<\/a>. Alembic is a migration tool that works with SQLAlchemy. I&#8217;m using it for database migrations with PostgreSQL.<\/p>\n<p>So, here&#8217;s what I want to say today:<\/p>\n<ul>\n<li>Written by SQLAlchemy wiz <a href=\"https:\/\/twitter.com\/zzzeek\">Mike Bayer<\/a><\/li>\n<li>Here&#8217;s the <a href=\"https:\/\/alembic.readthedocs.org\/en\/latest\/tutorial.html\">tutorial<\/a>. Socorro is now using alembic in production with SQLAlchemy 0.6.x. I&#8217;m hoping to get us upgraded to 0.8.x soon.<\/li>\n<li>Here&#8217;s what <a href=\"https:\/\/gist.github.com\/selenamarie\/4dcf5d05bbe8419e4b42\/raw\/62de2c32f17c0153dc69afa97f145f25a5fab12b\/alembic+output+v46.txt\">running an upgrade in production for Socorro looks like<\/a>. Awesome right?<\/li>\n<li>Here&#8217;s what a <a href=\"https:\/\/github.com\/mozilla\/socorro\/blob\/master\/alembic\/versions\/37004fc6e41e_bug_867606_add_data_.py\">migration looks like<\/a>.<\/li>\n<li>Here&#8217;s <a href=\"https:\/\/github.com\/mozilla\/socorro\/blob\/master\/config\/alembic.ini-dist\">a configuration file<\/a>.<\/li>\n<li>Generating a migration from the command line might look something like:<br \/>\n<code>alembic revision -m \"bug XXXXXX Add a new table\" --autogenerate<\/code><\/li>\n<\/ul>\n<p>The most difficult thing to deal with so far are the many <a href=\"https:\/\/github.com\/mozilla\/socorro\/tree\/master\/socorro\/external\/postgresql\/raw_sql\/procs\">User Defined Functions that we use in Socorro<\/a>. This isn&#8217;t something that any migration tools I tested deal well with.<\/p>\n<p>Happy to answer questions! And I&#8217;ll see about making a longer talk about this transition soon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got a Beer &amp; Tell to give about alembic. Alembic is a migration tool that works with SQLAlchemy. I&#8217;m using it for database migrations with PostgreSQL. So, here&#8217;s what I want to say today: Written by SQLAlchemy wiz Mike &hellip; <a href=\"https:\/\/www.chesnok.com\/daily\/2013\/05\/17\/migrations-with-alembic-a-lightspeed-tour\/\">Continue reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4761","post","type-post","status-publish","format-standard","hentry","category-postgresql"],"_links":{"self":[{"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/posts\/4761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/comments?post=4761"}],"version-history":[{"count":3,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/posts\/4761\/revisions"}],"predecessor-version":[{"id":4807,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/posts\/4761\/revisions\/4807"}],"wp:attachment":[{"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/media?parent=4761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/categories?post=4761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chesnok.com\/daily\/wp-json\/wp\/v2\/tags?post=4761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}