New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IColumnTypeSyntax<TNext>.AsType(DbType type) method for columns #1085
Comments
@antrv This is an interesting request. As a workaround, you can always implement AsCustom for now. You can also implement this quickly today as an extension method and have the underlying implementation use AsCustom. - There may be some databases that don't support all DbType values, but otherwise it is straight forward and probably one hour to implement.
Thoughts:
using FluentMigrator;
namespace MyCOmpany.DatabaseName.Migrations
{
using static System.Data.DbType;
[Migration(1)]
public class M1_ColumnDbTypeExample : ForwardOnlyMigration
{
public void Up()
{
var foo = Int16; // This is actually System.Data.DbType.Int16
// and only works this way because
// we put the "using static System.Data.DbType" inside the namespace directive
}
}
} |
Yes, there are databases that don't support all types. There may also be providers that don't provide workarounds for the types not natively supported by the database. I - for example - remember vaguely that I had to be careful with the types to use when I use Problems may arise for the following types:
|
Yeah, seems like potential for a lot of bugs. @antrv I think we would need to better understand your plan for implementing this. As I mentioned, you can naively write your own proprietary extension method that implements the feature by calling I think I'd be curious to hear what your use case is for this, as well. - What don't you like about the current way of expressing column data types. So far, the only feedback we've gotten is from Jay Harris that it would be useful to make TypeMap extensible/injectable. |
|
@antrv It's just a type switch: var foo = Alter.Table("foo").AddColumn("x").AsDbType(DbType.AnsiString); public static class IAlterTableColumnAsTypeSyntaxExtensions
{
public static IAlterTableColumnOptionOrAddColumnOrAlterColumnSyntax AsDbType(
this FluentMigrator.Builders.Alter.Table.IAlterTableColumnAsTypeSyntax syntax,
DbType dbType,
int? length = null)
{
switch (dbType)
{
case DbType.AnsiString:
return syntax.AsCustom($"varchar{length ?? 30}");
default:
throw new InvalidEnumArgumentException(nameof(dbType));
}
}
} |
@jzabroski Yes, I understand this. The point is the argument of |
I think I understand what you're ask is now. You want something that is easy to code-generate or parameterize. AsCustom subverts that goal if you're targeting many different databases. We agree with that; there is a ticket for coming up with a dictionary / mapping of how each database behaves #1032 The problem is it's a lot of work to do this right |
@jzabroski yes, exactly! thanks! |
And how are you going to handle things if when you call FM from your app on a db that doesn't support a given DbType? I'm curious because one feature that FM does not have is "error overrides". |
I actually require a DBMS supports the minimal set of types For example SQLite doesn't support the
and then I construct descriptor for
and the same for wide set of C# types, so I'll never call FM with unsupported combination of DBMS and DbType. |
Tagged this issue and #1029 with area-CodeGeneratorFriendliness as it seems like there are end users who would really find FluentMigrator more powerful if it had an internal API they could target (similar to LLVM) instead of the fluent syntax. |
Please add
IColumnTypeSyntax.AsType(DbType type)
method for columns.
Possibly other overloads:
AsType(DbType type, int size)
AsType(DbType type, int precision, int scale)
The text was updated successfully, but these errors were encountered: