Wednesday, May 15, 2013

Yet Another ORM Micro Benchmark, part 2/3, implementation

As the principles of the benchmark have been laid, I can now move to implementations. What follows are code snippets of each test case, with comments where necessary.

ADO.NET

The ADO.NET test is straightforward:

public class PerformanceADOSelect : IPerformanceTest
{
    public PerformanceADOSelect( int NumberOfItems, int NumberOfTests )
    {
        this._NUMBEROFITEMS = NumberOfItems;
        this._NUMBEROFTESTS = NumberOfTests;
    }
 
    int _NUMBEROFITEMS;
    int _NUMBEROFTESTS;
 
    public void PerformTest( out DateTime StartedAt, out DateTime EndedAt )
    {
        StartedAt = DateTime.Now;
 
        for ( int i = 0; i < _NUMBEROFTESTS; i++ )
        {
            StringBuilder sb = new StringBuilder();
            using ( SqlConnection conn = 
               new SqlConnection( ConfigurationManager.ConnectionStrings["ParentChildConnectionString"].ConnectionString ) )
            {
                conn.Open();
                using ( SqlCommand cmd = 
                   new SqlCommand( string.Format( "SELECT TOP {0} * FROM Child", _NUMBEROFITEMS ), conn ) )
                using ( SqlDataReader dr = cmd.ExecuteReader() )
                {
                    while ( dr.Read() )
                    {
                        Child child = new Child();
 
                        child.ID        = (int)dr["ID"];
                        child.ID_PARENT = (int)dr["ID_PARENT"];
                        child.ChildName = (string)dr["ChildName"];
 
                        sb.Append( child.ChildName );
                    }
                }
            }
            sb = null;
        }
 
        EndedAt = DateTime.Now;
    }
 
    public string Category
    {
        get { return "ADO.NET"; }
    }
 
    public string Name
    {
        get { return string.Format( "SELECT TOP {0} - {1} TIMES", _NUMBEROFITEMS, _NUMBEROFTESTS ); }
    }
}
 
public class Child
{
    public int ID { get; set; }
    public string ChildName { get; set; }
    public int ID_PARENT { get; set; }
}

Note that the materialization is done manually but in addition, a dummy StringBuilder accumulates some data for each read record. This string builder is not important with this ADO.NET test but in later tests the intention of it will be to simulate that the data is actually used somehow (not only read from the database).

Linq2SQL

This time also the test is straightforward. The model has been generated automatically, both the data context and entities.

public class PerformanceLinq2SqlSelect : IPerformanceTest
{
    public PerformanceLinq2SqlSelect( int NumberOfItems, int NumberOfTests )
    {
        this._NUMBEROFITEMS = NumberOfItems;
        this._NUMBEROFTESTS = NumberOfTests;
    }
 
    int _NUMBEROFITEMS;
    int _NUMBEROFTESTS;
 
    public void PerformTest( out DateTime StartedAt, out DateTime EndedAt )        
    {
        // warmup
        using ( ParentChildDataContext ctx = new ParentChildDataContext() )
        {
            var children = ctx.Childs.ToList();
        }
 
        StartedAt = DateTime.Now;
 
        for ( int i = 0; i < _NUMBEROFTESTS; i++ )
        {
            StringBuilder sb = new StringBuilder();
            using ( ParentChildDataContext ctx = new ParentChildDataContext() )
            {
                foreach ( var child in ctx.Childs.Take( _NUMBEROFITEMS ) )
                    sb.Append( child.ChildName );
            }
            sb = null;
        }
 
        EndedAt = DateTime.Now;
    }
 
    public string Category
    {
        get { return "Linq2Sql"; }
    }
 
    public string Name
    {
        get { return string.Format( "SELECT TOP {0} - {1} TIMES", _NUMBEROFITEMS, _NUMBEROFTESTS ); }
    }
}

Note that this time I perform a “warmup” – this is to make sure that no internals of the ORM depending on the “first run” will influence the measurement.

EF5 Model First

This test is similar to the previous one – model is generated with the help of the designer, both object context and entity classes are available.

