<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: SQLAlchemy Migrate Process Hiccups</title>
	<atom:link href="http://percious.com/blog/archives/24/feed" rel="self" type="application/rss+xml" />
	<link>http://percious.com/blog/archives/24</link>
	<description>pythonic musings of a mountaineer</description>
	<lastBuildDate>Mon, 30 Aug 2010 23:25:44 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Lucas</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-8039</link>
		<dc:creator>Lucas</dc:creator>
		<pubDate>Wed, 04 Feb 2009 16:33:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-8039</guid>
		<description>Seems like Hans and Doug solution combined should be new migrate plan.

Add a 
set_table_version(tablename, version)

Version could be a combination of numbers (production.testing.development)(1.3.503)

then when doing upgrades use the solution that goes through each upgrade version from 0 but first check if this version of the upgrade was applied? (isEligible(CurrentTableVersion,upgradeTableVersion)

If upgrade was not applied, apply it, 
if upgrade was applied move on to the next item.

This would make sure you only upgrade from what you are on forward. 

There should also be a command to reset it all. For example after few years you are at production 40.1.0, and you don&#039;t want to check all the upgrades from day1. There should be a reset that takes the current 40.1.0 and makes it a first upgrade. 

Now we just needs some code samples to fill these parts in and connect it to migrate.

Thanks,
Lucas</description>
		<content:encoded><![CDATA[<p>Seems like Hans and Doug solution combined should be new migrate plan.</p>
<p>Add a<br />
set_table_version(tablename, version)</p>
<p>Version could be a combination of numbers (production.testing.development)(1.3.503)</p>
<p>then when doing upgrades use the solution that goes through each upgrade version from 0 but first check if this version of the upgrade was applied? (isEligible(CurrentTableVersion,upgradeTableVersion)</p>
<p>If upgrade was not applied, apply it,<br />
if upgrade was applied move on to the next item.</p>
<p>This would make sure you only upgrade from what you are on forward. </p>
<p>There should also be a command to reset it all. For example after few years you are at production 40.1.0, and you don&#8217;t want to check all the upgrades from day1. There should be a reset that takes the current 40.1.0 and makes it a first upgrade. </p>
<p>Now we just needs some code samples to fill these parts in and connect it to migrate.</p>
<p>Thanks,<br />
Lucas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jorge Vargas</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-3413</link>
		<dc:creator>Jorge Vargas</dc:creator>
		<pubDate>Wed, 10 Dec 2008 08:19:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-3413</guid>
		<description>I got very little experience with migrate, but I think there is a 3th, from migrate docs:
&quot;A freshly versioned database begins at version 0 by default. This assumes the database is empty. (If this is a bad assumption, you can specify the version at the time the database is declared under version control, with the version_control command.) We&#039;ll see that creating and applying change scripts changes the database&#039;s version number. &quot;

This implies you can alter the initial version number. Although I&#039;m not sure if you can do that with a migrate command, so back to your example: Say it is your project and I&#039;m the one hoping in from time to time, you will give the the current model and the current db number, which I&#039;ll insert as my first migration, and with that we should be able to fool the db.

Now that&#039;s all theory as I haven&#039;t been able to get migrations going for this project :)</description>
		<content:encoded><![CDATA[<p>I got very little experience with migrate, but I think there is a 3th, from migrate docs:<br />
&#8220;A freshly versioned database begins at version 0 by default. This assumes the database is empty. (If this is a bad assumption, you can specify the version at the time the database is declared under version control, with the version_control command.) We&#8217;ll see that creating and applying change scripts changes the database&#8217;s version number. &#8221;</p>
<p>This implies you can alter the initial version number. Although I&#8217;m not sure if you can do that with a migrate command, so back to your example: Say it is your project and I&#8217;m the one hoping in from time to time, you will give the the current model and the current db number, which I&#8217;ll insert as my first migration, and with that we should be able to fool the db.</p>
<p>Now that&#8217;s all theory as I haven&#8217;t been able to get migrations going for this project <img src='http://percious.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-3261</link>
		<dc:creator>Hans</dc:creator>
		<pubDate>Sat, 06 Dec 2008 15:31:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-3261</guid>
		<description>I should also clarify that the end solution for us was a little more involved than simply storing version number in the table comment.  Because we are using an ORM that generates the SQL based on a schema.xml file (Propel, to be specific), we modified our build system to split out all of the DDL related to indexes, foreign keys, views, etc.  Before we actually run the migration code for each table, we do things like drop all FKEY constraints on the table.  In some cases we have to drop other dependent objects too (e.g. views).  At the end of our migration code we actually re-apply all of that dependent object creation DDL; much of it does not get applied (because it was never dropped), but that has proven a clean way of upgrading non-table objects.

So, the point I wanted to clarify is that while the table-version-in-model method only addresses versioning for tables, we found that this was all that we really *needed* to version since we could drop and recreate all the other (dependent) objects in the system.

We also moved all of the comment-setting code into database functions -- we have a set_table_version(tablename, version) method, for example -- which does some fancy regex to replace or prepend the version information to a comment.  And a get_table_version(tablename) to get the current version.  End result just looks like &quot;v1.0.2 - Table to store user data.&quot;

In any event, the approach shouldn&#039;t scare you like PHPNuke :)  There was actually some thought put into how this works -- and keeping the abstraction points in place to avoid coupling it too closely to any one particular database or even any one particular versioning mechanism.  (We could always re-implement the Upgrade-&gt;isEligible(Table) method to use something besides table comments to determine eligibility.)

-H</description>
		<content:encoded><![CDATA[<p>I should also clarify that the end solution for us was a little more involved than simply storing version number in the table comment.  Because we are using an ORM that generates the SQL based on a schema.xml file (Propel, to be specific), we modified our build system to split out all of the DDL related to indexes, foreign keys, views, etc.  Before we actually run the migration code for each table, we do things like drop all FKEY constraints on the table.  In some cases we have to drop other dependent objects too (e.g. views).  At the end of our migration code we actually re-apply all of that dependent object creation DDL; much of it does not get applied (because it was never dropped), but that has proven a clean way of upgrading non-table objects.</p>
<p>So, the point I wanted to clarify is that while the table-version-in-model method only addresses versioning for tables, we found that this was all that we really *needed* to version since we could drop and recreate all the other (dependent) objects in the system.</p>
<p>We also moved all of the comment-setting code into database functions &#8212; we have a set_table_version(tablename, version) method, for example &#8212; which does some fancy regex to replace or prepend the version information to a comment.  And a get_table_version(tablename) to get the current version.  End result just looks like &#8220;v1.0.2 &#8211; Table to store user data.&#8221;</p>
<p>In any event, the approach shouldn&#8217;t scare you like PHPNuke <img src='http://percious.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   There was actually some thought put into how this works &#8212; and keeping the abstraction points in place to avoid coupling it too closely to any one particular database or even any one particular versioning mechanism.  (We could always re-implement the Upgrade-&gt;isEligible(Table) method to use something besides table comments to determine eligibility.)</p>
<p>-H</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Hellmann</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-3256</link>
		<dc:creator>Doug Hellmann</dc:creator>
		<pubDate>Sat, 06 Dec 2008 13:21:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-3256</guid>
		<description>I haven&#039;t used sqlalchemy-migrate, but the way we deal with this in the alter scripts we wrote at work is to have each migration test the database to see if it needs to be applied.  So if a script wants to add a column, first the test() method is invoked and it looks for the column.  If it isn&#039;t found, it returns True, and the alter() method is run.  If the column is found by test(), it returns False and the alter() method is not run.  

We found this to be much more workable than depending on recording which alterations have been made to a given database -- that&#039;s just redundant information if you have the ability to look at the schema.</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t used sqlalchemy-migrate, but the way we deal with this in the alter scripts we wrote at work is to have each migration test the database to see if it needs to be applied.  So if a script wants to add a column, first the test() method is invoked and it looks for the column.  If it isn&#8217;t found, it returns True, and the alter() method is run.  If the column is found by test(), it returns False and the alter() method is not run.  </p>
<p>We found this to be much more workable than depending on recording which alterations have been made to a given database &#8212; that&#8217;s just redundant information if you have the ability to look at the schema.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: percious</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-3242</link>
		<dc:creator>percious</dc:creator>
		<pubDate>Sat, 06 Dec 2008 04:52:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-3242</guid>
		<description>Thanks for the reply hans.  This was exactly the kind of discussion I was hoping to get.  You have a unique solution to the problem, and I must admit it has the benefit of being flexible in that you could use other migrate solutions since the migration data is stored within the database, but it scares me a little in the way that PHPNuke does...  But seriously, I am interested in all solutions people have for this problem.  The more I think about it, the more I like solution 2.</description>
		<content:encoded><![CDATA[<p>Thanks for the reply hans.  This was exactly the kind of discussion I was hoping to get.  You have a unique solution to the problem, and I must admit it has the benefit of being flexible in that you could use other migrate solutions since the migration data is stored within the database, but it scares me a little in the way that PHPNuke does&#8230;  But seriously, I am interested in all solutions people have for this problem.  The more I think about it, the more I like solution 2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans</title>
		<link>http://percious.com/blog/archives/24/comment-page-1#comment-3235</link>
		<dc:creator>Hans</dc:creator>
		<pubDate>Sat, 06 Dec 2008 00:47:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.percious.com/blog/archives/24#comment-3235</guid>
		<description>Well, I haven&#039;t used Migrate yet; I look forward to being able to do that on an upcoming project.  I had to solve a similar problem with our PHP ORM solution not that long ago.  What we ended up doing was actually storing versions of our model in the database -- in the comments on table names, to be specific.  We also had a lightweight set of DB utilities and baseclasses that we could extend with our actual migration scripts.  Yes, this solution does require that you use an RDBMS that supports comments (we use postgresql), but in practice it actually has worked very well and it provides some additional assurance that our migration scripts won&#039;t try to migrate an already-upgraded table.   This is certainly not the best solution, but I wanted to offer another lightweight option to this migration issue.

-H</description>
		<content:encoded><![CDATA[<p>Well, I haven&#8217;t used Migrate yet; I look forward to being able to do that on an upcoming project.  I had to solve a similar problem with our PHP ORM solution not that long ago.  What we ended up doing was actually storing versions of our model in the database &#8212; in the comments on table names, to be specific.  We also had a lightweight set of DB utilities and baseclasses that we could extend with our actual migration scripts.  Yes, this solution does require that you use an RDBMS that supports comments (we use postgresql), but in practice it actually has worked very well and it provides some additional assurance that our migration scripts won&#8217;t try to migrate an already-upgraded table.   This is certainly not the best solution, but I wanted to offer another lightweight option to this migration issue.</p>
<p>-H</p>
]]></content:encoded>
	</item>
</channel>
</rss>
