<?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>Ruby on Rails Notes &#187; database</title> <atom:link href="http://railsnotes.com/tag/database/feed/" rel="self" type="application/rss+xml" /><link>http://railsnotes.com</link> <description>A code-heavy brain dump of stuff I come across working on Ruby on Rails projects including Models, ActiveRecord, Views, Controllers, RESTful rails, deployment, server stuff, etc.</description> <lastBuildDate>Sun, 29 Aug 2010 23:45:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Find and Replace in MySQL</title><link>http://railsnotes.com/207-find-and-replace-in-mysql/</link> <comments>http://railsnotes.com/207-find-and-replace-in-mysql/#comments</comments> <pubDate>Tue, 21 Apr 2009 20:58:22 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[Other]]></category> <category><![CDATA[database]]></category> <category><![CDATA[mysql]]></category><guid
isPermaLink="false">http://www.railsnotes.com/?p=207</guid> <description><![CDATA[Even though Rails shields us from having to resort to SQL, it&#8217;s still good to know how to do things directly. One thing I wanted to do today was find all the records that contain &#8220;blahblahblah&#8221; and replace it with &#8220;blah_dee_blah_dee_blah&#8221;. Here&#8217;s how I did it: update wp_3_posts set POST_CONTENT = replace(POST_CONTENT, 'http://www.volcanicmarketing.com/wp-content/', 'http://volcanic.sitespress.net/wp-content/uploads/'); As [...]]]></description> <content:encoded><![CDATA[<p></p><p>Even though Rails shields us from having to resort to SQL, it&#8217;s still good to know how to do things directly. One thing I wanted to do today was find all the records that contain &#8220;blahblahblah&#8221; and replace it with &#8220;blah_dee_blah_dee_blah&#8221;. Here&#8217;s how I did it:</p><pre>update wp_3_posts
set POST_CONTENT = replace(POST_CONTENT,
'http://www.volcanicmarketing.com/wp-content/',
'http://volcanic.sitespress.net/wp-content/uploads/');</pre><p>As you may or may not have guessed, this wasn&#8217;t for a Rails app. It was for my WordPress system. I had moved from single wordpress sites to a server that runs WordPress Mu. One of the changes that resulted from this was that images contained inside my posts didn&#8217;t automatically adjust. The above code fixes this. Let&#8217;s deconstruct it by looking at by looking at the structure of the command:</p><pre>update TABLE_NAME
set FIELD_NAME = replace(FIELD_NAME,
'find this string',
'replace found string with this string');</pre><p>I got the info from <a
href="http://www.mydigitallife.info/2007/04/23/how-to-find-and-replace-text-in-mysql-database-using-sql/">http://www.mydigitallife.info/2007/04/23/how-to-find-and-replace-text-in-mysql-database-using-sql/</a></p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/207-find-and-replace-in-mysql/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Turning an existing database to a rails migration</title><link>http://railsnotes.com/97-turning-an-existing-database-to-a-rails-migration/</link> <comments>http://railsnotes.com/97-turning-an-existing-database-to-a-rails-migration/#comments</comments> <pubDate>Wed, 25 Feb 2009 07:23:02 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[deployment]]></category> <category><![CDATA[database]]></category> <category><![CDATA[migration]]></category> <category><![CDATA[server]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=97</guid> <description><![CDATA[Q: Is there a way to make a migration from an existing database? A. Yes, but you need to be more specific with this question because there are two ways. The first approach will dump the schema of your existing database into a migration. The second will dump the data as well. Why would you want [...]]]></description> <content:encoded><![CDATA[<p></p><p>Q: Is there a way to make a migration from an existing database?</p><p>A. Yes, but you need to be more specific with this question because there are two ways.</p><p>The first approach will dump the schema of your existing database into a migration.</p><p>The second will dump the data as well. Why would you want to dump the data? If you&#8217;re moving machines or changing from a MySQL to a POSTGREs db, this might be useful.</p><p><strong>Approach 1: Dump schema</strong></p><p>Hint: Type in &#8220;rake -T&#8221; into your terminal. The will show you a list of all the rake tasks available to you. Everything you need is here.</p><p>Step 1: rake db:schema:dump   <em>#this will dump the schema into a file called schema.rb</em></p><p>Step 2: rake db:schema:to_migration <em>#this will turn your schema.rb file into a migration file</em></p><p><strong>Approach 2: Dump schema + data</strong></p><p>You&#8217;re going to need the YAMLdb plugin by Adam Wiggins at Heroku. To grab it from: <a
href="http://github.com/adamwiggins/yaml_db/">http://github.com/adamwiggins/yaml_db/</a></p><p>Follow the instructions on the github page.</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/97-turning-an-existing-database-to-a-rails-migration/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Fetching all records corresponding to a set of ids, ignoring invalid ids</title><link>http://railsnotes.com/27-fetching-all-records-corresponding-to-a-set-of-ids-ignoring-invalid-ids/</link> <comments>http://railsnotes.com/27-fetching-all-records-corresponding-to-a-set-of-ids-ignoring-invalid-ids/#comments</comments> <pubDate>Wed, 01 Oct 2008 05:05:24 +0000</pubDate> <dc:creator>Melvin Ram</dc:creator> <category><![CDATA[models]]></category> <category><![CDATA[database]]></category><guid
isPermaLink="false">http://railsnotes.wordpress.com/?p=27</guid> <description><![CDATA[Conversation from #rubyonrails IRC channel pipegeek: Is there a straightforward way, given a list of ids, fetch all corresponding records, ignoring invalid ids? pipegeek: ie, something like Model.find([1,2,3,4,5]), but without the requirement that all the ids be matched pipegeek: err, should clarify (if it isn&#8217;t already obvious) I&#8217;m speaking about activerecord therrg: pipegeek: Model.find_all_by_id([1,2,3,4,5]) does [...]]]></description> <content:encoded><![CDATA[<p></p><p><strong>Conversation from #rubyonrails IRC channel</strong></p><p>pipegeek:<span> </span>Is there a straightforward way, given a list of ids, fetch all corresponding records, ignoring invalid ids?</p><p>pipegeek:<span> </span>ie, something like Model.find([1,2,3,4,5]), but without the requirement that all the ids be matched</p><p>pipegeek:<span> </span>err, should clarify (if it isn&#8217;t already obvious) I&#8217;m speaking about activerecord</p><p>therrg:<span> </span>pipegeek: Model.find_all_by_id([1,2,3,4,5]) does what you want</p><p>pipegeek:<span> </span>oh!  Damn, I feel foolish for not having checked that&#8212;figured the find_all_by_ methods behaved the same way</p><p>pipegeek:<span> </span>thanks, therrg</p><p>therrg:<span> </span>yw</p><p>melvinram:<span> </span>btw, what is your usage scenario?</p><p>melvinram:<span> </span>trying to see when that would be useful</p><p>pipegeek:<span> </span>Well, I have a list of ids generated much earlier by some other tool that added a bunch of records</p><p>pipegeek:<span> </span>I need to do something to all of those records.  Only, it&#8217;s possible that some have been DELETEd in the meantime</p><p>melvinram:<span> </span>ahe i see</p> ]]></content:encoded> <wfw:commentRss>http://railsnotes.com/27-fetching-all-records-corresponding-to-a-set-of-ids-ignoring-invalid-ids/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 6/16 queries in 0.045 seconds using disk

Served from: railsnotes.com @ 2010-09-10 05:54:27 -->