views:

181

answers:

2

I have inherited a project with a local development environment that has code specific to that machine, and which is different for the production server. Even though the majority of it is contained in constants and the rest is in the tests, every time I commit from development and update in production I'm going to have to make the same changes in production. Fortunately this is an internal tool with low volume.

I guess I could write a script to automate it but I'm hoping there's a better solution. Anyone else solved this problem?

These questions are similar but not asking the same thing, just so you know I looked:

(1) make changes to a production database

(2) transferring changes from dev to prod

Edit: Nelson LaQuet put me on what I believe is the right track, which led me to Configuring Rails Applications. However, I am unsure how to reference my FormController < ApplicationController constants, such as MyExternalCodeDir, in config/environments/production.rb and config/environments/development.rb.

Also I do not want to be required to change every reference to MyExternalCodeDir to something like config.MyExternalCodeDir.

+3  A: 

You abstract all environment settings (database connection/pathing/URIs) into a single file. Let's call it "config.ini"

Then you simply commit a "template" called "config.ini.template" that contains the structure of the config file clearly documenting what is expected at each value - and sensable defaults. You then commit this file.

After you do that, delete the current config.ini file that is specific to your location, and add it to svn:ignore. Now, when you copy and paste config.ini.template to config.ini, and change your settings, it is not going to be committed to the repository.

It adds an extra step per deployment, but must be done only once (unless you add/remove config options). This is the best and most standard way of accomplishing what you want.

nlaq
...and you could commit your machine-specific settings files as config.development.ini and config.production.ini or something. No code would refer to those files, but all you'd need to do to make a new checkout work is to rename the appropriate file. Plus you get all the benefits of source control for your specific ini files.
RichieHindle
I'm confused. I delete config.ini that has my specific settings, then copy/paste the template into config.ini and change it back to my settings...why did i delete it in the first place?
kajaco
so you can add it to svn:ignore - which will make it never reach the "repository" code.
nlaq
A: 

I would move the constants' values that are environment specific in a configuration file, which would make it easier to handle. I would also keep the code in just one repository in the version-control system and manage the build outputs in two separate repositories: one for the test environment and one for production. That way I can manage my code base however I choose, and when I want to deploy I'll first commit to test, and then merge from test to production and at that point just diff the configuration file and keep the correct configuration for the production environment.

Mircea Grelus