Skip to content
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
13 changes: 12 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ dotnet_naming_style.interface_style.required_prefix = I
dotnet_naming_style.async_method_style.capitalization = pascal_case
dotnet_naming_style.async_method_style.required_suffix = Async

dotnet_naming_style.underscore_pascalcase.capitalization = pascal_case
dotnet_naming_style.underscore_pascalcase.required_prefix = _

# === Symbols ===
dotnet_naming_symbols.public_api_symbols.applicable_kinds = class, struct, enum, property, method, event, field, delegate, namespace
dotnet_naming_symbols.public_api_symbols.applicable_accessibilities = public, protected, protected_internal

dotnet_naming_symbols.protected_fields.applicable_kinds = field
dotnet_naming_symbols.protected_fields.applicable_accessibilities = protected

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

Expand All @@ -113,6 +119,10 @@ dotnet_naming_rule.public_api_should_be_pascal_case.symbols = public_api_symbols
dotnet_naming_rule.public_api_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.public_api_should_be_pascal_case.severity = warning

dotnet_naming_rule.protected_fields_should_be_prefixed_with_underscore_and_pascalcase.symbols = protected_fields
dotnet_naming_rule.protected_fields_should_be_prefixed_with_underscore_and_pascalcase.style = underscore_pascalcase
dotnet_naming_rule.protected_fields_should_be_prefixed_with_underscore_and_pascalcase.severity = warning

dotnet_naming_rule.private_fields_should_be_underscore_camel.symbols = private_fields
dotnet_naming_rule.private_fields_should_be_underscore_camel.style = underscore_camel_case_style
dotnet_naming_rule.private_fields_should_be_underscore_camel.severity = warning
Expand Down Expand Up @@ -167,7 +177,7 @@ csharp_new_line_between_query_expression_clauses = true
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_case_contents_when_block = false
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

Expand Down Expand Up @@ -229,6 +239,7 @@ dotnet_diagnostic.SA1600.severity = suggestion # Elements must be documented
dotnet_diagnostic.SA1623.severity = suggestion # Property summary must match accessor

# Code quality
dotnet_diagnostic.IDE0005.severity = error # Unused usings
dotnet_diagnostic.IDE0040.severity = warning # Accessibility modifiers
dotnet_diagnostic.IDE0052.severity = warning # Remove unread private members
dotnet_diagnostic.IDE0059.severity = warning # Unused assignment
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.wordWrapColumn": 230
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,18 @@ public void UpdateFromTableToTable_Success()
Provider.Insert(tableNameTarget, [columnName1Target, columnName2Target, columnName3Target, columnName4Target, columnName5Target], [1, 3, "target no update", "target no update", "target no update"]);

// Act
Provider.UpdateFromTableToTable(
Provider.UpdateTargetFromSource(
tableNameSource,
tableNameTarget,
[
new ColumnPair { ColumnNameSourceNotQuoted = columnName3Source, ColumnNameTargetNotQuoted = columnName3Target },
new ColumnPair { ColumnNameSourceNotQuoted = columnName4Source, ColumnNameTargetNotQuoted = columnName4Target },
new ColumnPair { ColumnNameSourceNotQuoted = columnName5Source, ColumnNameTargetNotQuoted = columnName5Target }
new () { ColumnNameSource = columnName3Source, ColumnNameTarget = columnName3Target },
new () { ColumnNameSource = columnName4Source, ColumnNameTarget = columnName4Target },
new () { ColumnNameSource = columnName5Source, ColumnNameTarget = columnName5Target }
],
[
new ColumnPair { ColumnNameSourceNotQuoted = columnName1Source, ColumnNameTargetNotQuoted = columnName1Target },
new ColumnPair { ColumnNameSourceNotQuoted = columnName2Source, ColumnNameTargetNotQuoted = columnName2Target }
]
);
new () { ColumnNameSource = columnName1Source, ColumnNameTarget = columnName1Target },
new () { ColumnNameSource = columnName2Source, ColumnNameTarget = columnName2Target }
]);

