Exemple #1
0
        public void WritePatchByType(string directory)
        {
            var system = new FileSystem();

            system.DeleteDirectory(directory);
            system.CreateDirectory(directory);

            var features = _features.AllActiveFeatures(_tenant).ToArray();

            writeDatabaseSchemaGenerationScript(directory, system, features);

            using (var conn = _tenant.CreateConnection())
            {
                conn.Open();

                foreach (var feature in features)
                {
                    var patch = new SchemaPatch(StoreOptions.DdlRules);
                    patch.Apply(conn, AutoCreate.CreateOrUpdate, feature.Objects);

                    if (patch.UpdateDDL.IsNotEmpty())
                    {
                        var file = directory.AppendPath(feature.Identifier + ".sql");
                        patch.WriteUpdateFile(file);
                    }
                }
            }
        }
Exemple #2
0
        private void generateOrUpdateFeature(Type featureType, IFeatureSchema feature)
        {
            lock (_updateLock)
            {
                using (var conn = _factory.Create())
                {
                    conn.Open();

                    var patch = new SchemaPatch(_options.DdlRules);
                    patch.Apply(conn, _options.AutoCreateSchemaObjects, feature.Objects);
                    patch.AssertPatchingIsValid(_options.AutoCreateSchemaObjects);

                    var ddl = patch.UpdateDDL;
                    if (patch.Difference != SchemaPatchDifference.None && ddl.IsNotEmpty())
                    {
                        var cmd = conn.CreateCommand(ddl);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            _options.Logger().SchemaChange(ddl);
                            RegisterCheck(featureType, feature);
                        }
                        catch (Exception e)
                        {
                            throw new MartenCommandException(cmd, e);
                        }
                    }
                    else if (patch.Difference == SchemaPatchDifference.None)
                    {
                        RegisterCheck(featureType, feature);
                    }
                }
            }
        }
Exemple #3
0
        private void writeAndApplyPatch(AutoCreate autoCreate, DocumentTable table)
        {
            var patch = new SchemaPatch(new DdlRules());

            patch.Apply(_conn, autoCreate, new ISchemaObject[] { table });

            _conn.CreateCommand(patch.UpdateDDL).ExecuteNonQuery();
        }
Exemple #4
0
        public void determine_that_it_is_missing()
        {
            var patch = new SchemaPatch(new DdlRules());

            patch.Apply(_conn, AutoCreate.All, theSequence);

            patch.Difference.ShouldBe(SchemaPatchDifference.Create);
        }
Exemple #5
0
        public void determine_that_it_is_already_there()
        {
            can_create_sequence_without_blowing_up();

            var patch = new SchemaPatch(new DdlRules());

            patch.Apply(_conn, AutoCreate.All, theSequence);

            patch.Difference.ShouldBe(SchemaPatchDifference.None);
        }
        private void writeAndApplyPatch(AutoCreate autoCreate, DocumentTable table)
        {
            var patch = new SchemaPatch(new DdlRules());

            patch.Apply(_conn, autoCreate, new ISchemaObject[] { table });

            var updateDDL = patch.UpdateDDL;

            if (!string.IsNullOrEmpty(updateDDL))
            {
                _conn.CreateCommand(updateDDL).ExecuteNonQuery();
            }
        }
Exemple #7
0
        public SchemaPatch ToPatch(Type documentType)
        {
            var mapping = _features.MappingFor(documentType);

            var patch = new SchemaPatch(StoreOptions.DdlRules);

            using (var conn = _tenant.CreateConnection())
            {
                conn.Open();

                patch.Apply(conn, AutoCreate.CreateOrUpdate, mapping.As <IFeatureSchema>().Objects);
            }

            return(patch);
        }
Exemple #8
0
        public SchemaPatch ToPatch(bool withSchemas = true)
        {
            var patch = new SchemaPatch(StoreOptions.DdlRules);

            if (withSchemas)
            {
                var allSchemaNames = StoreOptions.Storage.AllSchemaNames();
                DatabaseSchemaGenerator.WriteSql(StoreOptions, allSchemaNames, patch.UpWriter);
            }

            var @objects = _features.AllActiveFeatures(_tenant).SelectMany(x => x.Objects).ToArray();

            using (var conn = _tenant.CreateConnection())
            {
                conn.Open();

                patch.Apply(conn, StoreOptions.AutoCreateSchemaObjects, @objects);
            }

            return(patch);
        }