src/Shared/EntityFramework/Migrations/Infrastructure/MigratorScriptingDecorator.cs
/// <summary>
/// Produces a script to update the database.
/// </summary>
/// <param name="sourceMigration">
/// The migration to update from. If null is supplied, a script to update the
/// current database will be produced.
/// </param>
/// <param name="targetMigration">
/// The migration to update to. If null is supplied,
/// a script to update to the latest migration will be produced.
/// </param>
/// <returns> The generated SQL script. </returns>
Produces a script to update the database.
Produces a script to update the database .
public string ScriptUpdate(string sourceMigration, string targetMigration)
        {
            _sqlBuilder.Clear();
            if (string.IsNullOrWhiteSpace(sourceMigration))
            {
                Update(targetMigration);
            }
            else
            {
                if (sourceMigration.IsAutomaticMigration())
                {
                    throw Error.AutoNotValidForScriptWindows(sourceMigration);
                }
                var sourceMigrationId = GetMigrationId(sourceMigration);
                var pendingMigrations = GetLocalMigrations().Where(m => string.CompareOrdinal(m, sourceMigrationId) > 0);
                string targetMigrationId = null;
                if (!string.IsNullOrWhiteSpace(targetMigration))
                {
                    if (targetMigration.IsAutomaticMigration())
                    {
                        throw Error.AutoNotValidForScriptWindows(targetMigration);
                    }
                    targetMigrationId = GetMigrationId(targetMigration);
                    if (string.CompareOrdinal(sourceMigrationId, targetMigrationId) > 0)
                    {
                        throw Error.DownScriptWindowsNotSupported();
                    }
                    pendingMigrations = pendingMigrations.Where(m => string.CompareOrdinal(m, targetMigrationId) <= 0);
                }
                _updateDatabaseOperation
                    = sourceMigration == DbMigrator.InitialDatabase
                          ? new UpdateDatabaseOperation(base.CreateDiscoveryQueryTrees().ToList())
                          : null;
                Upgrade(pendingMigrations, targetMigrationId, sourceMigrationId);
                if (_updateDatabaseOperation != null)
                {
                    ExecuteStatements(base.GenerateStatements(new[] { _updateDatabaseOperation }, null));
                }
            }
            return _sqlBuilder.ToString();
        }
public string ScriptUpdate ( string sourceMigration , string targetMigration ) { _sqlBuilder . Clear ( ) ; if ( string . IsNullOrWhiteSpace ( sourceMigration ) ) { Update ( targetMigration ) ; } else { if ( sourceMigration . IsAutomaticMigration ( ) ) { throw Error . AutoNotValidForScriptWindows ( sourceMigration ) ; } var sourceMigrationId = GetMigrationId ( sourceMigration ) ; var pendingMigrations = GetLocalMigrations ( ) . Where ( m => string . CompareOrdinal ( m , sourceMigrationId ) > 0 ) ; string targetMigrationId = null ; if ( ! string . IsNullOrWhiteSpace ( targetMigration ) ) { if ( targetMigration . IsAutomaticMigration ( ) ) { throw Error . AutoNotValidForScriptWindows ( targetMigration ) ; } targetMigrationId = GetMigrationId ( targetMigration ) ; if ( string . CompareOrdinal ( sourceMigrationId , targetMigrationId ) > 0 ) { throw Error . DownScriptWindowsNotSupported ( ) ; } pendingMigrations = pendingMigrations . Where ( m => string . CompareOrdinal ( m , targetMigrationId ) <= 0 ) ; } _updateDatabaseOperation = sourceMigration == DbMigrator . InitialDatabase ? new UpdateDatabaseOperation ( base . CreateDiscoveryQueryTrees ( ) . ToList ( ) ) : null ; Upgrade ( pendingMigrations , targetMigrationId , sourceMigrationId ) ; if ( _updateDatabaseOperation != null ) { ExecuteStatements ( base . GenerateStatements ( new [ ] { _updateDatabaseOperation } , null ) ) ; } } return _sqlBuilder . ToString ( ) ; }
Produces a script to update the database.
Produces a script to update the database .
The generated SQL script.
The generated SQL script .
sourceMigration
string
The migration to update from. If null is supplied, a script to update the
current database will be produced.
The migration to update from . If null is supplied a script to update the current database will be produced .
targetMigration
string
The migration to update to. If null is supplied,
a script to update to the latest migration will be produced.
The migration to update to . If null is supplied a script to update to the latest migration will be produced .