Holds the contents of a migration script file.
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <param name="migrationName">name of the migration script</param>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(string migrationName)
        {
            long version = GetNewVersionNumber();
            var path = GetPath(null);
            path = Path.Combine(path, version + "_" + SanitizeMigrationName(migrationName) + ".sql");

            var contents = new MigrationScriptContents(null, null);

            var file = new MigrationScriptFile(path);
            file.Write(contents);

            return path;
        }
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <param name="migrationName">name of the migration script</param>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(string migrationName)
        {
            long version = GetNewVersionNumber();
            var  path    = GetPath(null);

            path = Path.Combine(path, version + "_" + SanitizeMigrationName(migrationName) + ".sql");

            var contents = new MigrationScriptContents(null, null);

            var file = new MigrationScriptFile(path);

            file.Write(contents);

            return(path);
        }
Esempio n. 3
0
        /// <summary>
        /// Writes the given contents into the migration script file.
        /// </summary>
        public void Write(MigrationScriptContents contents)
        {
            var sb = new StringBuilder();

            sb.AppendLine(SetupStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Setup);
            sb.AppendLine();
            sb.AppendLine(SetupEndTag);
            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine(TeardownStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Teardown);
            sb.AppendLine();
            sb.Append(TeardownEndTag);

            File.WriteAllText(FilePath, sb.ToString(), Encoding.UTF8);
        }
        /// <summary>
        /// Creates a blank migration script with the given name.
        /// </summary>
        /// <returns>The path to the new migration script.</returns>
        public string CreateBlankScript(GenerateScriptCommandArgs args)
        {
            long version = GetNewVersionNumber(args);
            var  path    = GetPath(null, args);

            path = Path.Combine(path, version + "_" + SanitizeMigrationName(args.MigrationName) + ".sql");

            var setup = new System.Text.StringBuilder();

            setup.AppendLine("SET XACT_ABORT ON;");
            setup.AppendLine("");
            setup.Append("-- TODO: Replace with script implementation");

            var contents = new MigrationScriptContents(setup.ToString(), null);

            var file = new MigrationScriptFile(path);

            file.Write(contents);

            return(path);
        }
        /// <summary>
        /// Writes the given contents into the migration script file.
        /// </summary>
        public void Write(MigrationScriptContents contents)
        {
            var sb = new StringBuilder();
            sb.AppendLine(SetupStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Setup);
            sb.AppendLine();
            sb.AppendLine(SetupEndTag);
            sb.AppendLine();
            sb.AppendLine();
            sb.AppendLine(TeardownStartTag);
            sb.AppendLine();
            sb.AppendLine(contents.Teardown);
            sb.AppendLine();
            sb.Append(TeardownEndTag);

            File.WriteAllText(FilePath, sb.ToString());
        }