diff --git a/.editorconfig b/.editorconfig index 489eef37..39681c28 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..408a5079 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.wordWrapColumn": 230 +} \ No newline at end of file diff --git a/src/Migrator.Tests/Providers/Generic/Generic_UpdateFromTableToTableTestsBase.cs b/src/Migrator.Tests/Providers/Generic/Generic_UpdateFromTableToTableTestsBase.cs index fac1ca91..1e19fc29 100644 --- a/src/Migrator.Tests/Providers/Generic/Generic_UpdateFromTableToTableTestsBase.cs +++ b/src/Migrator.Tests/Providers/Generic/Generic_UpdateFromTableToTableTestsBase.cs @@ -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 targetRows = []; diff --git a/src/Migrator/Framework/ITransformationProvider.cs b/src/Migrator/Framework/ITransformationProvider.cs index 0a5d0dd6..cad4b97e 100644 --- a/src/Migrator/Framework/ITransformationProvider.cs +++ b/src/Migrator/Framework/ITransformationProvider.cs @@ -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); /// - /// 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 + /// Updates the target table with data from the source table. Make sure to use primary key or unique columns in /// - /// - /// - /// Pairs that represent the name of the source column and the column in the target table to be updated. - /// Pairs that represent the name of the source column and the name of the target tabel used to match the rows. - void UpdateFromTableToTable(string tableSourceNotQuoted, string tableTargetNotQuoted, ColumnPair[] fromSourceToTargetColumnPairs, ColumnPair[] conditionColumnPairs); + /// Source table name (unquoted). + /// Target table name (unquoted). + /// Pairs of columns that are used to copy data from column in source table to column in target table. + /// Pairs of columns that are used to match rows in source and target table. + void UpdateTargetFromSource(string tableNameSource, string tableNameTarget, ColumnPair[] copyColumnPairs, ColumnPair[] matchColumnPairs); /// /// Get a command instance diff --git a/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs b/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs index b3d82828..a7151122 100644 --- a/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs +++ b/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs @@ -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)) { @@ -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"); } @@ -935,7 +935,7 @@ 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"); } @@ -943,9 +943,9 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string 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); diff --git a/src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs b/src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs index 74d46083..76adbe8a 100644 --- a/src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs +++ b/src/Migrator/Providers/Impl/PostgreSQL/PostgreSQLTransformationProvider.cs @@ -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)) { @@ -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"); } @@ -843,7 +843,7 @@ 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"); } @@ -851,9 +851,9 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string 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); diff --git a/src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs b/src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs index 37c7bbf5..a948965f 100644 --- a/src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs +++ b/src/Migrator/Providers/Impl/SQLite/SQLiteTransformationProvider.cs @@ -210,7 +210,7 @@ public override ForeignKeyConstraint[] GetForeignKeyConstraints(string tableName 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)) { @@ -227,7 +227,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"); } @@ -237,7 +237,7 @@ 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"); } @@ -245,9 +245,9 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string 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); diff --git a/src/Migrator/Providers/Impl/SqlServer/SqlServerTransformationProvider.cs b/src/Migrator/Providers/Impl/SqlServer/SqlServerTransformationProvider.cs index 3b649356..4c946679 100644 --- a/src/Migrator/Providers/Impl/SqlServer/SqlServerTransformationProvider.cs +++ b/src/Migrator/Providers/Impl/SqlServer/SqlServerTransformationProvider.cs @@ -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)) { @@ -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"); } @@ -828,7 +828,7 @@ 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"); } @@ -836,9 +836,9 @@ public override void UpdateFromTableToTable(string tableSourceNotQuoted, string 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); diff --git a/src/Migrator/Providers/Models/ColumnPair.cs b/src/Migrator/Providers/Models/ColumnPair.cs index 6aa5e259..a0fb51a6 100644 --- a/src/Migrator/Providers/Models/ColumnPair.cs +++ b/src/Migrator/Providers/Models/ColumnPair.cs @@ -6,12 +6,12 @@ namespace DotNetProjects.Migrator.Framework.Models; public class ColumnPair { /// - /// 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. /// - public string ColumnNameSourceNotQuoted { get; set; } + public string ColumnNameSource { get; set; } /// - /// 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. /// - public string ColumnNameTargetNotQuoted { get; set; } + public string ColumnNameTarget { get; set; } } \ No newline at end of file diff --git a/src/Migrator/Providers/NoOpTransformationProvider.cs b/src/Migrator/Providers/NoOpTransformationProvider.cs index 387ed10d..b99cd0b1 100644 --- a/src/Migrator/Providers/NoOpTransformationProvider.cs +++ b/src/Migrator/Providers/NoOpTransformationProvider.cs @@ -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(); } diff --git a/src/Migrator/Providers/TransformationProvider.cs b/src/Migrator/Providers/TransformationProvider.cs index 86b5ab04..d3b6f8ed 100644 --- a/src/Migrator/Providers/TransformationProvider.cs +++ b/src/Migrator/Providers/TransformationProvider.cs @@ -1332,7 +1332,7 @@ public virtual int Update(string table, string[] columns, object[] values, strin 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(); }