<?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>Bagonca &#187; sqlite3</title>
	<atom:link href="http://www.bagonca.com/blog/tag/sqlite3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bagonca.com/blog</link>
	<description>Yet another developer blog</description>
	<lastBuildDate>Fri, 18 Jun 2010 09:28:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails deploy using sqlite3</title>
		<link>http://www.bagonca.com/blog/2009/05/09/rails-deploy-using-sqlite3/</link>
		<comments>http://www.bagonca.com/blog/2009/05/09/rails-deploy-using-sqlite3/#comments</comments>
		<pubDate>Sat, 09 May 2009 12:22:09 +0000</pubDate>
		<dc:creator>PEZ</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[sqlite3]]></category>

		<guid isPermaLink="false">http://www.bagonca.com/blog/?p=394</guid>
		<description><![CDATA[I had a hard time figuring out why, when reading up on capistrano, I couldn&#8217;t find any info on how to deal with the database file. That was until I realized most people don&#8217;t deploy on sqlite3. With mysql and other databases you have a server and it&#8217;s automatically &#8220;shared&#8221; then.
The only information I found [...]]]></description>
			<content:encoded><![CDATA[<p>I had a hard time figuring out why, when reading up on <a href="http://rubyforge.org/projects/capistrano/">capistrano</a>, I couldn&#8217;t find any info on how to deal with the database file. That was until I realized most people don&#8217;t deploy on <a href="http://www.sqlite.org/">sqlite3</a>. With mysql and other databases you have a server and it&#8217;s automatically &#8220;shared&#8221; then.</p>
<p>The only information I found on deployment on sqlite3 was an excellent deploy script in <a href="http://blog.ninjahideout.com/posts/busting-a-cap-in-yo-ass">this blog article</a>. Basically, using sqlite3 you have to make sure the database is in a shared directory across releases. But the sqlite3 parts of that deploy script didn&#8217;t work for me as they were. I had to make sure I referenced the shared database path all the way or I risked overwriting my database with a symlink. Below are the sqlite3 parts of the resulting capistrano script.</p>
<p>Setting up the shared database path. NB: Lazy binding. Important if you&#8217;re using multistaging from capistrano-ext.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:shared_database_path</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;#{shared_path}/databases&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Sqlite3 tasks.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:sqlite3</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Generate a database configuration file&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:build_configuration</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    db_options = <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#996600;">&quot;adapter&quot;</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;sqlite3&quot;</span>,
      <span style="color:#996600;">&quot;database&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{shared_database_path}/production.sqlite3&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
    config_options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;production&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> db_options<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">to_yaml</span>
    put config_options, <span style="color:#996600;">&quot;#{shared_config_path}/sqlite_config.yml&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Links the configuration file&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:link_configuration_file</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;ln -nsf #{shared_config_path}/sqlite_config.yml #{release_path}/config/database.yml&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Make a shared database folder&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:make_shared_folder</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    run <span style="color:#996600;">&quot;mkdir -p #{shared_database_path}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Hooks (or whatever they&#8217;re called, I&#8217;m new to all this).</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">after <span style="color:#996600;">&quot;deploy:setup&quot;</span>, <span style="color:#996600;">&quot;sqlite3:make_shared_folder&quot;</span>
after <span style="color:#996600;">&quot;deploy:setup&quot;</span>, <span style="color:#996600;">&quot;sqlite3:build_configuration&quot;</span>
&nbsp;
before <span style="color:#996600;">&quot;deploy:migrate&quot;</span>, <span style="color:#996600;">&quot;sqlite3:link_configuration_file&quot;</span></pre></div></div>

<p>Hope this helps someone. Please don&#8217;t hesitate to ask should something need more explaining. And of course suggest improvements. This is all the makings of a capistrano newbie.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bagonca.com/blog/2009/05/09/rails-deploy-using-sqlite3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
