Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #61 from andresmoschini/migrations-refactorization

Log migration errors inside MigrationDescriptors
  • Loading branch information...
commit 47e376e3b92991d4fc3536707cf9b9f51a73fdbf 2 parents 4811fb0 + 7f0c200
@AlphaGit AlphaGit authored
View
20 source/CommonJobs/CommonJobs.Mvc.UI/Views/Migrations/Index.cshtml
@@ -30,21 +30,21 @@
</thead>
<tbody>
@{
- var count = 0;
- foreach (var migration in migrations)
- {
+ var count = 0;
+ foreach (var migration in migrations)
+ {
<tr>
<td>@migration.Id</td>
<td>@migration.MigrationTypeFullName</td>
<td>@migration.Description</td>
- <td>@migration.Status</td>
+ <td>@migration.Status @Info(migration)</td>
<td>
@Html.Hidden(string.Format("actions[{0}].Id", count), migration.Id)
@Html.DropDownList(string.Format("actions[{0}].Action", count), PossibleActions(migration.Status))
</td>
</tr>
- count++;
- }
+ count++;
+ }
}
</tbody>
</table>
@@ -54,6 +54,14 @@
</body>
</html>
+@helper Info(MigrationDescriptor migration)
+{
+ if (migration.Messages.Any())
+ {
+ <span title="@string.Join("\n\n", migration.Messages.OrderByDescending(x => x.Date).Select(x => string.Format("{0} on {1} action: '{2}'", x.Date, x.Action, x.Message)))"><b>(i)</b></span>
+ }
+}
+
@functions {
IEnumerable<SelectListItem> PossibleActions(MigrationStatus status)
{
View
1  source/CommonJobs/CommonJobs.Raven.Migrations/CommonJobs.Raven.Migrations.csproj
@@ -48,6 +48,7 @@
<ItemGroup>
<Compile Include="MigrationAction.cs" />
<Compile Include="MigrationActionType.cs" />
+ <Compile Include="MigrationMessage.cs" />
<Compile Include="MigrationStatus.cs" />
<Compile Include="IMigration.cs" />
<Compile Include="Migration.cs" />
View
6 source/CommonJobs/CommonJobs.Raven.Migrations/MigrationDescriptor.cs
@@ -12,5 +12,11 @@ public class MigrationDescriptor
public string Description { get; set; }
public string MigrationTypeFullName { get; set; }
public MigrationStatus Status { get; set; }
+ public List<MigrationMessage> Messages { get; set; }
+
+ public MigrationDescriptor()
+ {
+ Messages = new List<MigrationMessage>();
+ }
}
}
View
38 source/CommonJobs/CommonJobs.Raven.Migrations/MigrationMessage.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace CommonJobs.Raven.Migrations
+{
+ public class MigrationMessage
+ {
+ public DateTime Date { get; set; }
+ public string Message { get; set; }
+ public MigrationActionType Action { get; set; }
+ public Exception Exception { get; set; }
+
+ public MigrationMessage()
+ {
+ Date = DateTime.Now;
+ }
+
+ public MigrationMessage(MigrationActionType action, string message)
+ : this()
+ {
+ Action = action;
+ Message = message;
+ }
+
+ public MigrationMessage(MigrationActionType action, Exception exception)
+ : this(action, CreateMessage(exception))
+ {
+ Exception = exception;
+ }
+
+ private static string CreateMessage(Exception exception)
+ {
+ return string.Format("Exception {0}\nType: {1}\nStackTrace: {2}", exception.GetType(), exception.Message, exception.StackTrace);
+ }
+ }
+}
View
30 source/CommonJobs/CommonJobs.Raven.Migrations/Migrator.cs
@@ -33,14 +33,16 @@ private static MigrationDescriptor GetDescriptorWithUpdatedStatus(string key, Di
{
MigrationDescriptor auxValid = null;
MigrationDescriptor auxInstalled = null;
- if (validMigrations.TryGetValue(key, out auxValid))
- {
- auxValid.Status = installedMigrations.TryGetValue(key, out auxInstalled) ? auxInstalled.Status : MigrationStatus.NotInstalled;
- }
- else
+ if (!validMigrations.TryGetValue(key, out auxValid))
{
auxInstalled = installedMigrations[key];
auxInstalled.Status = MigrationStatus.InstalledObsolete;
+
+ }
+ else if (installedMigrations.TryGetValue(key, out auxInstalled))
+ {
+ auxValid.Status = auxInstalled.Status;
+ auxValid.Messages = auxInstalled.Messages;
}
return auxValid ?? auxInstalled;
}
@@ -105,9 +107,14 @@ public void Up(MigrationDescriptor descriptor)
session.SaveChanges();
}
}
- catch
+ catch (Exception e)
{
- //Por ahora no estoy haciendo nada con esto, si no se pudo aplicar la migración se va a ver en el resumen
+ using (var session = DocumentStore.OpenSession())
+ {
+ descriptor.Messages.Add(new MigrationMessage(MigrationActionType.Up, e));
+ session.Store(descriptor);
+ session.SaveChanges();
+ }
}
}
@@ -136,9 +143,14 @@ public void Down(MigrationDescriptor descriptor)
}
}
}
- catch
+ catch (Exception e)
{
- //Por ahora no estoy haciendo nada con esto, si no se pudo deshacer la migración se va a ver en el resumen
+ using (var session = DocumentStore.OpenSession())
+ {
+ descriptor.Messages.Add(new MigrationMessage(MigrationActionType.Down, e));
+ session.Store(descriptor);
+ session.SaveChanges();
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.