Permalink
Browse files

Merge branch 'master' of https://github.com/schambers/fluentmigrator

  • Loading branch information...
spaccabit committed Dec 2, 2012
2 parents 77a0fcd + 021af65 commit 618660cdd83bb7aa275a79f24570fe0fc03e9620
Showing with 1,480 additions and 132 deletions.
  1. +2 −2 src/FluentMigrator.Runner/Generators/Generic/GenericGenerator.cs
  2. +8 −0 src/FluentMigrator.Runner/Generators/Generic/GenericQuoter.cs
  3. +1 −0 src/FluentMigrator.Runner/Generators/IQuoter.cs
  4. +0 −6 src/FluentMigrator.Runner/Generators/Oracle/OracleQuoter.cs
  5. +31 −3 src/FluentMigrator.Runner/Generators/SqlServer/SqlServerCeGenerator.cs
  6. +1 −1 src/FluentMigrator.Runner/Generators/SqlServer/SqlServerCeTypeMap.cs
  7. +9 −9 src/FluentMigrator.Runner/Processors/DotConnectOracle/DotConnectOracleProcessor.cs
  8. +3 −3 src/FluentMigrator.Runner/Processors/DotConnectOracle/DotConnectOracleProcessorFactory.cs
  9. +13 −22 src/FluentMigrator.Runner/Processors/Oracle/OracleProcessor.cs
  10. +20 −20 src/FluentMigrator.Runner/Processors/SqlServer/SqlServerCeProcessor.cs
  11. +17 −2 src/FluentMigrator.Tests/FluentMigrator.Tests.csproj
  12. +112 −0 src/FluentMigrator.Tests/Helpers/OracleTestTable.cs
  13. +92 −0 src/FluentMigrator.Tests/Helpers/SqlServerCeTestTable.cs
  14. +228 −10 src/FluentMigrator.Tests/Integration/Processors/OracleProcessorTests.cs
  15. +200 −0 src/FluentMigrator.Tests/Integration/Processors/SqlServerCeProcessorTests.cs
  16. +13 −0 src/FluentMigrator.Tests/IntegrationTestOptions.cs
  17. +1 −1 src/FluentMigrator.Tests/Unit/Generators/GenericGenerator/QuoterTests.cs
  18. +20 −20 src/FluentMigrator.Tests/Unit/Generators/Oracle/OracleAlterTableTests.cs
  19. +4 −4 src/FluentMigrator.Tests/Unit/Generators/Oracle/OracleCreateSequenceTests.cs
  20. +11 −11 src/FluentMigrator.Tests/Unit/Generators/Oracle/OracleCreateTableTests.cs
  21. +8 −8 src/FluentMigrator.Tests/Unit/Generators/Oracle/OracleDataTests.cs
  22. +6 −6 src/FluentMigrator.Tests/Unit/Generators/Oracle/OracleDropTableTests.cs
  23. +238 −0 src/FluentMigrator.Tests/Unit/Generators/SqlServerCe/SqlServerCeAlterTableTests.cs
  24. +204 −0 src/FluentMigrator.Tests/Unit/Generators/SqlServerCe/SqlServerCeCreateTableTests.cs
  25. +123 −0 src/FluentMigrator.Tests/Unit/Generators/SqlServerCe/SqlServerCeData.cs
  26. +82 −0 src/FluentMigrator.Tests/Unit/Generators/SqlServerCe/SqlServerCeDropTableTests.cs
  27. +29 −0 src/FluentMigrator.Tests/Unit/Generators/SqlServerCe/SqlServerCeGeneratorTests.cs
  28. +4 −4 src/FluentMigrator/VersionTableInfo/DefaultVersionTableMetaData.cs
