예제 #1
0
        public static IEnumerable <ScriptInfo> GetScripts(
            this IMigrationScriptsProvider provider,
            string[] scriptPaths,
            string folder)
        {
            const string extension  = ".sql";
            var          startIndex = folder.Length;

            return(scriptPaths
                   .Where(path => path.StartsWith(folder) && path.EndsWith(extension, StringComparison.OrdinalIgnoreCase))
                   .Select(path =>
            {
                var splits = path.Substring(startIndex + 1, path.Length - startIndex - extension.Length - 1)
                             .Split(new [] { '_' }, 2);

                if (splits.Length == 2 && long.TryParse(splits[0], out var id))
                {
                    return new ScriptInfo(provider)
                    {
                        Id = long.Parse(splits[0]),
                        Name = splits[1],
                        Path = path
                    };
                }
                else
                {
                    return null;
                }
            })
                   .Where(s => s != null)
                   .OrderBy(s => s.Id));
        }
예제 #2
0
 /// <summary>
 /// Register new <see cref="IMigrationScriptsProvider"/>.
 /// </summary>
 /// <param name="provider">Migration scripts provider.</param>
 public void AddScriptsProvider(IMigrationScriptsProvider provider)
 => _providers.Add(provider);
예제 #3
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="provider">Migration scripts provider.</param>
 public ScriptInfo(IMigrationScriptsProvider provider)
 {
     _provider = Check.NotNull(provider, nameof(provider));
 }