public class PerformanceEFModelFirstSelect : IPerformanceTest
{
    public PerformanceEFModelFirstSelect( bool Tracking, int NumberOfItems, int NumberOfTests )
    {
        this.Tracking       = Tracking;
        this._NUMBEROFITEMS = NumberOfItems;
        this._NUMBEROFTESTS = NumberOfTests;
    }
 
    bool Tracking;
    int _NUMBEROFITEMS;
    int _NUMBEROFTESTS;
 
    public void PerformTest( out DateTime StartedAt, out DateTime EndedAt )        
    {
        using ( ParentChildEntities ctx = new ParentChildEntities() )
        {
            var children = ctx.Child.ToList();
            var parents  = ctx.Parent.ToList();
        }
 
        StartedAt = DateTime.Now;
 
        for ( int i = 0; i < _NUMBEROFTESTS; i++ )
        {
            StringBuilder sb = new StringBuilder();
            using ( ParentChildEntities ctx = new ParentChildEntities() )
            {
                if ( !this.Tracking )
                    ctx.Child.MergeOption = System.Data.Objects.MergeOption.NoTracking;
 
                foreach ( var child in ctx.Child.Take( _NUMBEROFITEMS ) )
                    sb.Append( child.ChildName );
            }
            sb = null;
        }
 
        EndedAt = DateTime.Now;
    }
 
    public string Category
    {
        get { return string.Format( "EF ModelFirst {0}", Tracking ? "Tracking" : "NoTracking" ); }
    }
 
    public string Name
    {
        get { return string.Format( "SELECT TOP {0} - {1} TIMES", _NUMBEROFITEMS, _NUMBEROFTESTS ); }
    }
}

What is interesting is that this time I consider tracking as an important factor and I make sure that it can be turned off. Turining tracking off has some serious consequences for change tracking but since we only select the data, the only observable difference would be that turning tracking off will make the execution much faster.

I also make sure that views are pregenerated (by forcing the pregeneration with the EF Power Tools).

EF5 Code First

For Code First approach, we create entities and the dbcontext manually

public partial class Child
{
    public int ID { get; set; }
    public int ID_PARENT { get; set; }
    public string ChildName { get; set; }
    public virtual Parent Parent { get; set; }
}
 
public partial class Parent
{
    public Parent()
    {
        //this.Children = new List<Child>();
    }
 
    public int ID { get; set; }
    public string ParentName { get; set; }
    public virtual ICollection<Child> Children { get; set; }
}
 
public partial class ParentChildContext : DbContext
{
    static ParentChildContext()
    {
        Database.SetInitializer<ParentChildContext>(null);
    }
 
    public ParentChildContext()
        : base( "Name=ParentChildConnectionString" )
    {
        this.Configuration.AutoDetectChangesEnabled = false;
    }
 
    public DbSet<Child> Children 
    { 
        get; 
        set; 
    }
 
    public DbSet<Parent> Parents 
    { 
        get; 
        set; 
    }
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Child>()
            .ToTable("Child");
 
        // Relationships
        modelBuilder.Entity<Child>()
            .HasRequired( t => t.Parent )
            .WithMany( t => t.Children )
            .HasForeignKey( d => d.ID_PARENT );
 
        modelBuilder.Entity<Parent>()
            .ToTable( "Parent" );
    }
}

The test now becomes

