如何在C#中使用FluentMigrator创建具有数组类型列的PostgreSQL表:

huangapple go评论72阅读模式
英文:

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

问题

这是您要翻译的内容:

"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.

英文:

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.

答案1

得分: 0

根据您提供的链接以及我自己的搜索结果,似乎标准的FluentMigrator方法无法实现此操作。

但是,您可以在迁移中运行SQL脚本。虽然这不是最佳实践,但在某些情况下非常有帮助。在这里,您可以看到一些示例,其中包括"Execute Expression"部分。

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

另外,您还可以从FluentMigrator仓库创建一个分支,并自己添加这些方法。不过,这样做可能会难以处理新的官方更新。

英文:

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.

答案2

得分: 0

这部分翻译如下:

This worked for me:

    Create.Table("tablename")
                    .WithColumn("columnname").AsCustom("TEXT[]").Nullable();
英文:

This worked for me:

Create.Table("tablename")
                .WithColumn("columnname").AsCustom("TEXT[]").Nullable();

huangapple
  • 本文由 发表于 2023年2月14日 06:01:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定