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();
                }
            }
        }
Beispiel #2
0
        protected override void Execute(SchemaMetadataElement metadataElement)
        {
            var entities = _contextEntityTypesProvider.GetTypesFromContext(metadataElement.Context);

            using (var dataConnection = _dataConnectionFactory.CreateConnection(metadataElement))
            {
                var sqlSchemaService = new SqlSchemaService(dataConnection);
                sqlSchemaService.CreateTables(entities);
            }
        }
        private void InitializeMappingSchema(MappingSchema schema, Lock @lock)
        {
            using (var scope = CreateTransaction())
                using (var db = new DataConnection("Messages").AddMappingSchema(schema))
                {
                    var service = new SqlSchemaService(db);
                    service.CreateTablesWithIndices(schema, _dataObjectTypes);

                    @lock.IsNew = false;
                    db.Update(@lock);

                    scope.Complete();
                }
        }
Beispiel #4
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();
        }
Beispiel #5
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();
                }
        }
Beispiel #6
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();
                }
            }
        }