Disclaimer: This website requires JavaScript to function properly. Some features may not work as expected. Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Install database schema

Describes how to install database schema.

Optimizely uses Microsoft SQL Server to store content and other information created in the system. Optimizely supports database editions, including SQL Azure. See the System requirements for Optimizely for specific versions of SQL Server that Optimizely supports.

Install from the Visual Studio integration

A database schema is a way to logically group objects in the database, such as tables, views, and stored procedures. When you create a site from the Visual Studio integration, it automatically creates the database with the Optimizely schema. Each version of the database schema targets a specific version of the product. The following topics show how to deploy a database from development to production.

Install on an empty database

If you must install database schema on an empty database, see create site by template/cli.

Enable automatic creation of database schemas

You can also configure a site to create the database schema automatically during site initialization. When the site starts up, Optimizely checks if the schema is installed in the current database as specified by the connection string. If no schema is found and automatic creation is enabled, it executes an SQL script that adds the schema to the database.

To enable automatic schema creation, add attribute CreateDatabaseSchema": "true" to the appsetting.json:

{
  "EpiServer": {
    "Cms": {
      "DataAccess": {
        "CreateDatabaseSchema": "true"
      }
    }
  }
}

or it can be configured by code like this:

public class Startup {
  public void ConfigureServices(IServiceCollection services) {
    services.Configure<DataAccessOptions>(o => {
      o.CreateDatabaseSchema = true;
    });
  }
}

The automatic schema creation is done using the same process as schema updates, and it lets you interact with the schema creation process by registering an implementation of IDatabaseSchemaValidator in the Optimizely IOC container. See Automatic schema updates.

Create database manually

If you want to deploy the schema manually, you find the SQL script files in the EPiServer.CMS.Core NuGet package under the tools subfolder.

Best practices when setting up the database

Consider the following recommendations:

  • When upgrading, you should never directly access the tables or stored procedures in the database or create custom tables that interfere with the tables created by CMS. You should use the documented API instead because backward compatibility on the database level is not guaranteed.
  • CMS supports several SQL Server high-availability options for the database's availability and performance, including fail-over clustering and database mirroring. For instance, database mirroring retrieves a "hot" standby database that operates in read-only mode, and transactions are copied to the mirror synchronously or asynchronously. You can configure instant fail-over using a "witness" server.
  • When you run an SQL Server in production, create a maintenance plan for the database, including backup, checking database consistency, and rebuilding indexes. The performance of the database degrades over time if you do not create a maintenance plan, especially if indexes are never rebuilt because the query speed degrades as content is added. For information, see Microsoft: Maintenance Plans.