Skip to content

Conversation

@JaBistDuNarrisch
Copy link

No description provided.

@JaBistDuNarrisch JaBistDuNarrisch merged commit ebb1a97 into master Jan 12, 2026
1 check passed
@JaBistDuNarrisch JaBistDuNarrisch deleted the add-primary-key branch January 12, 2026 13:19
@jogibear9988 jogibear9988 requested a review from Copilot January 12, 2026 13:47
@jogibear9988 jogibear9988 restored the add-primary-key branch January 12, 2026 13:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds table and column name quoting to constraint methods to properly handle reserved words and special characters in database identifiers.

Changes:

  • Removed unused System.Reflection import
  • Added column and table name quoting to AddPrimaryKey method
  • Changed AddUniqueConstraint to use QuoteColumnNamesIfRequired instead of the private QuoteColumnNames method
Comments suppressed due to low confidence (17)

src/Migrator/Providers/TransformationProvider.cs:1789

        foreach (var col in columns)
        {
            if (col.IsPrimaryKey)
            {
                primaryKeys.Add(col.Name);
            }
        }

src/Migrator/Providers/TransformationProvider.cs:1840

        foreach (var column in columns)
        {
            var indexSql = column.IndexSql;

            if (indexSql != null)
            {
                indexes.Add(indexSql);
            }
        }

src/Migrator/Providers/TransformationProvider.cs:2048

            parameter.Value = value == null ? null : ((DateTimeOffset?)value).Value.ToUniversalTime();

src/Migrator/Providers/TransformationProvider.cs:1046

  • Redundant call to 'ToString' on a String object.
        var query = string.Format("SELECT {0} FROM {1}", builder.ToString(), table);

src/Migrator/Providers/TransformationProvider.cs:1050

  • Redundant call to 'ToString' on a String object.
            query = string.Format("SELECT {0} FROM {1} WHERE ", builder.ToString(), table);

src/Migrator/Providers/TransformationProvider.cs:1200

  • Redundant call to 'ToString' on a String object.
        var query = string.Format("UPDATE {0} SET {1}", table, builder.ToString());

src/Migrator/Providers/TransformationProvider.cs:1278

  • Redundant call to 'ToString' on a String object.
        var query = string.Format("UPDATE {0} SET {1} WHERE {2}", table, builder.ToString(), GetWhereStringWithNullCheck(whereColumns, whereValues, values.Length));

src/Migrator/Providers/TransformationProvider.cs:321

  • String concatenation in loop: use 'StringBuilder'.
                joins += string.Format("JOIN {0} {1} ON {1}.{2} = {3}.{4} ", viewField.TableName, " T" + nr,
                    viewField.KeyColumnName, viewField.ParentTableName, viewField.ParentKeyColumnName);

src/Migrator/Providers/TransformationProvider.cs:362

  • String concatenation in loop: use 'StringBuilder'.
            joins += string.Format("{0} {1} {2} ON {2}.{3} = {4}.{5} ", joinType, viewJoin.TableName, tableAlias,
                viewJoin.ColumnName, viewJoin.ParentTableName, viewJoin.ParentColumnName);

src/Migrator/Providers/TransformationProvider.cs:1077

  • This assignment to andNeeded is useless, since its value is never read.
            andNeeded = true;

src/Migrator/Providers/TransformationProvider.cs:1712

  • These 'if' statements can be combined.
        if (_connection != null && _connection.State == ConnectionState.Open)
        {
            if (!_outsideConnection)
            {
                _connection.Close();
            }
        }

src/Migrator/Providers/TransformationProvider.cs:1720

  • These 'if' statements can be combined.
        if (_connection != null)
        {
            if (!_outsideConnection)
            {
                _connection.Close();
            }
        }

src/Migrator/Providers/TransformationProvider.cs:1802

  • These 'if' statements can be combined.
        if (defaultValue is DateTime defaultValueDateTime)
        {
            if (defaultValueDateTime.Kind != DateTimeKind.Utc)
            {
                throw new Exception("Only UTC values are accepted as default DateTime values.");
            }
        }

src/Migrator/Providers/TransformationProvider.cs:2216

  • These 'if' statements can be combined.
        if (hasFilterItems)
        {
            if (!index.FilterItems.All(x => index.KeyColumns.Any(y => x.ColumnName.Equals(y, StringComparison.OrdinalIgnoreCase))))
            {
                throw new MigrationException($"All columns in the {nameof(index.FilterItems)} should exist in the {nameof(index.KeyColumns)}.");
            }
        }

src/Migrator/Providers/TransformationProvider.cs:2229

  • These 'if' statements can be combined.
        if (index.IncludeColumns != null && index.IncludeColumns.Length > 0)
        {
            if (index.IncludeColumns.Any(x => index.KeyColumns.Any(y => x.Equals(y, StringComparison.OrdinalIgnoreCase))))
            {
                throw new MigrationException($"It is not allowed to use a column in {nameof(index.IncludeColumns)} that exist in {nameof(index.KeyColumns)}.");
            }
        }

src/Migrator/Providers/TransformationProvider.cs:39

  • Field '_scope' can be 'readonly'.
    private string _scope;

src/Migrator/Providers/TransformationProvider.cs:1948

  • Both branches of this 'if' statement return - consider using '?' to express intent better.
            if (null == val)
            {
                return "null";
            }
            else
            {
                return string.Format("'{0}'", val.Replace("'", "''"));
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


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.
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.
@jogibear9988 jogibear9988 deleted the add-primary-key branch January 12, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants