Advertisement
Guest User

Untitled

a guest
May 21st, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. namespace ModuleName
  2. {
  3. public class Migrations : DataMigrationImpl
  4. {
  5. public int Create()
  6. {
  7. return 1;
  8. }
  9.  
  10. public int UpdateFrom1()
  11. {
  12. return ExecuteUpdateFrom(1);
  13. }
  14.  
  15. public int UpdateFrom2()
  16. {
  17. return ExecuteUpdateFrom(2);
  18. }
  19.  
  20. /// <summary>
  21. /// Execute the update migration step.
  22. /// </summary>
  23. /// <param name="updateFrom">Current migration step.</param>
  24. /// <param name="nextVersion">Next migration step. Specify null if the next step is the increment of 'updateFrom'.</param>
  25. /// <returns>The next migration step.</returns>
  26. private int ExecuteUpdateFrom(int updateFrom, int? nextVersion = null)
  27. {
  28. SomeRecord.UpdateFrom(updateFrom, SchemaBuilder, ContentDefinitionManager);
  29.  
  30. return nextVersion ?? (updateFrom + 1);
  31. }
  32. }
  33. }
  34.  
  35.  
  36. public class SomeRecord : AbstractRecord
  37. {
  38. public virtual int Id { get; set; }
  39.  
  40. /// <summary>
  41. /// Perform migration.
  42. /// </summary>
  43. /// <param name="curVersion">Version to upgrade from.</param>
  44. /// <param name="schemaBuilder">Schema builder.</param>
  45. /// <param name="contentDefinitionManager">Content definition manager.</param>
  46. internal static void UpdateFrom(int curVersion, SchemaBuilder schemaBuilder, IContentDefinitionManager contentDefinitionManager)
  47. {
  48. switch (curVersion)
  49. {
  50. case 1:
  51. {
  52. schemaBuilder.CreateTable(typeof(SomeRecord).Name, table => table
  53. .IndexColumn()
  54. );
  55.  
  56. break;
  57. }
  58. case 2:
  59. {
  60. // Do nothing.. case isn't really needed either
  61. break;
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement