Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptsProvider"/> class.
 /// </summary>
 /// <param name="assemblies">The assemblies to search.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 public EmbeddedScriptsProvider(Assembly[] assemblies, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions)
 {
     this.assemblies       = assemblies ?? throw new ArgumentNullException(nameof(assemblies));
     this.filter           = filter ?? throw new ArgumentNullException(nameof(filter));
     this.encoding         = encoding ?? throw new ArgumentNullException(nameof(encoding));
     this.sqlScriptOptions = sqlScriptOptions;
 }
Exemple #2
0
 /// <summary>
 /// Provider used to directly include an IScript instance during migrations
 /// </summary>
 /// <param name="namer">A function that returns the name of the script</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <param name="hasher">The hasher.</param>
 /// <param name="scripts">The IScript instances to include</param>
 public ScriptInstanceProvider(Func <IScript, string> namer, SqlScriptOptions sqlScriptOptions, IHasher hasher, params IScript[] scripts)
 {
     this.scripts          = scripts;
     this.namer            = namer;
     this.sqlScriptOptions = sqlScriptOptions;
     this.hasher           = hasher;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptsProvider"/> class.
 /// </summary>
 /// <param name="assemblies">The assemblies to search.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 public EmbeddedScriptsProvider(Assembly[] assemblies, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions)
 {
     this.assemblies       = assemblies;
     this.filter           = filter;
     this.encoding         = encoding;
     this.sqlScriptOptions = sqlScriptOptions;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptProvider"/> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The embedded script filter.</param>
 /// <param name="codeScriptFilter">The embedded script filter. If null, filter is used.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 public EmbeddedScriptAndCodeProvider(Assembly assembly, Func <string, bool> filter, Func <string, bool> codeScriptFilter, SqlScriptOptions sqlScriptOptions)
 {
     this.assembly          = assembly;
     this.filter            = codeScriptFilter ?? filter;
     this.sqlScriptOptions  = sqlScriptOptions;
     embeddedScriptProvider = new EmbeddedScriptProvider(assembly, filter);
 }
 internal static SqlScript Clone(this SqlScript script, SqlScriptOptions newOpts = null)
 {
     newOpts = newOpts ?? new SqlScriptOptions()
     {
         RunGroupOrder = script.SqlScriptOptions.RunGroupOrder,
         ScriptType    = script.SqlScriptOptions.ScriptType,
     };
     return(new SqlScript(script.Name, script.Contents, newOpts));
 }
 /// <summary>
 /// </summary>
 /// <param name="directoryPath">Path to SQL upgrade scripts</param>
 /// <param name="options">Different options for the file system script provider</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 public FileSystemScriptProvider(string directoryPath, FileSystemScriptOptions options, SqlScriptOptions sqlScriptOptions)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     this.directoryPath    = directoryPath;
     filter                = options.Filter;
     encoding              = options.Encoding;
     this.options          = options;
     this.sqlScriptOptions = sqlScriptOptions;
 }
Exemple #7
0
        public void RunHashedScript_Test()
        {
            var opts = new SqlScriptOptions {
                RunGroupOrder = 10, ScriptType = global::DbUp.Support.ScriptType.RunOnce
            };
            SqlScript script = new SqlScript("test_script_1", "SELECT GETDATE()", opts);
            IEnumerable <SqlScript> before   = null;
            IEnumerable <SqlScript> after    = null;
            IEnumerable <SqlScript> afterErr = null;

            _exec.Run(script, before, after, afterErr, HashJournal);
        }
Exemple #8
0
        protected IEnumerable <SqlScript> GetAllProviderScripts(string path)
        {
            var encoding         = System.Text.Encoding.UTF8;
            var sqlScriptOptions = new SqlScriptOptions();

            var files = GetFiles(path, true);

            return(files.Select(x =>
            {
                var s = SqlScript.FromFile(path, x.FullName, encoding, sqlScriptOptions);
                return new SqlScript(x.Name, s.Contents, s.SqlScriptOptions);
            }));
        }
Exemple #9
0
        public void RunScript_Test()
        {
            var opts = new SqlScriptOptions {
                RunGroupOrder = 10, ScriptType = global::DbUp.Support.ScriptType.RunOnce
            };
            SqlScript script = new SqlScript("test_script_1", "SELECT GETDATE()", opts);
            IEnumerable <SqlScript> before   = null;
            IEnumerable <SqlScript> after    = null;
            IEnumerable <SqlScript> afterErr = null;

            var result = _exec.Run(script, before, after, afterErr);

            _connection.Verify(x => x.ExecuteCommandsWithManagedConnection(It.IsAny <Action <Func <IDbCommand> > >()), Times.Exactly(1));
        }
 /// <summary>
 /// Adds IScript instances to the upgrader.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="namer">A function that returns the name of the script</param>
 /// <param name="scripts">The script instances.</param>
 /// <param name="sqlScriptOptions">The script sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScripts(this UpgradeEngineBuilder builder, Func <IScript, string> namer, SqlScriptOptions sqlScriptOptions, params IScript[] scripts)
 => WithScripts(builder, new ScriptInstanceProvider(namer, sqlScriptOptions, scripts));
 /// <summary>
 /// Adds a single IScript instance to the upgrader.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="name">The name of the script</param>
 /// <param name="script">The script instance</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScript(this UpgradeEngineBuilder builder, string name, IScript script, SqlScriptOptions sqlScriptOptions)
 => WithScripts(builder, new ScriptInstanceProvider(_ => name, sqlScriptOptions, script));
    /// <summary>
    /// Adds a single static script to the upgrader.
    /// </summary>
    /// <param name="builder">The builder.</param>
    /// <param name="name">The name of the script. This should never change once executed.</param>
    /// <param name="contents">The script body.</param>
    /// <param name="sqlScriptOptions">The sql script options.</param>
    /// <returns>
    /// The same builder
    /// </returns>
    public static UpgradeEngineBuilder WithScript(this UpgradeEngineBuilder builder, string name, string contents, SqlScriptOptions sqlScriptOptions)
    {
        var script = new SqlScript(name, contents, sqlScriptOptions);

        return(WithScripts(builder, script));
    }
 /// <summary>
 /// Adds all scripts from a folder on the file system, with custom encoding.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="path">The directory path.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 /// <param name="hasher">The hasher.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsFromFileSystem(this UpgradeEngineBuilder builder, string path, Encoding encoding, SqlScriptOptions sqlScriptOptions, IHasher hasher)
 {
     return(WithScripts(builder, new FileSystemScriptProvider(path, new FileSystemScriptOptions()
     {
         Encoding = encoding
     }, sqlScriptOptions, hasher)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptProvider"/> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The embedded script and code file filter.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 public EmbeddedScriptAndCodeProvider(Assembly assembly, Func <string, bool> filter, SqlScriptOptions sqlScriptOptions)
     : this(assembly, filter, filter, sqlScriptOptions)
 {
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assemblies, with a custom filter (you'll need to exclude non- .SQL files yourself).
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="filter">The filter. Don't forget to ignore any non- .SQL files.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <param name="hasher">The hasher.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsEmbeddedInAssemblies(this UpgradeEngineBuilder builder, Assembly[] assemblies, Func <string, bool> filter, SqlScriptOptions sqlScriptOptions, IHasher hasher)
 {
     return(WithScripts(builder, new EmbeddedScriptsProvider(assemblies, filter, DbUpDefaults.DefaultEncoding, sqlScriptOptions, hasher)));
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assembly, with a custom filter (you'll need to exclude non- .SQL files yourself) and where you specify the script type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The filter. Don't forget to ignore any non- .SQL files.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsEmbeddedInAssembly(this UpgradeEngineBuilder builder, Assembly assembly, Func <string, bool> filter, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new EmbeddedScriptProvider(assembly, filter, DbUpDefaults.DefaultEncoding, sqlScriptOptions)));
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assembly, or classes which inherit from IScript, with a custom filter (you'll need to exclude non- .SQL files yourself).
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The script filter. Don't forget to ignore any non- .SQL files.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsAndCodeEmbeddedInAssembly(this UpgradeEngineBuilder builder, Assembly assembly, Func <string, bool> filter, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new EmbeddedScriptAndCodeProvider(assembly, filter, sqlScriptOptions)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptProvider"/> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 public EmbeddedScriptProvider(Assembly assembly, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions) : base(new[] { assembly ?? throw new ArgumentNullException(nameof(assembly)) }, filter, encoding, sqlScriptOptions)
Exemple #19
0
        /// <summary>
        /// </summary>
        /// <param name="directoryPath">Path to SQL upgrade scripts</param>
        /// <param name="options">Different options for the file system script provider</param>
        /// <param name="sqlScriptOptions">The sql script options</param>
        public CustomFileSystemScriptProvider(string directoryPath, CustomFileSystemScriptOptions options, SqlScriptOptions sqlScriptOptions)
        {
            this.options = options ?? throw new ArgumentNullException(nameof(options));
            if (sqlScriptOptions == null)
            {
                throw new ArgumentNullException(nameof(sqlScriptOptions));
            }
            this.directoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));

            scriptProvider = new FileSystemScriptProvider(directoryPath, options, sqlScriptOptions);
        }
 /// <summary>
 /// Adds all scripts from a folder on the file system, with custom encoding.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="path">The directory path.</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsFromFileSystem(this UpgradeEngineBuilder builder, string path, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new FileSystemScriptProvider(path, new FileSystemScriptOptions(), sqlScriptOptions)));
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assembly, with custom encoding and script type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <param name="hasher">The hasher.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsEmbeddedInAssembly(this UpgradeEngineBuilder builder, Assembly assembly, Encoding encoding, SqlScriptOptions sqlScriptOptions, IHasher hasher)
 {
     return(WithScripts(builder, new EmbeddedScriptProvider(assembly, s => s.EndsWith(".sql", StringComparison.OrdinalIgnoreCase), encoding, sqlScriptOptions, hasher)));
 }
 /// <summary>
 /// Adds all scripts from a folder on the file system, with a custom filter and custom encoding.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="path">The directory path.</param>
 /// <param name="filter">The filter. Use the static <see cref="Filters"/> class to get some pre-defined filters.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsFromFileSystem(this UpgradeEngineBuilder builder, string path, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new FileSystemScriptProvider(path, new FileSystemScriptOptions()
     {
         Filter = filter, Encoding = encoding
     }, sqlScriptOptions)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmbeddedScriptProvider"/> class.
 /// </summary>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The filter.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options</param>
 public EmbeddedScriptProvider(Assembly assembly, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions) : base(new[] { assembly }, filter, encoding, sqlScriptOptions)
 {
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assembly, or classes which inherit from IScript, with a custom filter (you'll need to exclude non- .SQL files yourself).
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsAndCodeEmbeddedInAssembly(this UpgradeEngineBuilder builder, Assembly assembly, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new EmbeddedScriptAndCodeProvider(assembly, s => s.EndsWith(".sql", StringComparison.OrdinalIgnoreCase), sqlScriptOptions)));
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assembly, with custom encoding and with a custom filter (you'll need to exclude non- .SQL files yourself) and where you specify the script type.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assembly">The assembly.</param>
 /// <param name="filter">The filter. Don't forget to ignore any non- .SQL files.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <param name="hasher">The hasher.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsEmbeddedInAssembly(this UpgradeEngineBuilder builder, Assembly assembly, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions, IHasher hasher)
 {
     return(WithScripts(builder, new EmbeddedScriptProvider(assembly, filter, encoding, sqlScriptOptions, hasher)));
 }
 /// <summary>
 /// Adds all scripts found as embedded resources in the given assemblies, with a custom filter (you'll need to exclude non- .SQL files yourself).
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="assemblies">The assemblies.</param>
 /// <param name="filter">The filter. Don't forget to ignore any non- .SQL files.</param>
 /// <param name="encoding">The encoding.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <returns>
 /// The same builder
 /// </returns>
 public static UpgradeEngineBuilder WithScriptsEmbeddedInAssemblies(this UpgradeEngineBuilder builder, Assembly[] assemblies, Func <string, bool> filter, Encoding encoding, SqlScriptOptions sqlScriptOptions)
 {
     return(WithScripts(builder, new EmbeddedScriptsProvider(assemblies, filter, encoding, sqlScriptOptions)));
 }
 /// <summary>
 /// Provider used to directly include an IScript instance during migrations
 /// </summary>
 /// <param name="scripts">The IScript instances to include</param>
 /// <param name="namer">A function that returns the name of the script</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 public ScriptInstanceProvider(Func <IScript, string> namer, SqlScriptOptions sqlScriptOptions, params IScript[] scripts)
 {
     this.scripts          = scripts;
     this.namer            = namer ?? throw new ArgumentNullException(nameof(namer));
     this.sqlScriptOptions = sqlScriptOptions;
 }
Exemple #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlScript"/> class with a specific script type and a specific order
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="contents">The contents.</param>
 /// <param name="sqlScriptOptions">The script options.</param>
 public SqlScript(string name, string contents, SqlScriptOptions sqlScriptOptions) : base(name, contents, sqlScriptOptions)
 {
 }
Exemple #29
0
        private static void PopulateAdvancedScriptOptions(ScriptOptions scriptOptionsParameters, SqlScriptOptions advancedOptions)
        {
            if (scriptOptionsParameters == null)
            {
                Logger.Write(LogLevel.Verbose, "No advanced options set, the ScriptOptions object is null.");
                return;
            }

            foreach (PropertyInfo optionPropInfo in scriptOptionsParameters.GetType().GetProperties())
            {
                PropertyInfo advancedOptionPropInfo = advancedOptions.GetType().GetProperty(optionPropInfo.Name);
                if (advancedOptionPropInfo == null)
                {
                    Logger.Write(LogLevel.Warning, string.Format("Invalid property info name {0} could not be mapped to a property on SqlScriptOptions.", optionPropInfo.Name));
                    continue;
                }

                object optionValue = optionPropInfo.GetValue(scriptOptionsParameters, index: null);
                if (optionValue == null)
                {
                    Logger.Write(LogLevel.Verbose, string.Format("Skipping ScriptOptions.{0} since value is null", optionPropInfo.Name));
                    continue;
                }

                //
                // The ScriptOptions property types from the request will be either a string or a bool?.
                // The SqlScriptOptions property types from SMO will all be an Enum.  Using reflection, we
                // map the request ScriptOptions values to the SMO SqlScriptOptions values.
                //

                try
                {
                    object smoValue = null;
                    if (optionPropInfo.PropertyType == typeof(bool?))
                    {
                        smoValue = (bool)optionValue ? BooleanTypeOptions.True : BooleanTypeOptions.False;
                    }
                    else
                    {
                        smoValue = Enum.Parse(advancedOptionPropInfo.PropertyType, (string)optionValue, ignoreCase: true);
                    }

                    Logger.Write(LogLevel.Verbose, string.Format("Setting ScriptOptions.{0} to value {1}", optionPropInfo.Name, smoValue));
                    advancedOptionPropInfo.SetValue(advancedOptions, smoValue);
                }
                catch (Exception e)
                {
                    Logger.Write(
                        LogLevel.Warning,
                        string.Format("An exception occurred setting option {0} to value {1}: {2}", optionPropInfo.Name, optionValue, e));
                }
            }
        }