public void DropWebAppSchema(SchemaInitializationCommand command)
        {
            var excludeTableNames = command.DataTypes
                                    .Select(x => command.MappingSchema.GetAttribute <TableAttribute>(x))
                                    .Select(x => x.Name)
                                    .ToHashSet(StringComparer.OrdinalIgnoreCase);

            using (var dataConnection = CreateDataConnection(command.ConnectionStringIdentity, command.MappingSchema))
            {
                var service   = new SqlSchemaService(dataConnection);
                var allTables = service.AllTables();

                var tablesToDelete = allTables
                                     .Where(x => command.SqlSchemas.Contains(x.SchemaName))
                                     .Where(x => !excludeTableNames.Contains(x.TableName));

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    service.DropTables(tablesToDelete);
                    scope.Complete();
                }
            }
        }
コード例 #2
0
        private DataConnection CreateDataConnection(SchemaInitializationCommand command)
        {
            var connectionString = _connectionStringSettings.GetConnectionString(command.ConnectionStringIdentity);
            var connection       = SqlServerTools.CreateDataConnection(connectionString);

            connection.AddMappingSchema(command.MappingSchema);
            return(connection);
        }
コード例 #3
0
        private void ExecuteCommand(SchemaInitializationCommand cmd)
        {
            using var db = CreateDataConnection(cmd);
            var service = new SqlSchemaService(db);

            using var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted });

            // stateinit в классическом понимании сломан
            // теперь не удаляются все таблицы в схеме
            // механизм недо-stateinit должен быть заменён полноценным migrations engine
            service.DropTables(cmd.DataTypes);

            service.CreateTables(cmd.DataTypes);
            scope.Complete();
        }
コード例 #4
0
        private void ExecuteCommand(SchemaInitializationCommand cmd)
        {
            using (var db = CreateDataConnection(cmd))
                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    var service = new SqlSchemaService(db);
                    foreach (var schema in cmd.SqlSchemas)
                    {
                        service.DeleteAllTablesInSchema(schema);
                    }

                    service.CreateTablesWithIndices(cmd.MappingSchema, cmd.DataTypes);
                    scope.Complete();
                }
        }
コード例 #5
0
        private void ExecuteCommand(SchemaInitializationCommand cmd)
        {
            using (var db = CreateDataConnection(cmd))
            {
                var service   = new SqlSchemaService(db);
                var allTables = service.AllTables();

                var tablesToDelete = allTables
                                     .Where(x => cmd.SqlSchemas.Contains(x.SchemaName));

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                }))
                {
                    service.DropTables(tablesToDelete);
                    service.CreateTables(cmd.DataTypes);
                    scope.Complete();
                }
            }
        }