public virtual void CommitConfiguration([NotNull] IConfigurationSourceContainer configuration) { Check.NotNull(configuration, "configuration"); var configFile = configuration.Get(Constants.ConfigFileOption); if (string.IsNullOrEmpty(configFile)) { configFile = Constants.DefaultConfigFile; } configFile = ResolvePath(configFile); var iniFileConfigurationSource = CreateIniFileConfigurationSource(configFile); if (!File.Exists(configFile)) { WriteFile(configFile, CreateEmptyConfiguration(), true); } iniFileConfigurationSource.Load(); foreach (var key in GetCommitableSettings()) { var value = configuration.Get(key); if (!string.IsNullOrEmpty(value)) { iniFileConfigurationSource.Set(key, value); } } iniFileConfigurationSource.Commit(); }
// Internal for testing. protected internal virtual DbContext LoadContext(IConfigurationSourceContainer configuration) { var contextAssemblyRef = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyRef)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var contextTypeName = configuration.Get(Constants.ContextTypeOption); return(LoadContext(contextAssemblyRef, contextTypeName)); }
public virtual ScaffoldedMigration CreateMigration([NotNull] IConfigurationSourceContainer configuration) { Check.NotNull(configuration, "configuration"); var migrationName = configuration.Get(Constants.MigrationNameOption); if (string.IsNullOrEmpty(migrationName)) { throw new InvalidOperationException(Strings.MigrationNameNotSpecified); } var migrationDirectory = configuration.Get(Constants.MigrationDirectoryOption); var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyFile)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var references = configuration.Get(Constants.ReferencesOption); var contextTypeName = configuration.Get(Constants.ContextTypeOption); var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption); var migrationNamespace = configuration.Get(Constants.MigrationNamespaceOption); return(CreateMigration( migrationName, contextAssemblyFile, migrationDirectory, references, contextTypeName, migrationAssemblyFile, migrationNamespace)); }
// TODO: Add support for --SourceMigration // TODO: Add support for --Verbose public virtual void UpdateDatabase([NotNull] IConfigurationSourceContainer configuration) { Check.NotNull(configuration, "configuration"); var targetMigrationName = configuration.Get(Constants.TargetMigrationOption); var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyFile)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var references = configuration.Get(Constants.ReferencesOption); var contextTypeName = configuration.Get(Constants.ContextTypeOption); var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption); var migrationNamespace = configuration.Get(Constants.MigrationNamespaceOption); UpdateDatabase( contextAssemblyFile, targetMigrationName, references, contextTypeName, migrationAssemblyFile, migrationNamespace); }
// TODO: Add support for --SourceMigration public virtual IReadOnlyList <SqlStatement> GenerateScript([NotNull] IConfigurationSourceContainer configuration) { Check.NotNull(configuration, "configuration"); var targetMigrationName = configuration.Get(Constants.TargetMigrationOption); var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyFile)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var references = configuration.Get(Constants.ReferencesOption); var contextTypeName = configuration.Get(Constants.ContextTypeOption); var migrationAssemblyFile = configuration.Get(Constants.MigrationAssemblyOption); var migrationNamespace = configuration.Get(Constants.MigrationNamespaceOption); return(GenerateScript( contextAssemblyFile, targetMigrationName, references, contextTypeName, migrationAssemblyFile, migrationNamespace)); }
public virtual IReadOnlyList <IMigrationMetadata> GetMigrations([NotNull] IConfigurationSourceContainer configuration) { Check.NotNull(configuration, "configuration"); var source = configuration.Get(Constants.MigrationSourceOption); var contextAssemblyRef = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyRef)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var contextTypeName = configuration.Get(Constants.ContextTypeOption); var migrationAssemblyRef = configuration.Get(Constants.MigrationAssemblyOption); var migrationNamespace = configuration.Get(Constants.MigrationNamespaceOption); return(GetMigrations( contextAssemblyRef, source, contextTypeName, migrationAssemblyRef, migrationNamespace)); }
// Internal for testing. protected internal virtual DbContext LoadContext(IConfigurationSourceContainer configuration) { var contextAssemblyFile = configuration.Get(Constants.ContextAssemblyOption); if (string.IsNullOrEmpty(contextAssemblyFile)) { throw new InvalidOperationException(Strings.ContextAssemblyNotSpecified); } var references = configuration.Get(Constants.ReferencesOption); var contextTypeName = configuration.Get(Constants.ContextTypeOption); return LoadContext(contextAssemblyFile, references, contextTypeName); }