Пример #1
0
        protected override async Task <bool> execute(IDocumentStore store, PatchInput input)
        {
            try
            {
                await store.Schema.AssertDatabaseMatchesConfigurationAsync().ConfigureAwait(false);

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

                return(true);
            }
            catch (SchemaValidationException)
            {
                var patch = await store.Schema.CreateMigrationAsync().ConfigureAwait(false);

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

                var rules = store.Options.As <StoreOptions>().Advanced.DdlRules;
                rules.IsTransactional = input.TransactionalScriptFlag;

                rules.WriteTemplatedFile(input.FileName, (r, w) => patch.WriteAllUpdates(w, r, AutoCreate.CreateOrUpdate));

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

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

                rules.WriteTemplatedFile(dropFile, (r, w) => patch.WriteAllRollbacks(w, r));

                return(true);
            }
        }
Пример #2
0
        public async Task WriteMigrationFileAsync(string filename)
        {
            if (!Path.IsPathRooted(filename))
            {
                filename = AppContext.BaseDirectory.AppendPath(filename);
            }

            var patch = await CreateMigrationAsync();

            DdlRules.WriteTemplatedFile(filename, (r, w) =>
            {
                patch.WriteAllUpdates(w, r, AutoCreate.All);
            });

            var dropFile = SchemaMigration.ToDropFileName(filename);

            DdlRules.WriteTemplatedFile(dropFile, (r, w) =>
            {
                patch.WriteAllRollbacks(w, r);
            });
        }
Пример #3
0
 public void translates_the_file_name()
 {
     SchemaMigration.ToDropFileName("update.sql").ShouldBe("update.drop.sql");
     SchemaMigration.ToDropFileName("1.update.sql").ShouldBe("1.update.drop.sql");
     SchemaMigration.ToDropFileName("folder\\1.update.sql").ShouldBe("folder\\1.update.drop.sql");
 }