How to create a PostgreSQL table with column of type array using Fluentmigrator in C#

237 Views Asked by At

I might be overlooking something simple, I'm pretty novice with Fluentmigrator, but is it possible to create a table, using Fluentmigrator in C# code, that has a column of type array such as TEXT []?

Here is an example using SQL Syntax for comparison of the goal, with the column 'arrt' as the target column to create:

CREATE TEMPORARY TABLE IF NOT EXISTS array_test (
    id SERIAL, 
    is_active BOOLEAN,
    arrt TEXT[]
);

I tried checking the list of available methods through Visual Studio intelli-sense, on the WithColumn() method but this isn't giving me any luck. Also, although I am not sure I looked in the right place I did try going through the list of types here, which didn't show any indications I could tell that it is supported.

2

There are 2 best solutions below

1
Adolf On BEST ANSWER

This worked for me:

Create.Table("tablename")
                .WithColumn("columnname").AsCustom("TEXT[]").Nullable();
2
ba-a-aton On

Based on link you provided and some search by myself seems like standard FluentMigrator methods can't do it.

But you can run sql script from your migration. Not the best practice, but in some cases is very helpful. Here you can see some examples. Execute Expression section.

Execute.Script("myscript.sql");
Execute.EmbeddedScript("UpdateLegacySP.sql");
Execute.Sql("DELETE TABLE Users");

Also you can make branch from FluentMigrator repo and add this methods by yourself. But it will be hard to handle new official updates.