/// <summary> /// Enables the ability for that project to be able to use NHibernate Repo migrations, automatic or manual. /// </summary> public void EnableMigrations(EnableMigrationsCriteria criteria) { MessageFilter.Register(); var repoInfo = TypeHandler.FindSingleRepo(criteria.ProjectPath, criteria.RepoName); //if it is null something is wrong so drop out. if (repoInfo == null) { return; } AssertRepoHasEmptyConstructor(repoInfo.RepoType); EnsureDbAndMigrationTableExists(criteria.ProjectPath, repoInfo.RepoType, criteria.ConfigFilePath); var repoBase = TypeHandler.CreateRepoBase(repoInfo.Assembly.Location, repoInfo.RepoType); //create migration log table, if it doesn't exist. var updater = CreateSchemaUpdater(criteria.ProjectPath, typeof(MigrationRepo), criteria.ConfigFilePath, repoBase.ConnectionStringOrName); updater.Execute(true, true); bool multipleFound = false; var configType = TypeHandler.FindSingleConfiguration(criteria.ProjectPath, repoInfo.RepoType, out multipleFound); //this should not happen. should only ever have one config per repo type. if (multipleFound) { return; } if (configType == null) { LoggerBase.Log("Adding migration configuration"); var filePath = new ConfigurationFileHandler().CreateConfigurationFile(criteria.ProjectPath, repoInfo.RepoType.Name, "Migrations", MigrationToUse.Manual); new ProjectDteHelper().AddFile(criteria.ProjectPath, "Migrations", filePath, showFile: true); } else { LoggerBase.Log("System is already configured for migrations, see class: " + configType.Name); } //clean up ProjectEvalutionHelper.FinishedWithProject(criteria.ProjectPath); MessageFilter.Revoke(); }
private ConfigurationStatus GetMigrationConfigurationStatus(string projectPath, string optionalRepo) { var status = new ConfigurationStatus(); var configObject = TypeHandler.FindConfiguration(projectPath, optionalRepo); if (configObject == null) { status.Enabled = false; return(status); } status.Enabled = configObject.Enabled; status.MigrationType = configObject.MigrationType; return(status); }
/// <summary> /// Ensures that the migration database exists. /// </summary> /// <param name="projectdllPath"></param> /// <param name="repoType"></param> /// <param name="configFilePath"></param> /// <param name="args"></param> private void CreateRepoDatabase(string projectdllPath, Type repoType, string configFilePath, params object[] args) { var repoBase = TypeHandler.CreateRepoBase(projectdllPath, repoType, args); var connectionString = ConnectionStringHandler.FindConnectionString(repoBase, configFilePath); var builder = new System.Data.SqlClient.SqlConnectionStringBuilder { ConnectionString = connectionString }; string databaseName = builder.InitialCatalog; var migrationDbExists = DatabaseChecking.CheckDatabaseExists(connectionString, databaseName); if (!migrationDbExists) { DatabaseCreation.CreateDatabase(connectionString, databaseName); } }