Skip to content

Commit

Permalink
Fix Index parsing of column with canonization for character varying a…
Browse files Browse the repository at this point in the history
…s varchar
  • Loading branch information
mysticmind committed Jan 15, 2025
1 parent abdf7f9 commit 03c3dbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Weasel.Postgresql.Tests/Tables/IndexDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,14 @@ public void Marten_bug_3068()
"CREATE INDEX mt_doc_user_idx_fts ON app.mt_doc_user USING gin (mt_grams_vector(data ->> 'FirstName'))");
IndexDefinition.CanonicizeDdl(index1, table).ShouldBe(IndexDefinition.CanonicizeDdl(index2, table));
}

[Fact]
public void parse_index_with_column_type_character_varying_and_canonicize_as_varchar()
{
var table = new Table("mt_doc_abccorp_wallets_sunshine_payments");
var index1 =
IndexDefinition.Parse(
"create index bwsp_idx_tomainaccountid on mt_doc_abccorp_wallets_sunshine_payments using btree (cast(data->>'tomainaccountid' as character varying))");
IndexDefinition.CanonicizeDdl(index1, table).ShouldContain("varchar");
}
}
1 change: 1 addition & 0 deletions src/Weasel.Postgresql/Tables/IndexDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ public static string CanonicizeDdl(string sql, string schema)
.Replace(IndexCreationBeginComment, "")
.Replace(IndexCreationEndComment, "")
.Replace("as decimal", "as numeric")
.Replace("character varying", "varchar")
.Replace(", ", ",")
.Trim()
.TrimEnd(new[] { ';' })
Expand Down

0 comments on commit 03c3dbb

Please sign in to comment.