Exemple #1
0
        protected override bool execute(IDocumentStore store, PatchInput input)
        {
            try
            {
                store.Schema.AssertDatabaseMatchesConfiguration();


                input.WriteLine(ConsoleColor.Green, "No differences were detected between the Marten configuration and the database");

                return(true);
            }
            catch (SchemaValidationException)
            {
                var patch = store.Schema.ToPatch(input.SchemaFlag);

                input.WriteLine(ConsoleColor.Green, "Wrote a patch file to " + input.FileName);
                patch.WriteUpdateFile(input.FileName);


                var dropFile = input.DropFlag ?? SchemaPatch.ToDropFileName(input.FileName);

                input.WriteLine(ConsoleColor.Green, "Wrote the drop file to " + dropFile);
                patch.WriteRollbackFile(dropFile);

                return(true);
            }
        }
Exemple #2
0
        /// <summary>
        /// Called when [execute].
        /// </summary>
        /// <returns>System.Int32.</returns>
        public int OnExecute()
        {
            try
            {
                _store.Schema.AssertDatabaseMatchesConfiguration();
                _logger.LogInformation(
                    "No differences were detected between the Marten configuration and the database"
                    );

                return(0);
            }
            catch (SchemaValidationException)
            {
                var patch = _store.Schema.ToPatch(Schema, AutoCreateAll);

                _logger.LogInformation("Wrote a patch file to {FileName}", FileName);
                patch.WriteUpdateFile(FileName, TransactionalScript);

                var dropFile = Drop ?? SchemaPatch.ToDropFileName(FileName);

                _logger.LogInformation("Wrote the drop file to {DropFile}", dropFile);
                patch.WriteRollbackFile(dropFile, TransactionalScript);

                return(0);
            }
        }
Exemple #3
0
        public void WritePatch(string filename, bool withSchemas = true)
        {
            if (!Path.IsPathRooted(filename))
            {
                filename = AppContext.BaseDirectory.AppendPath(filename);
            }

            var patch = ToPatch(withSchemas);

            patch.WriteUpdateFile(filename);

            var dropFile = SchemaPatch.ToDropFileName(filename);

            patch.WriteRollbackFile(dropFile);
        }
Exemple #4
0
        public void WritePatch(string filename, bool withSchemas = true, bool transactionalScript = true)
        {
            if (!Path.IsPathRooted(filename))
            {
                filename = AppContext.BaseDirectory.AppendPath(filename);
            }

            var patch = ToPatch(withSchemas, withAutoCreateAll: true);

            patch.WriteUpdateFile(filename, transactionalScript);

            var dropFile = SchemaPatch.ToDropFileName(filename);

            patch.WriteRollbackFile(dropFile, transactionalScript);
        }
 public void translates_the_file_name()
 {
     SchemaPatch.ToDropFileName("update.sql").ShouldBe("update.drop.sql");
     SchemaPatch.ToDropFileName("1.update.sql").ShouldBe("1.update.drop.sql");
     SchemaPatch.ToDropFileName("folder\\1.update.sql").ShouldBe("folder\\1.update.drop.sql");
 }