Copying an existing database : Creating a local development database in MS SQL Part 1

One of the first tasks I set myself at my new role was to create my own local development database. Currently, the developers were developing against a populated database shared amongst developers and testers.

I couldn’t find the scripts to recreate the database schema from scratch. The Copy Database Wizard in MS SQL Server Management Studio (SMS) failed with authentication problems. Backup Database stored the sqldump on the remote server hard disk which I didn’t have access to. I was ready to give up when a colleague from another team told me about the scripting functionality in SMS.

Database Objects Scripts

In SMS, right click on the database you want to replicate, then select Tasks -> Generate Scripts. A dialogue will pop up, where you can select the database objects you want to copy. You can copy specific tables, views, stored procedures etc, as shown in the following diagram.

Then in the next dialogue, under the advanced options, there are two options I found especially useful.

  • Script DROP and CREATE
  • Types of data to script: options are schema only, data only and both schema and data

Once the script was generated, it can be applied in a query window for the target database.

Logging configuration in Jboss AS 7.1.1

My new work used Jboss Application Server 7.1 for its web applications. One of the things that surprised me was that it was not straightforward to configure webapps to use log4j.properties for logging configuration.

For development, I like to set all logging to ERROR level, except for the packages I’m working on. To achieve this in Jboss, edit the logging subsystem section in the file ${JBOSS_HOME}/standalone/configuration/standalone.xml.

<subsystem xmlns="urn:jboss:domain:logging:1.1">
   <logger category="com.mycompany.project.package">
     <level name="DEBUG"/>
   </logger>
   <root-logger>
     <level name="ERROR"/>
     <handlers>
       <handler name="CONSOLE"/>
       <handler name="FILE"/>
     </handlers>
   </root-logger>
</subsystem>

This will be applied to all webapps deployed in the Jboss instance.

Using git with a large subversion repos

I recently found myself working on a very large subversion (svn) repository. The repository (possibly) contains the company’s entire code base, spanning nearly 90,000 revisions. Even within the module I’m working on, there are over 300 branches.

Being a git convert, the first thought that occurred to me was to try git-svn, instead of moving back to svn. I love the ability to create multiple local feature branches. (I also prefer the way git merging works. But git-svn is restricted to the svn merge model).

For projects with many branches, it is recommended you clone one directory only. Otherwise, the resulting git repository will be many times larger than the original trunk.

git svn clone http://svn.mycompany.com/projectx/iteration123
Partial Cloning

However, I wanted to clone the trunk and a selection of branches. There are the options –trunk, –tags, –branches for svn repositories with non-standard layouts. Git-svn will also skip checking out paths specified with the option –ignore-paths.

After some experimentation, I found it easier to create an empty git repository, manually edit .git/config, and then fetch. Instead of using the command line options to clone.

git svn init http://svn.mycompany.com/projectx

Edit .git/config

[svn-remote "svn"]
url = http://svn.mycompany.com/projectx
fetch = trunk:refs/remotes/trunk
branches = branches/{iteration123}:refs/remotes/branches/*

The branches entry must contain a wildcard, or git-svn will complain with an error message along the lines of ‘glob needed’. I used the curly braces to fetch the branch iteration123 only. Multiple branches can be specified comma separated, like {iteration123,iteration124}.

I also restricted the fetch to recent revisions, by using the -r option

git svn fetch -r 80000:HEAD

Workflow

After the initial cloning hurdle, I found git-svn very straightforward to use.

At the start of each day, I merged changes from svn by using

git svn rebase

I committed changes to my local git repository with

git commit (-a)

Git-svn pushes each local commit as a separate commit to the remote svn. However, I committed very often and I really didn’t fancy polluting the svn log with lots of ‘reverting’, ‘trying x approach’. Therefore, I squashed all my commits for a scrum task into one commit before pushing the changes back to svn trunk.

git rebase -i branches/iteration123
git svn dcommit