diff --git a/src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs b/src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs index df68c18c..3990cefa 100644 --- a/src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs +++ b/src/Migrator.Providers/Impl/Mysql/MySqlTransformationProvider.cs @@ -53,7 +53,14 @@ INNER JOIN information_schema.TABLE_CONSTRAINTS i if (tuple.Item3 == "FOREIGN KEY") RemoveForeignKey(tuple.Item1, tuple.Item2); else if (tuple.Item3 == "PRIMARY KEY") - ExecuteNonQuery(String.Format("ALTER TABLE {0} DROP PRIMARY KEY", table)); + { + try + { + ExecuteNonQuery(String.Format("ALTER TABLE {0} DROP PRIMARY KEY", table)); + } + catch (Exception) + { } + } else if (tuple.Item3 == "UNIQUE") RemoveIndex(tuple.Item1, tuple.Item2); } diff --git a/src/Migrator.Providers/Impl/Oracle/OracleTransformationProvider.cs b/src/Migrator.Providers/Impl/Oracle/OracleTransformationProvider.cs index f9c8d502..c38cee00 100644 --- a/src/Migrator.Providers/Impl/Oracle/OracleTransformationProvider.cs +++ b/src/Migrator.Providers/Impl/Oracle/OracleTransformationProvider.cs @@ -175,7 +175,53 @@ public override void AddColumn(string table, string sqlColumn) table = QuoteTableNameIfRequired(table); sqlColumn = QuoteColumnNameIfRequired(sqlColumn); ExecuteNonQuery(String.Format("ALTER TABLE {0} ADD {1}", table, sqlColumn)); - } + } + + public override string[] GetConstraints(string table) + { + var constraints = new List(); + //using ( + // IDataReader reader = + // ExecuteQuery( + // String.Format("SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE LOWER(TABLE_NAME) = LOWER('{0}')", table))) + //{ + // while (reader.Read()) + // { + // constraints.Add(reader.GetString(0)); + // } + //} + + using ( + IDataReader reader = + ExecuteQuery( + String.Format("SELECT constraint_name FROM user_constraints WHERE lower(table_name) = '{0}'", table.ToLower()))) + { + while (reader.Read()) + { + constraints.Add(reader.GetString(0)); + } + } + + return constraints.ToArray(); + } + + protected override string GetPrimaryKeyConstraintName(string table) + { + var constraints = new List(); + + using ( + IDataReader reader = + ExecuteQuery( + String.Format("SELECT constraint_name FROM user_constraints WHERE lower(table_name) = '{0}' and constraint_type = 'P'", table.ToLower()))) + { + while (reader.Read()) + { + constraints.Add(reader.GetString(0)); + } + } + + return constraints.FirstOrDefault(); + } public override bool ConstraintExists(string table, string name) { @@ -207,7 +253,7 @@ public override bool TableExists(string table) string sql = string.Format("SELECT COUNT(table_name) FROM user_tables WHERE lower(table_name) = '{0}'", table.ToLower()); if (_defaultSchema != null) - sql = string.Format("SELECT COUNT(table_name) FROM all_tables WHERE lower(owner) = '{0}' and lower(table_name) = '{1}'", _defaultSchema.ToLower(), table.ToLower()); + sql = string.Format("SELECT COUNT(table_name) FROM user_tables WHERE lower(owner) = '{0}' and lower(table_name) = '{1}'", _defaultSchema.ToLower(), table.ToLower()); Logger.Log(sql); object count = ExecuteScalar(sql); @@ -472,19 +518,19 @@ private string SchemaInfoTableName } } - protected override string GetPrimaryKeyConstraintName(string table) - { - var sql = "select constraint_name " + - "from user_indexes join user_constraints on user_indexes.index_name = user_constraints.constraint_name " + - "where lower(user_indexes.table_name) = lower('{0}') and constraint_type = 'P'"; + //protected override string GetPrimaryKeyConstraintName(string table) + //{ + // var sql = "select constraint_name " + + // "from user_indexes join user_constraints on user_indexes.index_name = user_constraints.constraint_name " + + // "where lower(user_indexes.table_name) = lower('{0}') and constraint_type = 'P'"; - sql = string.Format(sql, table); + // sql = string.Format(sql, table); - using (IDataReader reader = ExecuteQuery(sql)) - { - return reader.Read() ? reader.GetString(0) : null; - } - } + // using (IDataReader reader = ExecuteQuery(sql)) + // { + // return reader.Read() ? reader.GetString(0) : null; + // } + //} public override Index[] GetIndexes(string table) { diff --git a/src/Migrator.Providers/TransformationProvider.cs b/src/Migrator.Providers/TransformationProvider.cs index 57da3609..3e17091b 100644 --- a/src/Migrator.Providers/TransformationProvider.cs +++ b/src/Migrator.Providers/TransformationProvider.cs @@ -1539,7 +1539,7 @@ protected string QuoteConstraintNameIfRequired(string name) protected virtual string GetPrimaryKeyConstraintName(string table) { - throw new NotImplementedException(); + return null; } public virtual void RemovePrimaryKey(string table)