// Assert
List<UpdateFromTableToTableModel> targetRows = [];
Expand Down
12 changes: 6 additions & 6 deletions src/Migrator/Framework/ITransformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,13 @@ IDataReader SelectComplex(IDbCommand cmd, string table, string[] columns, string
int Update(string table, string[] columns, object[] values, string[] whereColumns, object[] whereValues);

/// <summary>
/// Updates the target table using data from the source table updating the target table. Make sure to only use primary keys or unique columns in <paramref name="conditionColumnPairs"/>
/// Updates the target table with data from the source table. Make sure to use primary key or unique columns in <paramref name="matchColumnPairs"/>
/// </summary>
/// <param name="tableSourceNotQuoted"></param>
/// <param name="tableTargetNotQuoted"></param>
/// <param name="fromSourceToTargetColumnPairs">Pairs that represent the name of the source column and the column in the target table to be updated.</param>
/// <param name="conditionColumnPairs">Pairs that represent the name of the source column and the name of the target tabel used to match the rows.</param>
void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs);
/// <param name="tableNameSource">Source table name (unquoted).</param>
/// <param name="tableNameTarget">Target table name (unquoted).</param>
/// <param name="copyColumnPairs">Pairs of columns that are used to copy data from column in source table to column in target table.</param>
/// <param name="matchColumnPairs">Pairs of columns that are used to match rows in source and target table.</param>
void UpdateTargetFromSource(string tableNameSource, string tableNameTarget, ColumnPair[] copyColumnPairs, ColumnPair[] matchColumnPairs);

/// <summary>
/// Get a command instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ public override bool IndexExists(string table, string name)
return Convert.ToInt32(scalar) == 1;
}

public override void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public override void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
if (!TableExists(tableSourceNotQuoted))
{
Expand All @@ -925,7 +925,7 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(fromSourceToTargetColumnPairs)} is empty.");
}

if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(fromSourceToTargetColumnPairs)} is null or empty");
}
Expand All @@ -935,17 +935,17 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(conditionColumnPairs)} is empty.");
}

if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(conditionColumnPairs)} is null or empty");
}

var tableNameSource = QuoteTableNameIfRequired(tableSourceNotQuoted);
var tableNameTarget = QuoteTableNameIfRequired(tableTargetNotQuoted);

var conditionStrings = conditionColumnPairs.Select(x => $"t.{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}");
var conditionStrings = conditionColumnPairs.Select(x => $"t.{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSource)}");

var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}").ToList();
var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSource)}").ToList();

var conditionStringsJoined = string.Join(" AND ", conditionStrings);
var assignStringsJoined = string.Join(", ", assignStrings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public override bool IndexExists(string table, string name)
return reader.Read();
}

public override void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public override void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
if (!TableExists(tableSourceNotQuoted))
{
Expand All @@ -833,7 +833,7 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(fromSourceToTargetColumnPairs)} is empty.");
}

if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(fromSourceToTargetColumnPairs)} is null or empty");
}
Expand All @@ -843,17 +843,17 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(conditionColumnPairs)} is empty.");
}

if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(conditionColumnPairs)} is null or empty");
}

var tableNameSource = QuoteTableNameIfRequired(tableSourceNotQuoted);
var tableNameTarget = QuoteTableNameIfRequired(tableTargetNotQuoted);

var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = {tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}").ToList();
var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = {tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSource)}").ToList();

var conditionStrings = conditionColumnPairs.Select(x => $"{tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)} = {tableNameTarget}.{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)}");
var conditionStrings = conditionColumnPairs.Select(x => $"{tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSource)} = {tableNameTarget}.{QuoteColumnNameIfRequired(x.ColumnNameTarget)}");

var assignStringsJoined = string.Join(", ", assignStrings);
var conditionStringsJoined = string.Join(" AND ", conditionStrings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
return foreignKeyConstraints.ToArray();
}

public override void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public override void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
if (!TableExists(tableSourceNotQuoted))
{
Expand All @@ -227,7 +227,7 @@
throw new Exception($"{nameof(fromSourceToTargetColumnPairs)} is empty.");
}

if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(fromSourceToTargetColumnPairs)} is null or empty");
}
Expand All @@ -237,17 +237,17 @@
throw new Exception($"{nameof(conditionColumnPairs)} is empty.");
}

if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(conditionColumnPairs)} is null or empty");
}

var tableNameSource = QuoteTableNameIfRequired(tableSourceNotQuoted);
var tableNameTarget = QuoteTableNameIfRequired(tableTargetNotQuoted);

var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = {tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}").ToList();
var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = {tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSource)}").ToList();