@@ -177,7 +177,7 @@ public override string Generate(CreateForeignKeyExpression expression)
return string.Format(
CreateForeignKeyConstraint,
Quoter.QuoteTableName(expression.ForeignKey.ForeignTable),
- Quoter.QuoteColumnName(keyName),
+ Quoter.QuoteConstraintName(keyName),
String.Join(", ", foreignColumns.ToArray()),
Quoter.QuoteTableName(expression.ForeignKey.PrimaryTable),
String.Join(", ", primaryColumns.ToArray()),
@@ -199,7 +199,7 @@ public override string Generate(CreateConstraintExpression expression)
}
return string.Format(CreateConstraint, Quoter.QuoteTableName(expression.Constraint.TableName),
- Quoter.Quote(expression.Constraint.ConstraintName),
+ Quoter.QuoteConstraintName(expression.Constraint.ConstraintName),
constraintType,
String.Join(", ", columns));
}
@@ -149,6 +149,14 @@ public virtual string QuoteColumnName(string columnName)
return IsQuoted(columnName) ? columnName : Quote(columnName);
}
+ /// <summary>
+ /// Quotes a constraint name
+ /// </summary>
+ public virtual string QuoteConstraintName(string constraintName)
+ {
+ return IsQuoted(constraintName) ? constraintName : Quote(constraintName);
+ }
+
/// <summary>
/// Quote an index name
/// </summary>
@@ -9,6 +9,7 @@ public interface IQuoter
string QuoteColumnName(string columnName);
string QuoteTableName(string tableName);
string QuoteIndexName(string indexName);
+ string QuoteConstraintName(string contraintName);
string QuoteSchemaName(string schemaName);
string QuoteCommand(string command);
string QuoteSequenceName(string sequenceName);
@@ -10,11 +10,5 @@ public override string FormatDateTime(DateTime value)
var result = string.Format("to_date({0}{1}{0}, {0}yyyy-mm-dd hh24:mi:ss{0})", ValueQuote, value.ToString("yyyy-MM-dd HH:mm:ss")); //ISO 8601 DATETIME FORMAT (EXCEPT 'T' CHAR)
return result;
}
-
- //Not what to do here. Orcale quotes are " but if we do that then the column and table names become case
- //sensitive. For now we will just set it to not quote
- public override string OpenQuote { get { return string.Empty; } }
-
- public override string CloseQuote { get { return string.Empty; } }
}
}
@@ -23,18 +23,31 @@
namespace FluentMigrator.Runner.Generators.SqlServer
{
- public class SqlServerCeGenerator : SqlServer2005Generator
+ public class SqlServerCeGenerator : SqlServer2000Generator
{
public SqlServerCeGenerator()
: base(new SqlServerColumn(new SqlServerCeTypeMap()))
{
}
- //I think that this would be better inheriting form the SqlServer 2000 Generator. It seems to match it better
+ public override string GetClusterTypeString(CreateIndexExpression column)
+ {
+ return string.Empty;
+ }
+
+ protected string GetConstraintClusteringString(CreateConstraintExpression constraint)
+ {
+ return string.Empty;
+ }
public override string Generate(RenameTableExpression expression)
{
- return String.Format("sp_rename '{0}', '{1}'", Quoter.QuoteTableName(expression.OldName), Quoter.QuoteTableName(expression.NewName));
+ return String.Format("sp_rename {0}, {1}", Quoter.QuoteValue(expression.OldName), Quoter.QuoteValue(expression.NewName));
+ }
+
+ public override string Generate(RenameColumnExpression expression)
+ {
+ throw new DatabaseOperationNotSupportedException();
}
//All Schema method throw by default as only Sql server 2005 and up supports them.
@@ -55,6 +68,11 @@ public override string Generate(AlterSchemaExpression expression)
public override string Generate(DeleteColumnExpression expression)
{
+ if (expression.ColumnNames.Count != 1)
+ {
+ throw new DatabaseOperationNotSupportedException();
+ }
+
// Limited functionality in CE, for now will just drop the column.. no DECLARE support!
const string sql = @"ALTER TABLE {0} DROP COLUMN {1};";
return String.Format(sql, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnNames.ElementAt(0)));
@@ -64,5 +82,15 @@ public override string Generate(DeleteIndexExpression expression)
{
return String.Format("DROP INDEX {0}.{1}", Quoter.QuoteTableName(expression.Index.TableName), Quoter.QuoteIndexName(expression.Index.Name));
}
+
+ public override string Generate(AlterDefaultConstraintExpression expression)
+ {
+ throw new DatabaseOperationNotSupportedException();
+ }
+
+ public override string Generate(DeleteDefaultConstraintExpression expression)
+ {
+ throw new DatabaseOperationNotSupportedException();
+ }
}
}
@@ -49,7 +49,7 @@ protected override void SetupTypeMaps()
SetTypeMap(DbType.DateTime, "DATETIME");
SetTypeMap(DbType.Decimal, "NUMERIC(19,5)");
SetTypeMap(DbType.Decimal, "NUMERIC($size,$precision)", DecimalCapacity);
- SetTypeMap(DbType.Double, "DOUBLE PRECISION");
+ SetTypeMap(DbType.Double, "FLOAT");
SetTypeMap(DbType.Guid, "UNIQUEIDENTIFIER");
SetTypeMap(DbType.Int16, "SMALLINT");
SetTypeMap(DbType.Int32, "INT");
@@ -14,13 +14,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
-#endregion
-
-using System;
-using System.Data;
-using FluentMigrator.Builders.Execute;
-using FluentMigrator.Runner.Processors.Oracle;
-
+#endregion
+
+using System;
+using System.Data;
+using FluentMigrator.Builders.Execute;
+using FluentMigrator.Runner.Processors.Oracle;
+
namespace FluentMigrator.Runner.Processors.DotConnectOracle
{
public class DotConnectOracleProcessor : ProcessorBase
@@ -31,8 +31,8 @@ public class DotConnectOracleProcessor : ProcessorBase
public override string DatabaseType
{
get { return "Oracle"; }
- }
-
+ }
+
public DotConnectOracleProcessor(IDbConnection connection, IMigrationGenerator generator, IAnnouncer announcer, IMigrationProcessorOptions options, DotConnectOracleDbFactory factory)
: base(generator, announcer, options)
{
@@ -1,6 +1,6 @@
-using FluentMigrator.Runner.Generators.Oracle;
-using FluentMigrator.Runner.Processors.Oracle;
-
+using FluentMigrator.Runner.Generators.Oracle;
+using FluentMigrator.Runner.Processors.Oracle;
+
namespace FluentMigrator.Runner.Processors.DotConnectOracle
{
public class DotConnectOracleProcessorFactory : MigrationProcessorFactory
@@ -24,7 +24,7 @@ namespace FluentMigrator.Runner.Processors.Oracle
{
public class OracleProcessor : ProcessorBase
{
- private IDbConnection Connection { get; set; }
+ public IDbConnection Connection { get; private set; }
private readonly IDbFactory _factory;
public override string DatabaseType
@@ -50,7 +50,7 @@ public override bool SchemaExists(string schemaName)
if (schemaName.Length == 0)
return false;
- return Exists("SELECT 1 FROM ALL_USERS WHERE USERNAME = '{0}'", schemaName.ToUpper());
+ return Exists("SELECT 1 FROM \"ALL_USERS\" WHERE \"USERNAME\" = '{0}'", schemaName.ToUpper());
}
public override bool TableExists(string schemaName, string tableName)
@@ -62,9 +62,9 @@ public override bool TableExists(string schemaName, string tableName)
return false;
if (string.IsNullOrEmpty(schemaName))
- return Exists("SELECT 1 FROM USER_TABLES WHERE TABLE_NAME = '{0}'", tableName.ToUpper());
+ return Exists("SELECT 1 FROM \"USER_TABLES\" WHERE \"TABLE_NAME\" = '{0}'", tableName);
- return Exists("SELECT 1 FROM ALL_TABLES WHERE OWNER = '{0}' AND TABLE_NAME = '{1}'", schemaName.ToUpper(), tableName.ToUpper());
+ return Exists("SELECT 1 FROM \"ALL_TABLES\" WHERE \"OWNER\" = '{0}' AND \"TABLE_NAME\" = '{1}'", schemaName.ToUpper(), tableName);
}
public override bool ColumnExists(string schemaName, string tableName, string columnName)
@@ -78,9 +78,9 @@ public override bool ColumnExists(string schemaName, string tableName, string co
return false;
if (string.IsNullOrEmpty(schemaName))
- return Exists("SELECT 1 FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '{0}' AND COLUMN_NAME = '{1}'", tableName.ToUpper(), columnName.ToUpper());
+ return Exists("SELECT 1 FROM \"USER_TAB_COLUMNS\" WHERE \"TABLE_NAME\" = '{0}' AND \"COLUMN_NAME\" = '{1}'", tableName, columnName);
- return Exists("SELECT 1 FROM ALL_TAB_COLUMNS WHERE OWNER = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schemaName.ToUpper(), tableName.ToUpper(), columnName.ToUpper());
+ return Exists("SELECT 1 FROM \"ALL_TAB_COLUMNS\" WHERE \"OWNER\" = '{0}' AND \"TABLE_NAME\" = '{1}' AND \"COLUMN_NAME\" = '{2}'", schemaName.ToUpper(), tableName, columnName);
}
public override bool ConstraintExists(string schemaName, string tableName, string constraintName)
@@ -96,9 +96,9 @@ public override bool ConstraintExists(string schemaName, string tableName, strin
return false;
if (String.IsNullOrEmpty(schemaName))
- return Exists("SELECT 1 FROM USER_CONSTRAINTS WHERE CONSTRAINT_NAME = '{0}'", constraintName.ToUpper());
+ return Exists("SELECT 1 FROM \"USER_CONSTRAINTS\" WHERE \"CONSTRAINT_NAME\" = '{0}'", constraintName);
- return Exists("SELECT 1 FROM ALL_CONSTRAINTS WHERE OWNER = '{0}' AND CONSTRAINT_NAME = '{1}'", schemaName.ToUpper(), constraintName.ToUpper());
+ return Exists("SELECT 1 FROM \"ALL_CONSTRAINTS\" WHERE \"OWNER\" = '{0}' AND \"CONSTRAINT_NAME\" = '{1}'", schemaName.ToUpper(), constraintName);
}
public override bool IndexExists(string schemaName, string tableName, string indexName)
@@ -114,23 +114,14 @@ public override bool IndexExists(string schemaName, string tableName, string ind
return false;
if (String.IsNullOrEmpty(schemaName))
- return Exists("SELECT 1 FROM USER_INDEXES WHERE INDEX_NAME = '{0}'", indexName.ToUpper());
+ return Exists("SELECT 1 FROM \"USER_INDEXES\" WHERE \"INDEX_NAME\" = '{0}'", indexName);
- return Exists("SELECT 1 FROM ALL_INDEXES WHERE OWNER = '{0}' AND INDEX_NAME = '{1}'", schemaName.ToUpper(), indexName.ToUpper());
+ return Exists("SELECT 1 FROM \"ALL_INDEXES\" WHERE \"OWNER\" = '{0}' AND \"INDEX_NAME\" = '{1}'", schemaName.ToUpper(), indexName);
}
public override void Execute(string template, params object[] args)
{
- if (template == null)
- throw new ArgumentNullException("template");
-
- if (Connection.State != ConnectionState.Open)
- Connection.Open();
-
- using (var command = _factory.CreateCommand(String.Format(template, args), Connection))
- {
- command.ExecuteNonQuery();
- }
+ Process(string.Format(template, args));
}
public override bool Exists(string template, params object[] args)
@@ -154,9 +145,9 @@ public override DataSet ReadTableData(string schemaName, string tableName)
throw new ArgumentNullException("tableName");
if (String.IsNullOrEmpty(schemaName))
- return Read("SELECT * FROM {0}", tableName.ToUpper());
+ return Read("SELECT * FROM \"{0}\"", tableName);
- return Read("SELECT * FROM {0}.{1}", schemaName.ToUpper(), tableName.ToUpper());
+ return Read("SELECT * FROM \"{0}\".\"{1}\"", schemaName, tableName);
}
public override DataSet Read(string template, params object[] args)
@@ -27,7 +27,7 @@ namespace FluentMigrator.Runner.Processors.SqlServer
public sealed class SqlServerCeProcessor : ProcessorBase
{
private readonly IDbFactory factory;
- private readonly IDbConnection connection;
+ public IDbConnection Connection { get; private set; }
private IDbTransaction transaction;
public override string DatabaseType
@@ -39,14 +39,14 @@ public SqlServerCeProcessor(IDbConnection connection, IMigrationGenerator genera
: base(generator, announcer, options)
{
this.factory = factory;
- this.connection = connection;
+ Connection = connection;
connection.Open();
BeginTransaction();
}
public override bool SchemaExists(string schemaName)
{
- return Exists("SELECT * FROM SYS.SCHEMAS WHERE NAME = '{0}'", FormatSqlEscape(schemaName));
+ return true; // SqlServerCe has no schemas
}
public override bool TableExists(string schemaName, string tableName)
@@ -61,12 +61,12 @@ public override bool ColumnExists(string schemaName, string tableName, string co
public override bool ConstraintExists(string schemaName, string tableName, string constraintName)
{
- return Exists("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_CATALOG = DB_NAME() AND TABLE_NAME = '{0}' AND CONSTRAINT_NAME = '{1}'", FormatSqlEscape(tableName), FormatSqlEscape(constraintName));
+ return Exists("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = '{0}' AND CONSTRAINT_NAME = '{1}'", FormatSqlEscape(tableName), FormatSqlEscape(constraintName));
}
public override bool IndexExists(string schemaName, string tableName, string indexName)
{
- return Exists("SELECT NULL FROM sysindexes WHERE name = '{0}'", FormatSqlEscape(indexName));
+ return Exists("SELECT NULL FROM INFORMATION_SCHEMA.INDEXES WHERE INDEX_NAME = '{0}'", FormatSqlEscape(indexName));
}
public override void Execute(string template, params object[] args)
@@ -76,10 +76,10 @@ public override void Execute(string template, params object[] args)
public override bool Exists(string template, params object[] args)
{
- if (connection.State != ConnectionState.Open)
- connection.Open();
+ if (Connection.State != ConnectionState.Open)
+ Connection.Open();
- using (var command = factory.CreateCommand(String.Format(template, args), connection, transaction))
+ using (var command = factory.CreateCommand(String.Format(template, args), Connection, transaction))
using (var reader = command.ExecuteReader())
{
return reader.Read();
@@ -93,10 +93,10 @@ public override DataSet ReadTableData(string schemaName, string tableName)
public override DataSet Read(string template, params object[] args)
{
- if (connection.State != ConnectionState.Open) connection.Open();
+ if (Connection.State != ConnectionState.Open) Connection.Open();
var ds = new DataSet();
- using (var command = factory.CreateCommand(String.Format(template, args), connection, transaction))
+ using (var command = factory.CreateCommand(String.Format(template, args), Connection, transaction))
{
var adapter = factory.CreateDataAdapter(command);
adapter.Fill(ds);
@@ -107,7 +107,7 @@ public override DataSet Read(string template, params object[] args)
public override void BeginTransaction()
{
Announcer.Say("Beginning Transaction");
- transaction = connection.BeginTransaction();
+ transaction = Connection.BeginTransaction();
}
public override void CommitTransaction()
@@ -120,9 +120,9 @@ public override void CommitTransaction()
transaction = null;
}
- if (connection.State != ConnectionState.Closed)
+ if (Connection.State != ConnectionState.Closed)
{
- connection.Close();
+ Connection.Close();
}
}
@@ -138,9 +138,9 @@ public override void RollbackTransaction()
transaction.Rollback();
- if (connection.State != ConnectionState.Closed)
+ if (Connection.State != ConnectionState.Closed)
{
- connection.Close();
+ Connection.Close();
}
}
@@ -151,13 +151,13 @@ protected override void Process(string sql)
if (Options.PreviewOnly || string.IsNullOrEmpty(sql))
return;
- if (connection.State != ConnectionState.Open)
- connection.Open();
+ if (Connection.State != ConnectionState.Open)
+ Connection.Open();
if (transaction == null)
BeginTransaction();
- using (var command = factory.CreateCommand(sql, connection, transaction))
+ using (var command = factory.CreateCommand(sql, Connection, transaction))
{
try
{
@@ -180,10 +180,10 @@ protected override void Process(string sql)
public override void Process(PerformDBOperationExpression expression)
{
- if (connection.State != ConnectionState.Open) connection.Open();
+ if (Connection.State != ConnectionState.Open) Connection.Open();
if (expression.Operation != null)
- expression.Operation(connection, transaction);
+ expression.Operation(Connection, transaction);
}
private static string FormatSqlEscape(string sql)
Oops, something went wrong.

0 comments on commit 618660c

Please sign in to comment.