<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LuckyDonkey &#187; SQLAlchemy</title>
	<atom:link href="http://www.luckydonkey.com/category/sqlalchemy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.luckydonkey.com</link>
	<description>Never knowingly knowing narwhals</description>
	<lastBuildDate>Wed, 17 Mar 2010 01:05:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Beep My Stuff enters public Beta</title>
		<link>http://www.luckydonkey.com/2009/04/02/beep-my-stuff-enters-public-beta/</link>
		<comments>http://www.luckydonkey.com/2009/04/02/beep-my-stuff-enters-public-beta/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 23:00:23 +0000</pubDate>
		<dc:creator>dazza</dc:creator>
				<category><![CDATA[Beep My Stuff]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[TurboGears]]></category>

		<guid isPermaLink="false">http://www.luckydonkey.com/?p=226</guid>
		<description><![CDATA[After a rather long period in closed beta I've opened Beep My Stuff to a public beta. Beep My Stuff is a web site that makes it FREE and easy to create an online library of your Books, Movies, Video Games and Music. Check it out, all feedback is much appreciated. It's built with Turbogears, [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_232" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.luckydonkey.com/wp-content/uploads/2009/04/bms_logo-300x147.jpg" alt="Beep My Stuff" title="bms_logo" width="300" height="147" class="size-medium wp-image-232" /><p class="wp-caption-text">Beep My Stuff</p></div><br />
After a rather long period in closed beta I've opened <a href="http://www.beepmystuff.com/">Beep My Stuff</a> to a public beta.</p>
<p><a href="http://www.beepmystuff.com/">Beep My Stuff</a> is a web site that makes it FREE and easy to create an online library of your Books, Movies, Video Games and Music. Check it out, all feedback is much appreciated.</p>
<p>It's built with <a href="http://www.turbogears.org/">Turbogears</a>, <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>, <a href="http://genshi.edgewall.org/">Genshi</a> and countless other python modules. It's all sitting on <a href="http://www.python.org/">Python</a>, <a href="http://www.freebsd.org/">FreeBSD</a> and <a href="http://www.postgresql.org/">PostgreSQL</a>.</p>
<p>Just wanted to say thanks to all the pythonista's out there that helped me get this far <img src='http://www.luckydonkey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><map name='google_ad_map_226_afea9fcd39d8b84a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/226?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_226_afea9fcd39d8b84a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=226&amp;url= http%3A%2F%2Fwww.luckydonkey.com%2F2009%2F04%2F02%2Fbeep-my-stuff-enters-public-beta%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.luckydonkey.com/2009/04/02/beep-my-stuff-enters-public-beta/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQLAlchemy-Migrate upgrade scripts in a transaction</title>
		<link>http://www.luckydonkey.com/2008/07/27/sqlalchemy-migrate-upgrade-scripts-in-a-transaction/</link>
		<comments>http://www.luckydonkey.com/2008/07/27/sqlalchemy-migrate-upgrade-scripts-in-a-transaction/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 23:51:50 +0000</pubDate>
		<dc:creator>dazza</dc:creator>
				<category><![CDATA[NewMetalArmy]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[TurboGears]]></category>

		<guid isPermaLink="false">http://www.luckydonkey.com/?p=210</guid>
		<description><![CDATA[SQLAlchemy Migrate is a really good tool for managing database upgrades for SQLAlchemy centric projects. I've been using it for 6 months on New Metal Army and I haven't had a screwed website upgrade yet! For those that don't know SQLAlchemy-migrate allows you to version control database changes and easily upgrade and downgrade a database. [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9998980871049158";
//468x60, created 11/22/07
google_ad_slot = "6052810016";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><a href="http://code.google.com/p/sqlalchemy-migrate/">SQLAlchemy Migrate</a> is a really good tool for managing database upgrades for <a href="http://www.sqlalchemy.org/">SQLAlchemy</a> centric projects. I've been using it for 6 months on <a href="http://www.newmetalarmy.com">New Metal Army</a> and I haven't had a screwed website upgrade yet!</p>
<p>For those that don't know SQLAlchemy-migrate allows you to version control database changes and easily upgrade and downgrade a database. Basically you write a python script with two functions: upgrade and downgrade. You test the script against the database, commit it to the SQLAlchemy-migrate version repository (not to be confused with your source control mechanism). Finally you upgrade your development database.</p>
<p>When it the time comes to deploy the new application you simply ask sqlalchemy-migrate to upgrade your database to the current version. sqlalchemy-migrate reads the current version of your schema from the database (via a custom table it inserts) and proceeds to upgrade your schema by running each upgrade script in turn.</p>
<p>Often you want your upgrades and downgrades to run within a transaction. Not because you expect them to fail but because while writing them you don't wont to leave the database partially upgraded or downgraded if your script fails. To do this I wrote a transaction decorator. Here is a template for an upgrade script:</p>
<pre class="python"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;"># encoding: utf-8</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> *</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> migrate <span style="color: #ff7700;font-weight:bold;">import</span> *</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">from</span> migrate.<span style="color: black;">changeset</span> <span style="color: #ff7700;font-weight:bold;">import</span> *</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">metadata = MetaData<span style="color: black;">&#40;</span>migrate_engine<span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> transaction<span style="color: black;">&#40;</span>f, *args, **kwargs<span style="color: black;">&#41;</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff7700;font-weight:bold;">def</span> wrapper<span style="color: black;">&#40;</span>*args, **kwargs<span style="color: black;">&#41;</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        connection = migrate_engine.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        transaction = connection.<span style="color: black;">begin</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff7700;font-weight:bold;">try</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            result = f<span style="color: black;">&#40;</span>*args, **kwargs<span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            transaction.<span style="color: black;">commit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            <span style="color: #ff7700;font-weight:bold;">return</span> result</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff7700;font-weight:bold;">except</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            transaction.<span style="color: black;">rollback</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            <span style="color: #ff7700;font-weight:bold;">raise</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">        <span style="color: #ff7700;font-weight:bold;">finally</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">            connection.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    wrapper.__name__ = f.__name__</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    wrapper.<span style="color: #0000cd;">__dict__</span> = f.<span style="color: #0000cd;">__dict__</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    wrapper.__doc__ = f.__doc__</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff7700;font-weight:bold;">return</span> wrapper</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@transaction</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> upgrade<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff7700;font-weight:bold;">pass</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@transaction</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff7700;font-weight:bold;">def</span> downgrade<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color: #ff7700;font-weight:bold;">pass</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li></ol></pre>
<p>I fill in the upgrade and downgrade functions and I'm done <img src='http://www.luckydonkey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I include the decorator in every script as it's good practice to make your scripts as independent as possible. If you imported it from a module you may improve it in the future and inadvertently break your old downgrade scripts.</p>
<p>I hope this  helps you version control your database schema and data.</p>
<p><map name='google_ad_map_210_afea9fcd39d8b84a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/210?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_210_afea9fcd39d8b84a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=210&amp;url= http%3A%2F%2Fwww.luckydonkey.com%2F2008%2F07%2F27%2Fsqlalchemy-migrate-upgrade-scripts-in-a-transaction%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.luckydonkey.com/2008/07/27/sqlalchemy-migrate-upgrade-scripts-in-a-transaction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PostgreSQL, SQLAlchemy, Dropping all tables and sequences</title>
		<link>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/</link>
		<comments>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 21:10:50 +0000</pubDate>
		<dc:creator>dazza</dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQLAlchemy]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/</guid>
		<description><![CDATA[I've been working in deployment scripts for my current project and sometimes I need to drop all the tables and sequences from the database so I can create everything from scratch. I had been doing a &#160; DROP SCHEMA public CASCADE; CREATE SCHEMA public AUTHORIZATION bob; GRANT ALL ON SCHEMA public TO bob; &#160; This [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9998980871049158";
//468x60, created 11/22/07
google_ad_slot = "6052810016";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
I've been working in deployment scripts for my current project and sometimes I need to drop all the tables and sequences from the database so I can create everything from scratch. I had been doing a</p>
<pre class="sql">&nbsp;
<span style="color: #993333; font-weight: bold;">DROP</span> SCHEMA public CASCADE;
<span style="color: #993333; font-weight: bold;">CREATE</span> SCHEMA public AUTHORIZATION bob;
<span style="color: #993333; font-weight: bold;">GRANT</span> <span style="color: #993333; font-weight: bold;">ALL</span> <span style="color: #993333; font-weight: bold;">ON</span> SCHEMA public <span style="color: #993333; font-weight: bold;">TO</span> bob;
&nbsp;</pre>
<p>This was great but a little destructive and over the top. It removes stored procedures and triggers as well which isn't what I want. So I looked at the SQLAlchemy docs and there is a metadata command drop_all()</p>
<pre class="python">&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> drop_tables<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    metadata.<span style="color: black;">drop_tables</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;</pre>
<p>Unfortunately this doesn't CASCADE so this isn't going to work in cases where tables have foreign keys (which is most of the time). It also leaves sequences in place.</p>
<p>So I looked at dropping each table in turn with a cascade. So how do you get a list of tables and sequences in the database? I could hard code the names of the tables and sequences but that seemed a little poor.</p>
<p>It turns out that PostgreSQL has a set of views that expose the inner workings of your database and a few queries can give you all the information you need.</p>
<pre class="python">&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_table_list_from_db<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;
    return a list of table names from the current
    databases public schema
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    sql=<span style="color: #483d8b;">&quot;select table_name from information_schema.tables&quot;</span>\
        <span style="color: #483d8b;">&quot;where table_schema='public'&quot;</span>
    execute = metadata.<span style="color: black;">execute</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>name <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>name, <span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> execute<span style="color: black;">&#40;</span>text<span style="color: black;">&#40;</span>sql<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_seq_list_from_db<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #483d8b;">&quot;return a list of the sequence names from the current
       databases public schema
    &quot;</span><span style="color: #483d8b;">&quot;&quot;</span>
    sql=<span style="color: #483d8b;">&quot;select sequence_name from information_schema.sequences&quot;</span>\
        <span style="color: #483d8b;">&quot;where sequence_schema='public'&quot;</span>
    execute = metadata.<span style="color: black;">execute</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span>name <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: black;">&#40;</span>name, <span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">in</span> execute<span style="color: black;">&#40;</span>text<span style="color: black;">&#40;</span>sql<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> drop_all_tables_and_sequences<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    execute = metadata.<span style="color: black;">execute</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> table <span style="color: #ff7700;font-weight:bold;">in</span> get_table_list_from_db<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            execute<span style="color: black;">&#40;</span>text<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;DROP TABLE %s CASCADE&quot;</span> % table<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> SQLError, e:
            <span style="color: #ff7700;font-weight:bold;">print</span> e
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">for</span> seq <span style="color: #ff7700;font-weight:bold;">in</span> get_seq_list_from_db<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            execute<span style="color: black;">&#40;</span>text<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;DROP SEQUENCE %s CASCADE&quot;</span> % table<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span> SQLError, e:
            <span style="color: #ff7700;font-weight:bold;">print</span> e
&nbsp;</pre>
<p>The information_schema is full of interesting information. It's actually a 'view' of lower level database tables. You can find all sorts of performance and configuration information in there. Quite handy <img src='http://www.luckydonkey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a href="http://www.postgresql.org/docs/8.2/interactive/information-schema.html">Here are some docs</a>.</p>
<p>Good luck.</p>
<p><map name='google_ad_map_172_afea9fcd39d8b84a'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/172?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_172_afea9fcd39d8b84a' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=172&amp;url= http%3A%2F%2Fwww.luckydonkey.com%2F2007%2F11%2F23%2Fpostgresql-sqlalchemy-dropping-all-tables-and-sequences%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.luckydonkey.com/2007/11/23/postgresql-sqlalchemy-dropping-all-tables-and-sequences/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
