protected override PendingItem BuildClasspathItem(ItemLocation location, string itemName, Stream content)
        {
            Match matchResult = ScriptNameRegex.Match(itemName);

            if (!matchResult.Success)
            {
                Log.WarnFormat("File name {0} does not match migration script naming convention and will be ignored.", itemName);
                return(null);
            }

            ItemType type    = ScriptTypeUtils.ResolveType(matchResult.Groups[1].Value);
            string   version = string.Join(string.Empty, matchResult.Groups[2].Value.Split('.', '_'));

            using (var reader = new StreamReader(content, Encoding.UTF8))
            {
                string template = reader.ReadToEnd();

                var item = new PendingItem
                {
                    Id       = version,
                    Type     = type,
                    Version  = version,
                    Name     = itemName,
                    Content  = PreprocessScriptTemplate(location, template),
                    Checksum = StringUtils.ByteArrayToHex(HashUtils.GetMD5Hash(Encoding.UTF8.GetBytes(template)))
                };

                Log.DebugFormat("Adding file {0} as update script with version {1}", itemName, version);

                return(item);
            }
        }
示例#2
0
        private void InsertIntoSchemaVersion(SqlConnection connection, SqlTransaction tx, IMigratorConfiguration configuration, PendingItem script)
        {
            var insertSql = string.Format(InsertIntoSchemaVersionSql, configuration.SchemaVersionTable);

            using (var command = new SqlCommand(insertSql, connection, tx))
            {
                command.Parameters.Add(new SqlParameter("Type", ScriptTypeUtils.ResolveString(script.Type)));
                command.Parameters.Add(new SqlParameter("Version", script.Version));
                command.Parameters.Add(new SqlParameter("Script", script.Name));
                command.Parameters.Add(new SqlParameter("Executed", DateTime.Now));
                command.Parameters.Add(new SqlParameter("Hash", script.Checksum));
                command.ExecuteNonQuery();
            }
        }
示例#3
0
        private AppliedItem BuildAppliedScript(SqlDataReader reader)
        {
            ItemType type    = ScriptTypeUtils.ResolveType(reader.GetString(0));
            string   version = reader.GetString(1);

            return(new AppliedItem
            {
                Id = version,
                Type = type,
                Version = version,
                Name = reader.GetString(2),
                Executed = reader.GetDateTime(3),
                Checksum = reader.GetString(4)
            });
        }