Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am working on a migration and need to check the size/length of an existing varchar column in a class inheriting from DatabaseSchemaResult.
DatabaseSchemaResult
I can check the column exists:
this.ValidColumns.Contains("myTableName,description")
Great!
I then attempt to check the size:
this.TableDefinitions.FirstOrDefault(x => x.Name == "myTableName") .Columns.FirstOrDefault(c => c.Name == "description") .Size != 500)
and this is where it fails since the Size is zero for all columns?
Can anyone point me in the right direction please?
Thanks, Simon
In order to provide a solution for anyone else looking to do this here is what was implemented:
An extension method was added for Umbraco.Core.Persistence.Database objects as follows:
Umbraco.Core.Persistence.Database
internal static int GetDbTableColumnSize(this Database database, string tableName, string columnName) { var sql = new Sql("SELECT character_maximum_length FROM information_schema.columns WHERE table_name = @table AND column_name = @column", new { @table = tableName, @column = columnName }); return database.ExecuteScalar<int>(sql); }
Which was then used as follows:
var size = database.GetDbTableColumnSize("tableName", "columnName");
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Checking existing Column Size in a custom Migration
I am working on a migration and need to check the size/length of an existing varchar column in a class inheriting from
DatabaseSchemaResult
.I can check the column exists:
Great!
I then attempt to check the size:
and this is where it fails since the Size is zero for all columns?
Can anyone point me in the right direction please?
Thanks, Simon
In order to provide a solution for anyone else looking to do this here is what was implemented:
An extension method was added for
Umbraco.Core.Persistence.Database
objects as follows:Which was then used as follows:
is working on a reply...