public class PerformanceEFCodeFirstSelect : IPerformanceTest
 {
     public PerformanceEFCodeFirstSelect( bool Tracking, int NumberOfItems, int NumberOfTests )
     {
         this.Tracking       = Tracking;
         this._NUMBEROFITEMS = NumberOfItems;
         this._NUMBEROFTESTS = NumberOfTests;
     }
 
     bool Tracking;
     int _NUMBEROFITEMS;
     int _NUMBEROFTESTS;
 
     public void PerformTest( out DateTime StartedAt, out DateTime EndedAt )
     {
         #region warmup
         using ( ParentChildContext ctx = new ParentChildContext() )
         {
             var parents = ctx.Parents.ToList();
             var children = ctx.Children.ToList();
         }
         #endregion
 
         StartedAt = DateTime.Now;
 
         for ( int i = 0; i < _NUMBEROFTESTS; i++ )
         {
             StringBuilder sb = new StringBuilder();
             using ( ParentChildContext ctx = new ParentChildContext() )
             {
                 if ( Tracking )
                     foreach ( var child in ctx.Children.Take( _NUMBEROFITEMS ) )
                         sb.Append( child.ChildName );
                 else
                     foreach ( var child in ctx.Children.AsNoTracking().Take( _NUMBEROFITEMS ) )
                         sb.Append( child.ChildName );
             }
             sb = null;
         }
 
         EndedAt = DateTime.Now;
 
     }
 
     public string Category
     {
         get { return string.Format( "EF CodeFirst {0}", Tracking ? "Tracking" : "NoTracking" ); }
     }
 
     public string Name
     {
         get { return string.Format( "SELECT TOP {0} - {1} TIMES", _NUMBEROFITEMS, _NUMBEROFTESTS ); }
     }
 }

Note that in this case there is no easy way of turing tracking off on the db context, instead, an extension AsNoTracking is used.

nHibernate

For nHibernate, model has to be created manually

public class Child
{
    public virtual int ID { get; set; }
    public virtual int ID_PARENT { get; set; }
    public virtual string ChildName { get; set; }
    public virtual Parent Parent { get; set; }
}
 
public class Parent
{
    public Parent()
    {
    }
 
    public virtual int ID { get; set; }
    public virtual string ParentName { get; set; }
    public virtual IList<Child> Children { get; set; }
}

as well as mappings

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping 
    xmlns="urn:nhibernate-mapping-2.2" 
    assembly="Performance.NH" 
    namespace="Performance.NH.Model"    >
    <class name="Child" 
           optimistic-lock="none" dynamic-update="true">
        <id name="ID">
            <generator class="native" />
        </id>
        <property name="ChildName" />
        <many-to-one name="Parent" column="ID_PARENT" />
    </class>
</hibernate-mapping>
 
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
    assembly="Performance.NH" namespace="Performance.NH.Model">
    <class name="Parent" table="`Parent`" 
           optimistic-lock="none" dynamic-update="true">
        <id name="ID">
            <generator class="native" />
        </id>
        <property name="ParentName" />
        <bag name="Children">
            <key column="ID_PARENT" />
            <one-to-many class="Child"/>
        </bag>
    </class>
</hibernate-mapping>
 
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string_name">ParentChildConnectionString</property>
    </session-factory>
</hibernate-configuration>

and the test is

public class PerformanceNHSelect : IPerformanceTest
{
    public PerformanceNHSelect( bool StateLess, int NumberOfItems, int NumberOfTests )
    {
        this._StateLess = StateLess;
        this._NUMBEROFITEMS = NumberOfItems;
        this._NUMBEROFTESTS = NumberOfTests;
    }
 
    bool _StateLess;
    int _NUMBEROFITEMS;
    int _NUMBEROFTESTS;
 
    public void PerformTest( out DateTime StartedAt, out DateTime EndedAt )        
    {
        Configuration cfg = new Configuration();
 
        cfg.Configure( typeof( PerformanceNHSelect ).Assembly, 
           "Performance.NH.Model.hibernate.cfg.xml" );
        cfg.AddAssembly( typeof( PerformanceNHSelect ).Assembly );
 
        var sessionFactory = cfg.BuildSessionFactory();
 
        #region warmup
        StringBuilder sbw = new StringBuilder();
        using ( var session = sessionFactory.OpenSession() )
        {
            session.DefaultReadOnly = true;
            session.FlushMode = FlushMode.Never;
            foreach ( var child in session.Query<Child>().Take( _NUMBEROFITEMS ) )
                sbw.Append( child.ChildName );
        }
        #endregion
 
        StartedAt = DateTime.Now;
 
        for ( int i = 0; i < _NUMBEROFTESTS; i++ )
        {
            StringBuilder sb = new StringBuilder();
 
            if ( _StateLess )
            {
                using ( var session = sessionFactory.OpenStatelessSession() )
                {
                    using ( var tran = session.BeginTransaction() )
                    {
                        foreach ( var child in session.Query<Child>().Take( _NUMBEROFITEMS ) )
                            sb.Append( child.ChildName );
                    }
                }
            }
            else
            {
                using ( var session = sessionFactory.OpenSession() )
                {
                    using ( var tran = session.BeginTransaction() )
                    {
                        foreach ( var child in session.Query<Child>().Take( _NUMBEROFITEMS ) )
                            sb.Append( child.ChildName );
                    }
                }
            }
 
            sb = null;
        }
 
        EndedAt = DateTime.Now;
    }
 
    public string Category
    {
        get { return string.Format( "nHibernate {0}", _StateLess ? "StateLess" : "StateFull" ); }
    }
 
    public string Name
    {
        get { return string.Format( "SELECT TOP {0} - {1} TIMES", _NUMBEROFITEMS, _NUMBEROFTESTS ); }
    }
}

What is interesting here is that I am trying to compare the statefull and stateless session with the hope that stateless sessions would somehow correspond to EF’s “no tracking” in a sense that a stateless session should fetch rows from the database faster.

In the next entry we will analyze results.

Yet Another ORM Micro Benchmark, part 1/3, introduction

I’ve been experimenting with Entity Framework 5 Code First lately and one of my concerns was the performance on bare SELECTs as most of the time my applications just select the data.

In past, Entity Framework was never a fast mapper. In fact, my eariler experiments suggested that it is one of the most sluggish. As it turned out, there are quite a lot of factors a reliable benchmark has to consider regarding Entity Framework:

  1. EF relies on the metadata. A reliable test should not measure the time to create actual metadata but rather focus only on reading and materializing data.
  2. EF relies on “pregenerated” views, which are your actual queries. Similarily to metadata, view generation takes time so it should not be considered a factor.
  3. EF should supposedly be faster on .NET 4.5 while my earlier tests were performed on .NET 4.0
  4. It is important whether EF tracks changes to your entities or not

My fair tests should then consider all these factors and make sure that there is no single issue that could possibly spoil the results.

What other, similar benchmarks seem to omit is the fact that reading data behaves differently depending on the amount of data you actually read. There is a big difference in reading 1 entity vs reading 100 or 10000 entities when you compare different approaches.

I then decided to create a test environment with a database with two simple tables:

CREATE TABLE [dbo].[Child](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [ID_PARENT] [int] NOT NULL,
    [ChildName] [nvarchar](150) NOT NULL,
 CONSTRAINT [PK_Child] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)
 
CREATE TABLE [dbo].[Parent](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [ParentName] [nvarchar](150) NOT NULL,
 CONSTRAINT [PK_Parent] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)
 
ALTER TABLE [dbo].[Child] WITH CHECK 
  ADD CONSTRAINT [FK_Child_Parent] FOREIGN KEY([ID_PARENT])
    REFERENCES [dbo].[Parent] ([ID])

As you can see there is Parent table and Child table and a foreign key between these two. Both tables of the database were filled with over 100k of random records.

Now introducing the contestants:

  1. (ADO) Bare ADO.NET SqlDataReader which materializes objects by fetching columns from the data reader and creating new instances manually
  2. (Linq2SQL) A Linq2SQL data context created from the database by sqlmetal.exe
  3. (EF5 Model First) A EF5 Object Context created from the database by using the designer
  4. (EF5 Code First) A EF5 DbContext created manually with entities created manually to match the database structure
  5. (nHibernate) A nHibernate model created manually to match the database structure

I am gonna implement tests for all contestants using C#+VS2012. Each test will implement a simple interface so that I can create and run them in a single environment:

public interface IPerformanceTest
{
    string Category { get; }
    string Name     { get; }
 
    void PerformTest( out DateTime StartedAt, out DateTime EndedAt );
}
The idea of my tests it not only just to select the data but perform selects to fetch TOP 1, 10, 100, 1000 and 10000 entities using Linq where applicable. The assumption is that no matter which tool you use, you expect a consistent query language, Linq.

