OpenSource » Database Migrator » Migrator2
Clone URL:  

Migrator * implemented version of AddColumn and AlterColumn that don't require the column size for column types where the size is automatically determined.

Changeset d9d8922c8e68

Parent 4261f27a88a2

by gareth.farrington

Changes to 2 files · Browse files at d9d8922c8e68 Showing diff from parent 4261f27a88a2 Diff from another changeset...

 
563
564
565
 
566
567
568
 
563
564
565
566
567
568
569
@@ -563,6 +563,7 @@
  {   // initialize Migration variables injected from the Migrator   migration.TransformationProvider = _provider; + _provider.Timeout = null; // reset the Timeout to the default value   migration.Databases = this._additionalProviders;   migration.Parameters = this._parameters;   return migration;
 
39
40
41
42
43
 
 
 
44
45
46
47
48
49
50
51
52
 
53
54
55
 
74
75
76
77
78
79
80
81
82
83
84
85
86
 
87
88
 
 
 
 
 
 
 
89
90
91
 
123
124
125
126
 
127
128
129
 
133
134
135
136
 
137
138
139
 
142
143
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
146
147
 
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
 
266
267
268
 
 
269
270
271
 
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
 
642
643
644
645
646
 
647
648
649
 
39
40
41
 
 
42
43
44
45
46
47
48
49
 
 
 
 
50
51
52
53
 
72
73
74
 
75
76
77
 
 
 
 
 
 
78
79
80
81
82
83
84
85
86
87
88
89
90
 
122
123
124
 
125
126
127
128
 
132
133
134
 
135
136
137
138
 
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
 
212
213
214
 
 
 
 
 
 
 
 
 
215
216
217
 
303
304
305
306
307
308
309
310
 
582
583
584
 
 
 
 
 
 
 
 
 
585
586
587
 
672
673
674
 
 
675
676
677
678
@@ -39,17 +39,15 @@
  private ILogger _logger = new NullLogger();   protected IDbConnection _connection;   private IDbTransaction _transaction; - private String _assemblyId = null; - private Boolean _cacheConvertedValues = true; + private string _assemblyId = null; + private bool _cacheConvertedValues = true; + private int? _timeout = null;   public delegate U ConvertColumnDelegate<T, U>(T currentValue, IDataReader row);     #region Properties   public String AssemblyId   { - get - { - return this._assemblyId; - } + get { return this._assemblyId; }   }     /// <summary> @@ -74,18 +72,19 @@
  get { return _logger; }   set { _logger = value; }   } - #endregion     public string ConnectionString   { - get - { - if (_connection != null) - return (string)_connection.ConnectionString.Clone(); - return null; - } + get { return _connection != null ? (string)_connection.ConnectionString.Clone() : null; }   }   + public int? Timeout + { + get { return this._timeout == null || this._timeout == 0 ? null : this._timeout; } + set { this._timeout = value; } + } + #endregion +   #region Add Column/Table/PK/FK/Constraint   /// <summary>   /// Add a new column to an existing table. @@ -123,7 +122,7 @@
    /// <summary>   /// <see cref="TransformationProvider.AddColumn(string, string, Type, int, ColumnProperties, object)"> - /// AddColumn(string, string, Type, int, ColumnProperties, object) + /// AddColumn(string, string, Type, int, ColumnProperties)   /// </see>   /// </summary>   public virtual void AddColumn(string table, string column, Type type, ColumnProperties property) @@ -133,7 +132,7 @@
    /// <summary>   /// <see cref="TransformationProvider.AddColumn(string, string, Type, int, ColumnProperties, object)"> - /// AddColumn(string, string, Type, int, ColumnProperties, object) + /// AddColumn(string, string, Type, int, ColumnProperties)   /// </see>   /// </summary>   public virtual void AddColumn(string table, string column, Type type, int size, ColumnProperties property) @@ -142,6 +141,53 @@
  }     /// <summary> + /// <see cref="TransformationProvider.AddColumn(string, string, Type, int, ColumnProperties, object)"> + /// AddColumn(string, string, Type, int, ColumnProperties, object) + /// </see> + /// </summary> + public virtual void AddColumn(string table, string column, Type type, ColumnProperties property, object defaultValue) + { + AddColumn(table, column, type, 0, property, defaultValue); + } + + /// <summary> + /// Implements 'Alter Table' functionality common in most SQL variants. + /// </summary> + /// <param name="table">Table Name</param> + /// <param name="column">Column Name to alter</param> + /// <param name="dataType">new typw of the Column</param> + /// <param name="size">new size of the Column</param> + /// <param name="props">New Column Properties</param> + /// <param name="defaultValue">new Default Value</param> + public abstract void AlterColumn(string table, string column, Type type, int size); + + /// <summary> + /// Implements 'Alter Table' functionality common in most SQL variants. + /// </summary> + /// <remarks>Transformation providers that dont support all possible functionality are free to work around the problem OR throw an exception. + /// If an exception is thrown please include the specific functionality that isnt implemented in the exception message. E.g. SqlLite cant alter columns to be primary keys.</remarks> + /// <param name="table">Table Name</param> + /// <param name="column">Column Name to alter</param> + /// <param name="dataType">new typw of the Column</param> + /// <param name="size">new size of the Column</param> + /// <param name="props">New Column Properties</param> + /// <param name="defaultValue">new Default Value</param> + public abstract void AlterColumn(string table, string column, Type dataType, int size, ColumnProperties props, object defaultValue); + + /// <summary> + /// Implements 'Alter Table' functionality common in most SQL variants. + /// </summary> + /// <param name="table">Table Name</param> + /// <param name="column">Column Name to alter</param> + /// <param name="dataType">new type of the Column</param> + /// <param name="props">New Column Properties</param> + /// <param name="defaultValue">new Default Value</param> + public virtual void AlterColumn(string table, string column, Type dataType, ColumnProperties props, object defaultValue) + { + AlterColumn(table, column, dataType, 0, props, defaultValue); + } + + /// <summary>   /// Append a primary key to a table.   /// </summary>   /// <param name="name">Constraint name</param> @@ -166,15 +212,6 @@
  public abstract void AddTable(string name, params Column[] columns);     /// <summary> - /// Alter the definition of a column - /// </summary> - /// <param name="table"></param> - /// <param name="column"></param> - /// <param name="type"></param> - /// <param name="size"></param> - public abstract void AlterColumn(string table, string column, Type type, int size); - - /// <summary>   /// Append a foreign key (relation) between two tables.   /// </summary>   /// <param name="name">Constraint name</param> @@ -266,6 +303,8 @@
  IDbCommand cmd = _connection.CreateCommand();   cmd.CommandText = sql;   cmd.CommandType = CommandType.Text; + if (this.Timeout != null) + cmd.CommandTimeout = this.Timeout.Value;   BeginTransaction();   if (_transaction != null)   { @@ -543,15 +582,6 @@
    #region Remove Column/Table/Constraint/FK   /// <summary> - /// Implements 'Alter Table' functionality common in most SQL variants. - /// </summary> - /// <remarks>Transformation providers that dont support all possible functionality are free to work around the problem OR throw an exception. - /// If an exception is thrown please include the specific functionality that isnt implemented in the exception message. E.g. SqlLite cant alter columns to be primary keys.</remarks> - /// <param name="table"></param> - /// <param name="column"></param> - public abstract void AlterColumn(string table, string column, Type dataType, int size, ColumnProperties props, object defaultValue); - - /// <summary>   /// Removes a column from a table   /// </summary>   /// <param name="table">table containing the column</param> @@ -642,8 +672,7 @@
  {   return ExecuteNonQuery(string.Format("UPDATE {0} SET {1}", table, string.Join(", ", columnValues)));   } - - +   protected virtual bool VersionRecordExists(String assemblyId)   {   int? ver = (int?)ExecuteScalar(String.Format("SELECT TOP 1 Version FROM SchemaInfo WHERE AssemblyId='{0}'", assemblyId));