コード例 #1
0
        private void UpdateDatabase(MigrateInput input, IServiceProvider serviceProvider)
        {
            var runner = serviceProvider.GetRequiredService <IMigrationRunner>();

            switch (input.Direction)
            {
            case MigrateInput.MigrationDirection.Down:
                if (input.VersionFlag.HasValue)
                {
                    runner.MigrateDown(input.VersionFlag.Value);
                }
                else
                {
                    runner.Rollback(1);
                }
                break;

            case MigrateInput.MigrationDirection.Up:
                if (input.VersionFlag.HasValue)
                {
                    runner.MigrateUp(input.VersionFlag.Value);
                }
                else
                {
                    runner.MigrateUp();
                }
                break;
            }
        }
コード例 #2
0
        public override bool Execute(MigrateInput input)
        {
            string connectionString;

            using (var host = input.BuildHost())
            {
                var configuration = host.Services.GetRequiredService <IConfiguration>();
                connectionString = configuration.GetConnectionString("Default");
            }

            var serviceProvider = CreateServices(connectionString);

            using (var scope = serviceProvider.CreateScope())
            {
                UpdateDatabase(input, scope.ServiceProvider);
            }

            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Migrate item.
 /// </summary>
 /// <remarks>
 /// The operation to initiate migration of the item.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Protection container name.
 /// </param>
 /// <param name='migrationItemName'>
 /// Migration item name.
 /// </param>
 /// <param name='migrateInput'>
 /// Migrate input.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <MigrationItem> BeginMigrateAsync(this IReplicationMigrationItemsOperations operations, string fabricName, string protectionContainerName, string migrationItemName, MigrateInput migrateInput, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginMigrateWithHttpMessagesAsync(fabricName, protectionContainerName, migrationItemName, migrateInput, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #4
0
 /// <summary>
 /// Migrate item.
 /// </summary>
 /// <remarks>
 /// The operation to initiate migration of the item.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='fabricName'>
 /// Fabric name.
 /// </param>
 /// <param name='protectionContainerName'>
 /// Protection container name.
 /// </param>
 /// <param name='migrationItemName'>
 /// Migration item name.
 /// </param>
 /// <param name='migrateInput'>
 /// Migrate input.
 /// </param>
 public static MigrationItem BeginMigrate(this IReplicationMigrationItemsOperations operations, string fabricName, string protectionContainerName, string migrationItemName, MigrateInput migrateInput)
 {
     return(operations.BeginMigrateAsync(fabricName, protectionContainerName, migrationItemName, migrateInput).GetAwaiter().GetResult());
 }