Also, because selecting 1 or 10 records takes is too quick to measure reliably, my test runner will repeat tests 1000 times. Because of this, it will probably be possible to observe how different query mechanisms behave when the number of fetched rows changes.

As for the test environment – it is Win7x64 with SQL Server 2012, 8GB RAM and 4 core i7 processor. Tests will be performed on .NET 4.5 in Release mode, the runner is executed from the OS shell directly rather than from VS2012.

In the next post I will show how all tests are implemented. Then, in the 3rd post we will analyze and comment the results.

Monday, May 13, 2013

Viewing Generated Proxy Code for Entity Framework 5 Code First

There is an old post by David DeWinter which shows how to see the proxy code generated by EF. The information is a little bit outdated or at least, there is no information on how to do the same for Code First approach.

The problem stems from the fact that David uses the CreateProxyTypes method which is not available on the DbContext class.

There are two possible approaches to get the same result (an assembly containing all your proxy types) for Code First’s DbContext.

An easiest approach is to switch the AssemblyBuilderAccess strategy just before you access any of your data. Then execute a linq statement on one of your DbSets and the proxy will automatically be created and thus – it can be persisted.

// this assumes that ctx is of type DbContext
ctx = new YourDbContext();
 
// switch the strategy to allow the assembly to be persisted
Type entityProxyFactoryType = Type.GetType(
     "System.Data.Objects.Internal.EntityProxyFactory, " + 
     typeof( ObjectContext ).Assembly.FullName );
 
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
entityProxyFactoryType.GetField( "s_ProxyAssemblyBuilderAccess", bindingFlags )
     .SetValue( null, AssemblyBuilderAccess.RunAndSave );
 
// this forces the proxy to be created
foreach ( var entity in ctx.OneOfYourDbSets )
{
}
 
var moduleBuilders = (IDictionary<Assembly, ModuleBuilder>)
    entityProxyFactoryType.GetField( "s_ModuleBuilders", bindingFlags ).GetValue( null );
 
var pocoProxyModule = moduleBuilders[typeof( YourDbContext ).Assembly];
var pocoProxyAssembly = (AssemblyBuilder)pocoProxyModule.Assembly;
 
pocoProxyAssembly.Save( "EntityProxyModule.dll" );

This method has one disadvantage – the persisted assembly doesn’t contain all possible proxies but rather – only these proxies that have been created so far (OneOfYourDbSets in the above snippet).

A difficult approach is to get deeply under the hood of the DbContext and fix David’s code to still work for this scenario:

var ctx = new YourDbContext(); 
 
Type entityProxyFactoryType = Type.GetType(
    "System.Data.Objects.Internal.EntityProxyFactory, " + 
    typeof( ObjectContext ).Assembly.FullName );
 
const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
entityProxyFactoryType.GetField( "s_ProxyAssemblyBuilderAccess", bindingFlags )
    .SetValue( null, AssemblyBuilderAccess.RunAndSave );
 
// dig deeply to the internal ObjectContext in the DbContext
var changeTracker = ctx.ChangeTracker;
object _internalContext = changeTracker.GetType().InvokeMember( "_internalContext", 
    BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance, null, changeTracker , null );
object _objectContext = _internalContext.GetType().InvokeMember( "ObjectContext", 
    BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance, null, _internalContext, null );
 
ObjectContext objectContext = _objectContext as ObjectContext;
 
objectContext.CreateProxyTypes( Assembly.GetExecutingAssembly().GetTypes() );
 
var moduleBuilders = (IDictionary<Assembly, ModuleBuilder>)
    entityProxyFactoryType.GetField( "s_ModuleBuilders", bindingFlags ).GetValue( null );
 
var pocoProxyModule = moduleBuilders[typeof( YourDbContext ).Assembly];
var pocoProxyAssembly = (AssemblyBuilder)pocoProxyModule.Assembly;
 
pocoProxyAssembly.Save( "EntityProxyModule.dll" );

