<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.christophchamp.com/index.php?action=history&amp;feed=atom&amp;title=Alembic</id>
		<title>Alembic - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.christophchamp.com/index.php?action=history&amp;feed=atom&amp;title=Alembic"/>
		<link rel="alternate" type="text/html" href="http://wiki.christophchamp.com/index.php?title=Alembic&amp;action=history"/>
		<updated>2026-04-30T15:23:50Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://wiki.christophchamp.com/index.php?title=Alembic&amp;diff=7329&amp;oldid=prev</id>
		<title>Christoph at 00:09, 30 August 2018</title>
		<link rel="alternate" type="text/html" href="http://wiki.christophchamp.com/index.php?title=Alembic&amp;diff=7329&amp;oldid=prev"/>
				<updated>2018-08-30T00:09:02Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 00:09, 30 August 2018&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;'&lt;/del&gt;''Alembic'' is a database migrations tool written by the author of [http://www.sqlalchemy.org/ SQLAlchemy].&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;''Alembic'' is a database migrations tool written by the author of [http://www.sqlalchemy.org/ SQLAlchemy].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Install Alembic==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Install Alembic==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Christoph</name></author>	</entry>

	<entry>
		<id>http://wiki.christophchamp.com/index.php?title=Alembic&amp;diff=6638&amp;oldid=prev</id>
		<title>Christoph: Created page with &quot;'''Alembic'' is a database migrations tool written by the author of [http://www.sqlalchemy.org/ SQLAlchemy].  ==Install Alembic== ''Note: This install process was tested on Ub...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.christophchamp.com/index.php?title=Alembic&amp;diff=6638&amp;oldid=prev"/>
				<updated>2016-08-10T22:27:27Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;Alembic&amp;#039;&amp;#039; is a database migrations tool written by the author of [http://www.sqlalchemy.org/ SQLAlchemy].  ==Install Alembic== &amp;#039;&amp;#039;Note: This install process was tested on Ub...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''Alembic'' is a database migrations tool written by the author of [http://www.sqlalchemy.org/ SQLAlchemy].&lt;br /&gt;
&lt;br /&gt;
==Install Alembic==&lt;br /&gt;
''Note: This install process was tested on Ubuntu 16.04, but it should also work on other distros just fine.''&lt;br /&gt;
&lt;br /&gt;
Assuming you already have MySQL installed on your machine, get the following Alembic dependencies installed:&lt;br /&gt;
 $ sudo apt-get install libmysqlclient-dev -y&lt;br /&gt;
 $ sudo pip install mysql-python&lt;br /&gt;
&lt;br /&gt;
Now, install Alembic:&lt;br /&gt;
 $ sudo pip install alembic&lt;br /&gt;
&lt;br /&gt;
==Configure and use Alembic==&lt;br /&gt;
&lt;br /&gt;
* Create the database migrations environment (note: use &amp;quot;generic&amp;quot; if setting up a single database):&lt;br /&gt;
 $ cd $HOME/dev&lt;br /&gt;
 $ alembic init --template generic alembic&lt;br /&gt;
&lt;br /&gt;
* Edit the &amp;lt;code&amp;gt;alembic.ini&amp;lt;/code&amp;gt; (created by the above command) and change the following line to match your MySQL user, password, hostname, and database name (note: change &amp;quot;driver&amp;quot; to &amp;quot;mysql&amp;quot;):&lt;br /&gt;
 sqlalchemy.url = driver://user:pass@localhost/dbname&lt;br /&gt;
&lt;br /&gt;
* Test that alembic has been properly configured and can connect to MySQL:&lt;br /&gt;
 $ alembic current&lt;br /&gt;
&lt;br /&gt;
* If the above command did not return any errors, create your first revision:&lt;br /&gt;
 $ alembic revision -m &amp;quot;Create users table&amp;quot;&lt;br /&gt;
 Generating $HOME/dev/alembic/versions/9710a474efc0_create_users_table.py ... done&lt;br /&gt;
&lt;br /&gt;
* Edit that &amp;lt;code&amp;gt;9710a474efc0_create_users_table.py&amp;lt;/code&amp;gt; file and update the &amp;lt;code&amp;gt;upgrade()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;downgrade()&amp;lt;/code&amp;gt; functions to look like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def upgrade():&lt;br /&gt;
    op.create_table(&lt;br /&gt;
        'users',&lt;br /&gt;
        sa.Column('id', sa.Integer, primary_key=True),&lt;br /&gt;
        sa.Column('name', sa.String(50), nullable=False),&lt;br /&gt;
        sa.Column('my_decimal', sa.Numeric(16,8), nullable=False),&lt;br /&gt;
        sa.Column('dob', sa.DateTime, nullable=False),&lt;br /&gt;
    )&lt;br /&gt;
&lt;br /&gt;
def downgrade():&lt;br /&gt;
    op.drop_table('users')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now, run a database migration to create the above user table to &amp;quot;head&amp;quot; (where &amp;quot;head&amp;quot; is the latest available migration):&lt;br /&gt;
 $ alembic upgrade head&lt;br /&gt;
&lt;br /&gt;
* Check your MySQL database, and you should see something like the following:&lt;br /&gt;
 $ mysql -e 'describe dbname.users;'&lt;br /&gt;
 +------------+---------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field      | Type          | Null | Key | Default | Extra          |&lt;br /&gt;
 +------------+---------------+------+-----+---------+----------------+&lt;br /&gt;
 | id         | int(11)       | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | name       | varchar(50)   | NO   |     | NULL    |                |&lt;br /&gt;
 | my_decimal | decimal(16,8) | NO   |     | NULL    |                |&lt;br /&gt;
 | dob        | datetime      | NO   |     | NULL    |                |&lt;br /&gt;
 +------------+---------------+------+-----+---------+----------------+&lt;br /&gt;
&lt;br /&gt;
* Undo that above (last) migration with:&lt;br /&gt;
 $ alembic downgrade -1&lt;br /&gt;
&lt;br /&gt;
* Delete the entire database and re-create it (note: to migrate back to the first migration {the beginning}, use &amp;quot;base&amp;quot; {the opposite of &amp;quot;head&amp;quot;}):&lt;br /&gt;
 $ alembic downgrade base&lt;br /&gt;
 $ alembic upgrade head&lt;br /&gt;
&lt;br /&gt;
Your Alembic environment tree should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.&lt;br /&gt;
├── alembic&lt;br /&gt;
│   ├── env.py&lt;br /&gt;
│   ├── env.pyc&lt;br /&gt;
│   ├── README&lt;br /&gt;
│   ├── script.py.mako&lt;br /&gt;
│   └── versions&lt;br /&gt;
│       ├── 9710a474efc0_create_users_table.py&lt;br /&gt;
│       └── 9710a474efc0_create_users_table.pyc&lt;br /&gt;
└── alembic.ini&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [http://alembic.zzzcomputing.com/en/latest/ Alembic documentation] for many more examples and details.&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [https://bitbucket.org/zzzeek/alembic Official website]&lt;br /&gt;
* [http://alembic.zzzcomputing.com/en/latest/ Alembic documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical and Specialized Skills]]&lt;br /&gt;
[[Category:Linux Command Line Tools]]&lt;/div&gt;</summary>
		<author><name>Christoph</name></author>	</entry>

	</feed>