Welcome Guest, Not a member yet? Register   Sign In
Developing with SVN and CI - best practices?
#1

[eluser]thurting[/eluser]
I am planning on using SVN for my CI projects and was wondering if anyone had insight on best practices for using SVN to develop websites. I'm thinking my workflow will be as follows:

1. checkout from repo
2. develop locally - test locally
4. commit to trunk
5. update to staging server - test on staging server
5. update/export to production server

Feels alright to me, but I have some questions about config files, databases, and larger binary files.

Regarding config, there will be certain settings that differ between development and production servers (e.g. error_reporting, database). I'm wondering what the best way to handle this issue is. Taking the case of error_reporting, in my trunk/tags I will want this set to 0, but when developing it should be set to a higher level. Should I leave it up to developers to make sure this setting is always set to 0 upon commit? Should I have a development branch with the relevant settings that an administrative user will change upon moving to the trunk/tags? Should I do something else? If I use a staging server I should be able to catch any errors before they go live, but I'd like to minimize issues like this.

Regarding databases, obviously I don't want to work off of the live DB in a dev environment, so how should this be handled? Should I include some .sql files that will quickly build up a dev DB on the dev machine? This seems easiest, but the developer would then also have to go into the DB config file and alter the active group and I would run into the issue described in the paragraph above.

Regarding large binary files (e.g. .mov, .flv), it seems like putting these in the repository would be a bad idea - especially, if I was going to use export to sync my production server. Most of these files probably won't be needed for development, but if some are, where should they be kept? I'm thinking I should just copy those needed to a private dir on my server and allow developers to download directly through ftp.

What do you think?
#2

[eluser]Phil Sturgeon[/eluser]
Config
Much of this can be kept the same while working through it all. You can set the basic config stuff that wont change using some sneaky plain PHP in the config files, for example:

Code:
if($_SERVER['SERVER_NAME'] == 'localhost'):
    $config['base_url']    = "http://localhost/project/";
else:
    $config['base_url']    = "http://beta.project.com/";
endif;

You could perhaps even do that in a few other places in the config file, then just remember to remove it all when the project is complete.

OR you can simply commit the server config settings, change your copy to settings that work for your machine then use SVN's ignore to make sure the changes are not commited.


Database
I use two online databases, live and test. All my team work on the test one (which is online ofc) but we keep a .sql file in the trunk just to make sure we have a backup of the DB in case we lose it or our internet randomly breaks, then we can grab the .sql file and run our DB locally.


Large Files
Upload to FTP somewhere and post a file with a link to them in the trunk. That way if the files move you can track where they have moved, and all your team know where they are without clogging your SVN.
#3

[eluser]thurting[/eluser]
Thanks for the suggestions.
#4

[eluser]Crimp[/eluser]
A Transmit tip, if on Mac:

You can exclude optional files from the sync. This makes it easy to keep two original versions of files, config, database, etc., that have local/live settings. Configs are rarely changed, so a manual edit if you do change is no big deal.
#5

[eluser]esra[/eluser]
Pyro, very helpfull.
#6

[eluser]thephpx[/eluser]
thanks! was helpful Tongue
#7

[eluser]Jonas G[/eluser]
I like the idea about working on an online test database - i'll do that for my next project. If you like the idea about working offline (as I do), here's my method:

What I do now is dump the database to an .sql file and then have a controller which imports the sql file:

Code:
$sql_file = APPPATH.'sql/dump_all.sql';
                echo 'This might take some time...';
                $handle = @fopen($sql_file, "r");
                $query = "";
                while(!feof($handle)) {
                    $sql_line = fgets($handle);
                    if (trim($sql_line) != "" && strpos($sql_line, "--") === false) {
                        $query .= $sql_line;
                        if (preg_match("/;[\040]*\$/", $sql_line)) {
                            $this->db->query($query);
                            $query = "";
                        }
                    }
                }
                echo 'Done...';

That way you can add the .sql file to the repo and when there is updates to the database just run a local URL which calls the above.

I use this with mysql dumps but would be much more versatile if it used ALTER TABLE and the like... Be careful about this way though - there's no reverting.




Theme © iAndrew 2016 - Forum software by © MyBB