Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/Migrator/Providers/TransformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using ForeignKeyConstraint = DotNetProjects.Migrator.Framework.ForeignKeyConstraint;
using ForeignKeyConstraintType = DotNetProjects.Migrator.Framework.ForeignKeyConstraintType;
Expand Down Expand Up @@ -416,7 +415,7 @@
// Remove the primary key notation if compound primary key because we'll add it back later
if (compoundPrimaryKey && column.IsPrimaryKey)
{
column.ColumnProperty = column.ColumnProperty ^ ColumnProperty.PrimaryKey;

Check warning on line 418 in src/Migrator/Providers/TransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.PrimaryKey' is obsolete: 'Use AddPrimaryKey instead.'
column.ColumnProperty = column.ColumnProperty | ColumnProperty.NotNull; // PK is always not-null
}

Expand Down Expand Up @@ -725,6 +724,9 @@
/// <param name="columns">Primary column names</param>
public virtual void AddPrimaryKey(string name, string table, params string[] columns)
{
QuoteColumnNamesIfRequired(columns);
table = QuoteTableNameIfRequired(table);

ExecuteNonQuery(
string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} PRIMARY KEY ({2}) ", table, name,
string.Join(",", QuoteColumnNamesIfRequired(columns))));
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Column names are being quoted twice. The call to QuoteColumnNamesIfRequired(columns) on line 727 modifies the array in-place, but then line 732 calls QuoteColumnNamesIfRequired(columns) again on the already-quoted column names. This will result in double-quoting. Either remove line 727 or use the array directly in line 732 without calling the method again.

Suggested change
string.Join(",", QuoteColumnNamesIfRequired(columns))));
string.Join(",", columns)));

Copilot uses AI. Check for mistakes.
Expand All @@ -735,8 +737,7 @@
}
public virtual void AddUniqueConstraint(string name, string table, params string[] columns)
{
QuoteColumnNames(columns);

QuoteColumnNamesIfRequired(columns);
table = QuoteTableNameIfRequired(table);

ExecuteNonQuery(string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE({2}) ", table, name, string.Join(", ", columns)));
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After quoting the column names on line 740, the code should use the quoted columns array that was returned, but line 743 uses the columns variable directly. Since QuoteColumnNamesIfRequired modifies the array in-place and returns it, the code works correctly but is inconsistent with how the method is called. For clarity and consistency, use the return value: string.Join(", ", QuoteColumnNamesIfRequired(columns)) or store the result in a variable on line 740.

Suggested change
ExecuteNonQuery(string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE({2}) ", table, name, string.Join(", ", columns)));
ExecuteNonQuery(string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE({2}) ", table, name, string.Join(", ", QuoteColumnNamesIfRequired(columns))));

Copilot uses AI. Check for mistakes.
Expand Down
Loading