PyCon 2014

Gestionando el esquema de las aplicaciones Python con Alembic y SQLAlchemy

Selena Deckelmann  · 




Extracto de la transcripción automática del vídeo realizada por YouTube.

good afternoon everyone it's my honor to introduce Selina Declan she's a major contributor to post grad school and she founded pi ladies PDX open source bridge post grads open do you still keep chickens she still keeps chickens so let's give her

a big warm welcome she's gonna be talking about Alembic it's equally yeah there's one that's even alive right now it's good sorry little dead chicken humor to start off this talk okay so um so this talk is about database migrations and

being sane about it I uploaded the slides already so you can check them out there and I wanted to start out by saying thank you and I'm sorry - Mike Baer who who's the primary author of Alembic and he's here today I think he's speaking after

after me so I don't think he's here right now and so for work I work for Mozilla and I work on this tool called socorro which is an open-source crash management and business intelligence system that we run to analyze primarily Firefox crashes you can

check out our source code at that URL and you can also see our production site that's running and we use Alembic for all of our migrations and while I have been at PyCon actually my co-workers have been running migrations all on their own which is amazing

and awesome so as you might imagine from that introduction we use Postgres so most of these things thank you i I'm pretty sure that all this stuff that I'm going to talk about today would work with another database and I know that Mike develops quite

a bit for Oracle but just to let you know that all of my experience has to do with using Alembic with Postgres so I think the first thing to note about databases is that database systems and maybe the also the people that maintain them very much resist change

and this is my idea of sort of the evolution of schema change process over time you start out with the Yolo approach at the bottom there and people I don't know if you're familiar with the /ef command but that allows you to actually edit stored procedures

and Postgres interactively and the PIA SQL command line so people do that in prod it's pretty awesome that's kind of on the the Precambrian evolutionary scale and then over time people figure out that maybe you know they want a little more process

involved in their schema management and they start doing things like using revision control on their schemas and then eventually they do things like have rollback plans and code review and then finally finally we sometimes occasionally get two tests that are

run using generator to date on our skews how do you hear you do that for intestine nice alright my people here that's great and then you might move on to testing on prod like data which is exciting and then finally you might get to testing a complete stage

environment that has a copy of production data and I will say that I am one of the very fortunate few that has a complete copy of production data in my staging environment and it makes my life a lot easier so here to say it can be done it happens so what is

same schema management well I think I define that as executing a schema change in a controlled and repeatable way while you're working with developers and also operations I think that this is the only way that you can get it to be controlled and repeat

of all is if you have both the developers and the operations folks kind of working together you know it's the DevOps keyword but it it really you really do need people collaborating on this and the other thing that I've realized as I've had to

maintain this system for the last couple years is that migration tools really are configuration management tools for your database and once that kind of clicks in the head of the people that are working on these problems in some ways it can make the conversations

easier about really how this is managed why you need code review and why having downgrade scripts is actually a really good idea so the stuff we're going to talk about today migrations they're about communicating change communicating process and like

I said executing stuff in a controlled and repeatable way with both developers and operations so what you came here for Alembic it's a schema migration tool that integrates with sequel alchemy and I'm gonna get into a lot of details about exactly how

to use it in my talks today they might talk today so my assumptions about people's environments and why you might want to use something like olimpic specifically is that schema migrations are frequent automation of schema migration is a goal we currently

have an environment that runs a downgrade and then an upgrade in Jenkins before every build of our production code that your stage environment is enough like production for testing it doesn't have to be an exact duplicate like ours but it needs to be enough

it needs to have enough bad data in it or whatever else it is that you deal with in production so that it can make it real and also I assume that writing a small amount of code is okay sometimes this can be a problem if you're working in an environment

where you have to hand things off wholesale to the DBAs I know that Mike wrote the Olympic with that specific situation in mind and there are tools built into it to help you with that so that you can just hand raw sequel off to a group of DBAs if that's

[ ... ]

Nota: se han omitido las otras 2.649 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.