/// <summary> /// Generates C# files from the supplied view definitions /// </summary> /// <param name="context">The context that defines how the migrations should be created</param> /// <param name="viewDefinitions">The view definitions that are the source for thr migration</param> private static void GenerateViewMigrations(SchemaMigrationContext context, IList<ViewDefinition> viewDefinitions) { var mockDumper = new Mock<ISchemaDumper>(); var writer = new CSharpViewMigrationsWriter(new DebugAnnouncer()); mockDumper.Setup(m => m.ReadViews()).Returns(viewDefinitions); writer.GenerateMigrations(context, mockDumper.Object); }
/// <summary> /// Generates schema migrations from the datasource as C# source code /// </summary> /// <param name="context">Define data required to generate the C# migrations</param> public void Generate(SchemaMigrationContext context) { Announcer.AnnounceTime = context.AnnounceTime; Announcer.Say(string.Format("Generating schema {0} migrations from {1}", context.Type, context.FromConnectionString)); using (var connection = GetConnection(context)) { var processor = GetProcessor(connection); var schemaDumper = GetSchemaDumper(processor); if (context.MigrationRequired(MigrationType.Tables) || context.MigrationRequired(MigrationType.Indexes) || context.MigrationRequired(MigrationType.Data) || context.MigrationRequired(MigrationType.ForeignKeys)) { var tables = new CSharpTableMigrationsWriter(Announcer); tables.GenerateMigrations(context, schemaDumper); } if (context.MigrationRequired(MigrationType.Procedures)) { var procedures = new CSharpProcedureMigrationsWriter(Announcer); procedures.GenerateMigrations(context, schemaDumper); } if (context.MigrationRequired(MigrationType.Functions)) { var functions = new CSharpFunctionMigrationsWriter(Announcer); functions.GenerateMigrations(context, schemaDumper); } // Migrate the views last as procedures or functions may be included in them if (context.MigrationRequired(MigrationType.Views)) { var views = new CSharpViewMigrationsWriter(Announcer); views.GenerateMigrations(context, schemaDumper); } } }