OpenSource » Database Migrator » Migrator2
Clone URL:  

Migrator Fixed a bug, AssemblyGuid was not being set and was causing things to screw up.

Changeset 030457bb3959

Parent 957b10626f18

by jasoncline

Changes to 2 files · Browse files at 030457bb3959 Showing diff from parent 957b10626f18 Diff from another changeset...

 
54
55
56
57
 
58
59
60
 
86
87
88
89
 
90
91
92
93
94
95
96
 
97
98
99
 
100
101
102
 
105
106
107
108
 
109
110
111
112
113
114
115
 
116
117
118
 
119
120
121
122
123
124
125
126
127
 
 
 
 
128
129
130
 
131
132
133
134
 
135
136
 
137
138
139
 
140
141
142
 
144
145
146
147
 
148
149
150
 
161
162
163
164
 
165
166
167
168
 
169
170
171
 
219
220
221
222
 
223
224
225
 
227
228
229
230
 
231
232
233
 
235
236
237
238
 
239
240
241
 
54
55
56
 
57
58
59
60
 
86
87
88
 
89
90
91
92
93
94
95
 
96
97
98
 
99
100
101
102
 
105
106
107
 
108
109
110
111
112
113
114
 
115
116
117
 
118
119
120
121
122
123
 
 
 
 
124
125
126
127
128
129
 
130
131
132
133
 
134
135
 
136
137
138
 
139
140
141
142
 
144
145
146
 
147
148
149
150
 
161
162
163
 
164
165
166
167
 
168
169
170
171
 
219
220
221
 
222
223
224
225
 
227
228
229
 
230
231
232
233
 
235
236
237
 
238
239
240
241
@@ -54,7 +54,7 @@
  allParamsSpecified = false;   }   } - +   /// <summary>   /// Run the migrator's console   /// </summary> @@ -86,17 +86,17 @@
  }   return 0;   } - +   /// <summary>   /// Runs the migrations.   /// </summary>   public void Migrate()   {   CheckArguments(); - +   Migrator mig = GetMigrator();   - if(_migrateUp) + if (_migrateUp)   mig.MigrateUp();   else if (_migrateDown)   mig.MigrateDown(); @@ -105,38 +105,38 @@
  else   mig.MigrateTo(_migrateTo);   } - +   /// <summary>   /// List migrations.   /// </summary>   public void List()   {   CheckArguments(); - +   Migrator mig = GetMigrator();   int currentVersion = mig.CurrentVersion; - +   Console.WriteLine("Available migrations:");   foreach (Type t in mig.MigrationsTypes)   {   int v = Migrator.GetMigrationVersion(t);   Console.WriteLine("{0} {1} {2}", - v == currentVersion ? "=>" : " ", - v.ToString().PadLeft(3), - Migrator.GetMigrationDescription(t) - ); + v == currentVersion ? "=>" : " ", + v.ToString().PadLeft(3), + Migrator.GetMigrationDescription(t) + );   }   } - +   public void Dump()   {   CheckArguments(); - +   SchemaDumper dumper = new SchemaDumper(_provider, _connectionString); - +   dumper.DumpTo(_dumpTo);   } - +   /// <summary>   /// Show usage information and help.   /// </summary> @@ -144,7 +144,7 @@
  {   int tab = 17;   Version ver = Assembly.GetExecutingAssembly().GetName().Version; - +   Console.WriteLine("Database migrator - v{0}.{1}.{2}", ver.Major, ver.Minor, ver.Revision);   Console.WriteLine();   Console.WriteLine("usage:\nMigrator.Console.exe provider connectionString migrationsAssembly [options]"); @@ -161,11 +161,11 @@
  Console.WriteLine();   Console.WriteLine("-up, -down, and -to options are mutually exclusive");   } - +   #region Private helper methods   private Assembly GetAssembly()   { - return Assembly.LoadFrom(_migrationsAssembly);; + return Assembly.LoadFrom(_migrationsAssembly); ;   }     private Migration GetBeginMigration() @@ -219,7 +219,7 @@
  migrations.Sort(new MigrationTypeComparer(true));   return migrations;   } - +   private void CheckArguments()   {   if (_connectionString == null) @@ -227,7 +227,7 @@
  if (_migrationsAssembly == null)   throw new ArgumentException("Migrations assembly missing", "migrationsAssembly");   } - +   private Migrator GetMigrator()   {   GuidAttribute guidAttribute = (GuidAttribute)Attribute.GetCustomAttribute(GetAssembly(), typeof(GuidAttribute)); @@ -235,7 +235,7 @@
  var logger = new Loggers.ConsoleLogger(_trace);   return new Migrator(_provider, _connectionString, GetGeneralMigrations(), GetBeginMigration(), GetEndMigration(), guidAttribute, logger);   } - +   private void ParseArguments(string[] argv)   {   for (int i = 0; i < argv.Length; i++)
 
31
32
33
34
 
35
36
37
 
75
76
77
78
 
79
80
81
 
84
85
86
87
 
88
89
90
91
92
93
94
 
95
96
97
 
104
105
106
107
 
108
109
110
 
202
203
204
205
 
206
207
208
 
362
363
364
365
 
366
367
368
 
569
570
571
572
 
573
574
575
 
31
32
33
 
34
35
36
37
 
75
76
77
 
78
79
80
81
 
84
85
86
 
87
88
89
90
91
92
93
 
94
95
96
97
 
104
105
106
 
107
108
109
110
 
202
203
204
 
205
206
207
208
 
362
363
364
 
365
366
367
368
 
569
570
571
 
572
573
574
575
@@ -31,7 +31,7 @@
   namespace Migrator  { - /// <summary> + /// <summary>   /// Migrations mediator.   /// </summary>   public class Migrator @@ -75,7 +75,7 @@
  public Migrator(string provider, string connectionString)   : this(CreateProvider(provider, connectionString), Assembly.GetExecutingAssembly(), new Log4NetLogger())   { } - +   public Migrator(TransformationProvider provider, Assembly migrationAssembly, ILogger logger)   {   _provider = provider; @@ -84,14 +84,14 @@
    if (provider == null)   throw new ArgumentNullException("provider"); - +   if (migrationAssembly == null)   {   _logger.Exception("Migration assembly not provided.", new ArgumentNullException("migrationAssembly"));   throw new Exception("Assembly not found");   }   - if(migrationAssembly != null) + if (migrationAssembly != null)   _logger.Log("Performing migrations for {0}", migrationAssembly.FullName);     // add all providers to the "all providers" list @@ -104,7 +104,7 @@
  }   this._allProviders.Add(_provider);   - GuidAttribute guid = (GuidAttribute)Attribute.GetCustomAttribute(migrationAssembly, typeof(GuidAttribute)); + AssemblyGuid = (GuidAttribute)Attribute.GetCustomAttribute(migrationAssembly, typeof(GuidAttribute));     // only load the migrations for the given assembly   if (migrationAssembly != null) @@ -202,7 +202,7 @@
  }   }   #endregion - +   #region Static Methods   /// <summary>   /// Allow a migration to create a TransformationProvider to another database so it can migrate data from that database @@ -362,7 +362,7 @@
  this._logger.Started(CurrentVersion, toVersion);     /// Execute the Begin Migration - if(goingUp) + if (goingUp)   InitializeMigration(BeginMigration).Up();   else   InitializeMigration(EndMigration).Down(); @@ -569,7 +569,7 @@
  }   #endregion   - #region Helper methods + #region Helper methods   /// <summary>   /// Check for duplicated version in migrations.   /// </summary>