2

What´s the right way to create a TEXT (MYSQL) or CLOB(ORACLE/SQLSERVER) using a Migration script?

I mean something like: Alter.Column("column").OnTable("table").AsXXX

1 Answers1

0

An answer to a similar question: Can I create a column of nvarchar(MAX) using FluentMigrator? The idea is to use an extension on the FluentMigrator to add a method for handling "clob like" data types. In the example solution the extension uses a asString(int.MaxValue) but if you intend on using each database's specific text type (example bellow extends FluentMigrator so you can use the clob type on an alter column migration as opposed to the linked solution which allows you to use it in a create column):

public static IAlterColumnOptionSyntax AsClob(this IAlterColumnAsTypeOrInSchemaSyntax alterColumnAsTypeOrInSchemaSyntax) {
    var currentDB = ... // get from some config
    var clobType = null;
    switch(currentDB){
        case MYSQL:
           clobType = "LONGTEXT";
        break;
        case ORACLE:
            clobType = "CLOB";
        break;
        ... // so on and so forth
    }
    return alterColumnAsTypeOrInSchemaSyntax.asCustom(clobType);
}

and then you can use it as:

Alter.Column("column").OnTable("table").AsClob();

not the most elegant solution because it requires you to take the migrator's driver's job and determine the text type manually but it works.

Community
  • 1
  • 1
rodrigo.botti
  • 268
  • 1
  • 4
  • 9