Skip to content
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

Fix parsing of multicolumn fulltext indexes #138

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Weasel.Postgresql.Tests/Tables/IndexDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,36 @@ public void Bug30()
IndexDefinition.CanonicizeDdl(index1, table).ShouldBe(IndexDefinition.CanonicizeDdl(index2, table));
}

[Fact]
public void test_multicolumn_index_with_fulltextsearch_vs_raw_sql()
{
var table = new Table("mt_doc_mydata");
var index1 = "CREATE INDEX mt_doc_mydata_idx_fulltext_search ON public.mt_doc_mydata USING gin (tenant_id, type, is_active_and_not_archived, to_tsvector('english'::regconfig, (data ->> 'SearchableValue'::text)));";
var index2 = IndexDefinition.Parse(index1);

IndexDefinition.CanonicizeDdl(index1, "public").ShouldBe(IndexDefinition.CanonicizeDdl(index2, table));
}
[Fact]
public void test_multicolumn_index_with_fulltextsearch_vs_parsed_sql()
{
var table = new Table("mt_doc_mydata");
var index1 = new IndexDefinition("mt_doc_mydata_idx_fulltext_search")
{
Columns =
[
"tenant_id",
"type",
"is_active_and_not_archived",
"to_tsvector('english', (data ->> 'SearchableValue'::text))"
],
Method = IndexMethod.gin
};
var index2 = IndexDefinition.Parse(
"CREATE INDEX mt_doc_mydata_idx_fulltext_search ON public.mt_doc_mydata USING gin (tenant_id, type, is_active_and_not_archived, to_tsvector('english'::regconfig, (data ->> 'SearchableValue'::text)));");

IndexDefinition.CanonicizeDdl(index1, table).ShouldBe(IndexDefinition.CanonicizeDdl(index2, table));
}

[Fact]
public void ensure_proper_delta_check_for_full_text_index_definition_between_db_and_instance()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Weasel.Postgresql/Tables/IndexDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,12 @@ public static string CanonicizeDdl(string sql, string schema)
.Replace("IS NOT NULL", "is not null")
.Replace("INDEX CONCURRENTLY", "INDEX")
.Replace("::text", "")
.Replace("::regconfig", "")
.Replace(" ->> ", "->>")
.Replace(" -> ", "->")
.Replace(IndexCreationBeginComment, "")
.Replace(IndexCreationEndComment, "")
.Replace(", ", ",")
.Trim()
.TrimEnd(new[] { ';' })
.ToLowerInvariant();
Expand Down
Loading