private void ParseLine(string line) { if (line.StartsWith("description:")) { line = line.Substring("description:".Length).Trim(); description = line; } else if (line.StartsWith("version:")) { line = line.Substring("version:".Length).Trim(); var newVersion = DatabaseVersion.Parse(line); if (version != null && !Equals(version, newVersion)) { throw new FormatException($"Version specified in {this} headers ({newVersion}) is different from version specified in its file name ({version})"); } version = newVersion; } else if (line.StartsWith("dependency:")) { line = line.Substring("dependency:".Length).Trim(); int at = line.IndexOf('@'); if (at == -1) { dependencies.Add(new DatabaseMigrationSpecifier(line, null)); } else { string moduleName = line.Substring(0, at); string versionString = line.Substring(at + 1); dependencies.Add(new DatabaseMigrationSpecifier(moduleName, DatabaseVersion.Parse(versionString))); } } }
private void ParseFileName() { var match = FileNameRegex.Match(FileName); if (!match.Success) { throw new FormatException($"Invalid FileSqlDatabaseMigration file name: must match the following regex '{FileNameRegex}'"); } moduleName = match.Groups["module"].Captures.Count > 0 ? match.Groups["module"].Captures[0].Value : throw new FormatException($"Invalid FileSqlDatabaseMigration file name: missing module name in '{FileName}'"); isBaseline = match.Groups["baseline"].Captures.Count > 0; isRepeatable = match.Groups["repeatable"].Captures.Count > 0; version = match.Groups["version"].Captures.Count > 0 ? DatabaseVersion.Parse(match.Groups["version"].Captures[0].Value) : null; tags = match.Groups["tag"].Captures.Count > 0 ? new[] { match.Groups["tag"].Captures.OfType <Capture>().Select(x => x.Value).ToArray() } : new string[0][]; }