var conditionStrings = conditionColumnPairs.Select(x => $"{tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)} = {tableNameTarget}.{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)}");
var conditionStrings = conditionColumnPairs.Select(x => $"{tableNameSource}.{QuoteColumnNameIfRequired(x.ColumnNameSource)} = {tableNameTarget}.{QuoteColumnNameIfRequired(x.ColumnNameTarget)}");

var assignStringsJoined = string.Join(", ", assignStrings);
var conditionStringsJoined = string.Join(" AND ", conditionStrings);
Expand Down Expand Up @@ -879,7 +879,7 @@
}

[Obsolete]
public override void AddTable(string table, string engine, string columns)

Check warning on line 882 in src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs

View workflow job for this annotation

GitHub Actions / build

Obsolete member 'SQLiteTransformationProvider.AddTable(string, string, string)' overrides non-obsolete member 'TransformationProvider.AddTable(string, string, string)'
{
throw new NotSupportedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public override void RenameTable(string oldName, string newName)
ExecuteNonQuery(string.Format("EXEC sp_rename '{0}', '{1}'", oldName, newName));
}

public override void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public override void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
if (!TableExists(tableSourceNotQuoted))
{
Expand All @@ -818,7 +818,7 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(fromSourceToTargetColumnPairs)} is empty.");
}

if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (fromSourceToTargetColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(fromSourceToTargetColumnPairs)} is null or empty");
}
Expand All @@ -828,17 +828,17 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string
throw new Exception($"{nameof(conditionColumnPairs)} is empty.");
}

if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSourceNotQuoted) || string.IsNullOrWhiteSpace(x.ColumnNameTargetNotQuoted)))
if (conditionColumnPairs.Any(x => string.IsNullOrWhiteSpace(x.ColumnNameSource) || string.IsNullOrWhiteSpace(x.ColumnNameTarget)))
{
throw new Exception($"One of the strings in {nameof(conditionColumnPairs)} is null or empty");
}

var tableNameSource = QuoteTableNameIfRequired(tableSourceNotQuoted);
var tableNameTarget = QuoteTableNameIfRequired(tableTargetNotQuoted);

var conditionStrings = conditionColumnPairs.Select(x => $"t.{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}");
var conditionStrings = conditionColumnPairs.Select(x => $"t.{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSource)}");

var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTargetNotQuoted)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSourceNotQuoted)}").ToList();
var assignStrings = fromSourceToTargetColumnPairs.Select(x => $"{QuoteColumnNameIfRequired(x.ColumnNameTarget)} = s.{QuoteColumnNameIfRequired(x.ColumnNameSource)}").ToList();

var conditionStringsJoined = string.Join(" AND ", conditionStrings);
var assignStringsJoined = string.Join(", ", assignStrings);
Expand Down
8 changes: 4 additions & 4 deletions src/Migrator/Providers/Models/ColumnPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace DotNetProjects.Migrator.Framework.Models;
public class ColumnPair
{
/// <summary>
/// Gets or sets the column name of the source table. Use the not quoted column name.
/// Gets or sets the column name of the source table. Use the unquoted column name.
/// </summary>
public string ColumnNameSourceNotQuoted { get; set; }
public string ColumnNameSource { get; set; }

/// <summary>
/// Gets or sets the column name of the target table. Use the not quoted column name.
/// Gets or sets the column name of the target table. Use the unquoted column name.
/// </summary>
public string ColumnNameTargetNotQuoted { get; set; }
public string ColumnNameTarget { get; set; }
}
2 changes: 1 addition & 1 deletion src/Migrator/Providers/NoOpTransformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ public void AddColumn(string table, string column, MigratorDbType type, object d
throw new NotImplementedException();
}

public void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Migrator/Providers/TransformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,9 @@

public virtual void ChangeColumn(string table, Column column)
{
var isUniqueSet = column.ColumnProperty.IsSet(ColumnProperty.Unique);

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

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

column.ColumnProperty = column.ColumnProperty.Clear(ColumnProperty.Unique);

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

View workflow job for this annotation

GitHub Actions / build

'ColumnProperty.Unique' is obsolete: 'Use method 'AddUniqueConstraint' instead. This is marked being obsolete since you cannot add a name for the constraint which makes it difficult to remove the constraint again.'

var mapper = _dialect.GetAndMapColumnProperties(column);

Expand Down Expand Up @@ -1332,7 +1332,7 @@
return command.ExecuteNonQuery();
}

public virtual void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
public virtual void UpdateTargetFromSource(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs)
{
throw new NotImplementedException();
}
Expand Down
Loading