Skip to content

Commit 7d5d7fe

Browse files
committed
Fix migration history table lookup (#2788)
(cherry picked from commit 9418c25)
1 parent e5ade7f commit 7d5d7fe

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/EFCore.PG/Migrations/Internal/NpgsqlHistoryRepository.cs

+8-19
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,15 @@ protected override string ExistsSql
1616
{
1717
get
1818
{
19-
var builder = new StringBuilder();
20-
21-
builder.Append("SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE ");
22-
2319
var stringTypeMapping = Dependencies.TypeMappingSource.GetMapping(typeof(string));
2420

25-
if (TableSchema is not null)
26-
{
27-
builder
28-
.Append("n.nspname=")
29-
.Append(stringTypeMapping.GenerateSqlLiteral(TableSchema))
30-
.Append(" AND ");
31-
}
32-
33-
builder
34-
.Append("c.relname=")
35-
.Append(stringTypeMapping.GenerateSqlLiteral(TableName))
36-
.Append(");");
37-
38-
return builder.ToString();
21+
return $@"
22+
SELECT EXISTS (
23+
SELECT 1 FROM pg_catalog.pg_class c
24+
JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
25+
WHERE n.nspname={stringTypeMapping.GenerateSqlLiteral(TableSchema ?? "public")} AND
26+
c.relname={stringTypeMapping.GenerateSqlLiteral(TableName)}
27+
)";
3928
}
4029
}
4130

@@ -60,4 +49,4 @@ public override string GetBeginIfExistsScript(string migrationId) => $@"
6049
public override string GetEndIfScript() =>
6150
@" END IF;
6251
END $EF$;";
63-
}
52+
}

0 commit comments

Comments
 (0)