diff --git a/src/Migrator.Tests/Providers/Generic/Generic_AddPrimaryKey.cs b/src/Migrator.Tests/Providers/Generic/Generic_AddPrimaryKey.cs
index 420608b..1d26a81 100644
--- a/src/Migrator.Tests/Providers/Generic/Generic_AddPrimaryKey.cs
+++ b/src/Migrator.Tests/Providers/Generic/Generic_AddPrimaryKey.cs
@@ -1,9 +1,47 @@
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using DotNetProjects.Migrator.Framework;
using Migrator.Tests.Providers.Base;
using NUnit.Framework;
namespace Migrator.Tests.Providers.Generic;
[TestFixture]
-[Category("SQLite")]
-public class Generic_AddPrimaryTestsBase : TransformationProviderBase
-{ }
\ No newline at end of file
+public abstract class Generic_AddPrimaryTestsBase : TransformationProviderBase
+{
+ [Test]
+ public void AddPrimaryKey_IdentityColumnWithData_Success()
+ {
+ // Arrange
+ const string tableName = "TestTable";
+ const string columnName1 = "TestColumn1";
+ const string columnName2 = "TestColumn2";
+
+ Provider.AddTable(tableName,
+ new Column(columnName1, DbType.Int32, property: ColumnProperty.Identity | ColumnProperty.PrimaryKey),
+ new Column(columnName2, DbType.String)
+ );
+
+ // Act
+ Provider.Insert(tableName, [columnName2], ["Hello"]);
+ Provider.Insert(tableName, [columnName2], ["Hello2"]);
+
+ // Assert
+
+ List<(int, string)> list = [];
+
+ using var cmd = Provider.CreateCommand();
+ using var reader = Provider.Select(cmd, tableName, [columnName1, columnName2]);
+
+ while (reader.Read())
+ {
+ list.Add((reader.GetInt32(0), reader.GetString(1)));
+ }
+
+ list = list.OrderBy(x => x.Item1).ToList();
+
+ Assert.That(list[0].Item1, Is.EqualTo(1));
+ Assert.That(list[1].Item1, Is.EqualTo(2));
+ }
+}
\ No newline at end of file
diff --git a/src/Migrator/Framework/ITransformationProvider.cs b/src/Migrator/Framework/ITransformationProvider.cs
index 835974a..fcfcdbc 100644
--- a/src/Migrator/Framework/ITransformationProvider.cs
+++ b/src/Migrator/Framework/ITransformationProvider.cs
@@ -272,6 +272,7 @@ public interface ITransformationProvider : IDisposable
/// The name of the table that will get the primary key.
/// The name of the column or columns that are in the primary key.
void AddPrimaryKey(string name, string table, params string[] columns);
+
void AddPrimaryKeyNonClustered(string name, string table, params string[] columns);
///
/// Add a constraint to a table
diff --git a/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs b/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs
index 031bbc0..d157fac 100644
--- a/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs
+++ b/src/Migrator/Providers/Impl/Oracle/OracleTransformationProvider.cs
@@ -887,9 +887,12 @@ public override void AddTable(string name, params IDbField[] fields)
base.AddTable(name, fields);
- if (columns.Any(c => c.ColumnProperty == ColumnProperty.PrimaryKeyWithIdentity))
+ // Should be refactored
+ if (columns.Any(c => c.ColumnProperty == ColumnProperty.PrimaryKeyWithIdentity ||
+ (c.ColumnProperty.HasFlag(ColumnProperty.Identity) && c.ColumnProperty.HasFlag(ColumnProperty.PrimaryKey))))
{
- var identityColumn = columns.First(c => c.ColumnProperty == ColumnProperty.PrimaryKeyWithIdentity);
+ var identityColumn = columns.First(c => c.ColumnProperty == ColumnProperty.PrimaryKeyWithIdentity ||
+ (c.ColumnProperty.HasFlag(ColumnProperty.Identity) && c.ColumnProperty.HasFlag(ColumnProperty.PrimaryKey)));
var seqTName = name.Length > 21 ? name.Substring(0, 21) : name;
if (seqTName.EndsWith("_"))