Beispiel #1
0
        /// <summary>
        /// Creates a CS file that inherits from BaseMigration that will execute the SQL schema changes.
        /// </summary>
        /// <param name="criteria">description of what to do and where to put the file</param>
        public void CreateScript(CreationCriteria criteria)
        {
            var configurationStatus = GetMigrationConfigurationStatus(criteria.ProjectFileLocation, criteria.RepoName);

            if (!configurationStatus.Enabled)
            {
                LoggerBase.Log("Migrations are not enabled, can not create any migrations.");
                return;
            }

            if (configurationStatus.MigrationType != MigrationToUse.Manual)
            {
                LoggerBase.Log("Manual Migrations are not enabled, can not create manual migrations.");
                return;
            }

            var repoInfo = TypeHandler.FindSingleRepo(criteria.ProjectFileLocation, criteria.RepoName);

            //if null we need to drop out.
            if (repoInfo == null)
            {
                LoggerBase.Log("Unable to find repo");
                return;
            }

            AssertRepoHasEmptyConstructor(repoInfo.RepoType);
            EnsureDbAndMigrationTableExists(criteria.ProjectFileLocation, repoInfo.RepoType, criteria.ConfigFilePath);

            //ensure that we have the case correct.
            criteria.RepoName = repoInfo.RepoType.Name;

            var configuration = TypeHandler.FindConfiguration(criteria.ProjectFileLocation, repoInfo.RepoType);

            //if null something bad happend, drop out
            if (configuration == null)
            {
                LoggerBase.Log("unable to find configuration file");
                return;
            }

            var updater = CreateSchemaUpdater(repoInfo.Assembly.Location, repoInfo.RepoType, criteria.ConfigFilePath);

            var fileMigrationHandler = new MigrationFileHandler(updater);
            var projectFileHandler   = new ProjectDteHelper();

            //set the mgiration folder form config:
            criteria.MigrationPath = configuration.RootMigrationFolder;

            var filePath = fileMigrationHandler.CreateFile(criteria);

            projectFileHandler.AddFile(criteria.ProjectFileLocation, configuration.RootMigrationFolder, filePath, showFile: true);
            LoggerBase.Log("Created migration file.");

            //clean up
            ProjectEvalutionHelper.FinishedWithProject(criteria.ProjectFileLocation);
        }
Beispiel #2
0
        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);
        }