In both cases, the generated assembly can be inspected with any IlSpy-like tool.

Monday, May 6, 2013

Entity Framework 5 Code First Multi-Tenancy with Migrations

The Entity Framework 5 Code First Migrations mechanism works great, however there is a small issue regarding multi tenant applications where the same DbContext is used to connect to multiple databases with the same schema.

To be able to address multiple databases with the same schema, you could have two constructors:

public class MyDbContext : DbContext
{
   public MyDbContext() : 
      base( defaultconnectionstring )
   {
   }
 
   public MyDbContext( string ConnectionString ) : 
      base( ConnectionString )
   {
   }
}

or have a single, parameterless constructor but set the connection string after a context has been created. In both cases, the default parameterless constructor will always somehow point to a concrete, default database.

This raises following problem - the MigrateDatabaseToLatestVersion initializer creates your context using the default parameterless dbcontext constructor. It will migrate the database but only the default one! It seems that people report this issue.

To fix this, we need a modified database initializer. The initializer should migrate the current database rather than the default one. It means that the initializer should get the connection string from the current context somehow. Luckily, this is possible:

// an example code first data context
public class MasterDetailContext : DbContext
{
    public DbSet<Detail> Detail { get; set; }
    public DbSet<Master> Master { get; set; }
 
    // this one is used by DbMigrator but the client code will not use it
    public MasterDetailContext()
    {
        Database.Initialize( false );
    }
 
    // rather - the client code will use this one
    public MasterDetailContext( string ConnectionString ) : base( ConnectionString )
    {
        Database.SetInitializer( new CustomInitializer() );
        Database.Initialize( false );
    }
 
    protected override void  OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }
}
 
public class CustomInitializer : 
   IDatabaseInitializer<MasterDetailContext>
{
 
    #region IDatabaseInitializer<MasterDetailContext> Members
 
    // fix the problem with MigrateDatabaseToLatestVersion 
    // by copying the connection string FROM the actual context!
    public void InitializeDatabase( MasterDetailContext context )
    {            
        Configuration cfg = new Configuration(); // migration configuration class
        cfg.TargetDatabase = 
           new DbConnectionInfo( 
              context.Database.Connection.ConnectionString, 
              "System.Data.SqlClient" );
 
        DbMigrator dbMigrator = new DbMigrator( cfg );
        // this will call the parameterless constructor of the datacontext
        // but the connection string from above will be then set on in
        dbMigrator.Update();             
    }
 
    #endregion
}

The client code is now:

// Connect to two different schemas using the same context
// Use sql profier to see how both databases are migrated
using ( MasterDetailContext ctx = 
   new MasterDetailContext( @"Database=Database01;Server=.\SQL2012;Integrated Security=true" ) )
{
}
 
using ( MasterDetailContext ctx = 
   new MasterDetailContext( @"Database=Database02;Server=.\SQL2012;Integrated Security=true" ) )
{
}

Compare our new custom initializer with the existing MigrateDatabaseToLatestVersion initializer:

// The builtin initializer class
public class MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration> : 
   IDatabaseInitializer<TContext> 
      where TContext : DbContext 
      where TMigrationsConfiguration : DbMigrationsConfiguration<TContext>, new()
{
   private readonly DbMigrationsConfiguration _config;
 
   public MigrateDatabaseToLatestVersion()
   {
      // creates the migrations configuration instance
      this._config = Activator.CreateInstance<TMigrationsConfiguration>();
   }
 
   public void InitializeDatabase(TContext context)
   {
      // migrates the default database (doesn't use context!)
      DbMigrator dbMigrator = new DbMigrator(this._config);
      dbMigrator.Update();
   }   
}

Differences are obvious.

The built in initializer uses reflection to create the instance of the migrations configurator and asks DbMigrator to perform the update but it doesn’t ask it for the connection to the current database! Instead, the configurator by itself creates a new instance of the DbContext using the default parameterless constructor. On the other hand, our custom initializer uses the information on the context to set the configurator’s TargetDatabase to point to a current database.

This way, multiple databases can be migrated independently.