Skip to content

Commit

Permalink
Tweak to index canonicalization to better handle multi-column indexes…
Browse files Browse the repository at this point in the history
…, added some missing postgres too long identifier warnings
  • Loading branch information
jeremydmiller committed Oct 23, 2024
1 parent e5b2fd4 commit 6f02e26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Weasel.Core/Migrations/DatabaseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ public async Task<SchemaPatchDifference> ApplyAllConfiguredChangesToDatabaseAsyn

var objects = AllObjects().ToArray();

foreach (var objectName in objects.SelectMany(x => x.AllNames()))
{
Migrator.AssertValidIdentifier(objectName.Name);
}

TConnection? conn = null;
try
{
Expand Down Expand Up @@ -393,7 +398,9 @@ private async ValueTask ensureStorageExistsAsync(
await initializeSchemaWithNewConnection(token).ConfigureAwait(false);

foreach (var dependentType in feature.DependentTypes())
{
await ensureStorageExistsAsync(types, dependentType, token).ConfigureAwait(false);
}

await generateOrUpdateFeature(featureType, feature, token).ConfigureAwait(false);
}
Expand All @@ -410,7 +417,9 @@ protected async ValueTask generateOrUpdateFeature(Type featureType, IFeatureSche


foreach (var objectName in schemaObjects.SelectMany(x => x.AllNames()))
{
Migrator.AssertValidIdentifier(objectName.Name);
}

using (await _migrateLocker.Lock(5.Seconds(), token).ConfigureAwait(false))
{
Expand Down
6 changes: 6 additions & 0 deletions src/Weasel.Postgresql/Tables/IndexDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ public static IndexDefinition Parse(string definition)
}
else
{
if (expression.StartsWith('(') && expression.EndsWith(')'))
{
expression = expression.Substring(1, expression.Length - 2);
}

index.Columns = expression.Split(',').Select(canonicizeColumn).ToArray();
}

Expand Down Expand Up @@ -739,6 +744,7 @@ public static string CanonicizeDdl(string sql, string schema)
.Replace(" -> ", "->")
.Replace(IndexCreationBeginComment, "")
.Replace(IndexCreationEndComment, "")
.Replace("as decimal", "as numeric")
.Replace(", ", ",")
.Trim()
.TrimEnd(new[] { ';' })
Expand Down

0 comments on commit 6f02e26

Please sign in to comment.