<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>@Lathi.net: config/database.yml goodness for teams</title>
    <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>On Life, Fatherhood, Christianity, and Computers</description>
    <item>
      <title>config/database.yml goodness for teams</title>
      <description>&lt;p&gt;If you&amp;#8217;re a one hacker shop doing Rails development it&amp;#8217;s no big deal to store all your database usernames and passwords in &lt;code&gt;config/database.yml&lt;/code&gt;.  When you&amp;#8217;re part of a team all hacking on the same code it becomes a little more complicated.  This is my humble solution that I&amp;#8217;m sure dozens of folks have already thought of.&lt;/p&gt;


	&lt;p&gt;This is the ugliness of the default generated &lt;code&gt;config/database.yml&lt;/code&gt;:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
development:
  adapter: mysql
  database: rails_development
  username: root
  password: my super secret password
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;So let&amp;#8217;s say we have one master &lt;code&gt;config/database.yml&lt;/code&gt; checked into &lt;code&gt;svn&lt;/code&gt; and each developer modifies the file with their own username and password.  Now we&amp;#8217;re stuck with the risk of each developer accidentally checking in their working modification of that file.  Also, do you really want your production database username and password stored in &lt;code&gt;svn&lt;/code&gt;?&lt;/p&gt;


	&lt;p&gt;This morning I had an epiphany.  Thanks to Rails 1.0 we can embed &lt;span class="caps"&gt;ERB&lt;/span&gt; into the &lt;code&gt;config/database.yml&lt;/code&gt;.  Usually I only think of doing things like outputting environment variables and the like.  It occurred to me this morning you can put arbitrary Ruby inside the &lt;code&gt;config/database.yml&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;First we have to restructure the yaml:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
login: &amp;#38;login
  username: defaultuser
  password: defaultpassword

development:
  adapter: mysql
  host: localhost
  database: foo_development
  &amp;lt;&amp;lt;: *login
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;I learned that syntax from the Typo guys.  It basically lets you name blocks and then reuse them later in the yaml file.  You probably see where I&amp;#8217;m going with this&amp;#8230;&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;
login: &amp;#38;login
  username: defaultuser
  password: defaultpassword

&amp;lt;%= file = File.join(RAILS_ROOT, "config", "dblogin.yml")
    IO.read(file) if File.exist?(file) %&amp;gt;

development:
  adapter: mysql
  host: localhost
  database: foo_development
  &amp;lt;&amp;lt;: *login
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;What this will do is insert the contents of &lt;code&gt;config/dblogin.yml&lt;/code&gt; if it exists.  This allows each developer to have a separate file in their working dir with their personal db login information.  Further, you can &lt;code&gt;svn propedit svn:ignore config&lt;/code&gt; to tell svn not to complain about the unknown file &lt;code&gt;dblogin.yml&lt;/code&gt;.&lt;/p&gt;</description>
      <pubDate>Thu, 02 Mar 2006 09:00:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:0c087323-ce83-42db-802e-b25b5a720b35</guid>
      <author>Doug</author>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams</link>
      <category>Ruby on Rails</category>
      <category>Rails</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by gothic wedding dress</title>
      <description>&lt;p&gt;Yes, it&amp;#8217;s true&lt;/p&gt;</description>
      <pubDate>Thu, 29 Jun 2006 06:12:57 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f087cef9-b2e5-45e5-8be5-e273023dca95</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-261</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by choose fashion jewelry</title>
      <description>&lt;p&gt;Choose here&lt;/p&gt;</description>
      <pubDate>Thu, 29 Jun 2006 06:12:38 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:256c60dd-992f-403c-8c08-61ddd57aa82a</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-260</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by womens dress suit</title>
      <description>&lt;p&gt;All about women dresses&lt;/p&gt;</description>
      <pubDate>Mon, 26 Jun 2006 18:56:38 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:60776882-de07-4b6a-96af-b4325e8b010b</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-214</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by free music ringtone</title>
      <description>&lt;p&gt;I&amp;#8217;ll be back!&lt;/p&gt;</description>
      <pubDate>Thu, 15 Jun 2006 08:54:51 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:15e0cfc9-f3b2-4de7-bd8f-eb9f2a1cb541</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-233</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by Doug</title>
      <description>&lt;p&gt;Good advice, Mark!  Thanks for the reminder.&lt;/p&gt;</description>
      <pubDate>Tue, 07 Mar 2006 06:40:57 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:9da130c8-2473-4926-aa6d-e8db7ea76a38</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-163</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by Mark Mascolino</title>
      <description>&lt;p&gt;Neat trick.  I think it should go without saying but you should also check in a nice config/dblogin.yml.sample to svn to show an example of what needs to be filled out.  I&amp;#8217;ve always found that to be handy when picking up a codebase after not using it for awhile.&lt;/p&gt;</description>
      <pubDate>Mon, 06 Mar 2006 21:37:43 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:44e65b13-853c-40f9-9304-4cfda5871c3a</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-162</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by Doug</title>
      <description>&lt;p&gt;Two reasons:&lt;/p&gt;


	&lt;p&gt;First, when you set RAILS_ENV to some environment you also have to have a corresponding config/environments/foo.rb file.  For multiple developers that&amp;#8217;d probably end up as a symlink to config/environments/development.rb.  That&amp;#8217;s look like clutter.&lt;/p&gt;


	&lt;p&gt;Second, I wouldn&amp;#8217;t really want my own username and password stored in the config/database.yml either.  What your suggesting is that everyone put their own personal db username and password in one file and then check that into svn.&lt;/p&gt;


	&lt;p&gt;With my solution the config/dblogin.yml file is local to the developer&amp;#8217;s working directory.  It doesn&amp;#8217;t require global visibility at all.&lt;/p&gt;</description>
      <pubDate>Mon, 06 Mar 2006 07:35:02 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e1408cb4-92be-4e12-9f92-7d55d3d98971</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-161</link>
    </item>
    <item>
      <title>"config/database.yml goodness for teams" by Ed Sumerfield</title>
      <description>&lt;p&gt;Why wouldn&amp;#8217;t you add additional environments to database.yml?&lt;/p&gt;


	&lt;p&gt;dev_doug:
    ...
dev_ed:
    ...&lt;/p&gt;


	&lt;p&gt;Then I just need to set the RAILS_ENV variable to choose the one you want.&lt;/p&gt;</description>
      <pubDate>Sun, 05 Mar 2006 14:39:02 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:429bc4f0-6a57-40c5-9f5a-f29274c74150</guid>
      <link>http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams#comment-160</link>
    </item>
  </channel>
</rss>
