public void MigrationGenerateCreateTablesSql() { Migration m = new MigrationTest001(); string sql = m.BuildSqlStatement(Migration.MigrationDirection.Up); Assert.AreEqual( "CREATE TABLE [Distribution] (\r\n [Id] int NOT NULL PRIMARY KEY IDENTITY(1,1),\r\n [Name] nvarchar(20) NULL,\r\n [Capacity] int NULL \r\n);\r\nCREATE TABLE [ShipStatus] (\r\n [ShipStatusId] int NOT NULL PRIMARY KEY IDENTITY(1,1),\r\n [Status] nvarchar(50) NULL,\r\n [Code] nvarchar(4) NULL,\r\n [CreatedOn] datetime NOT NULL CONSTRAINT DF_ShipStatus_CreatedOn DEFAULT (getdate()),\r\n [ModifiedOn] datetime NOT NULL CONSTRAINT DF_ShipStatus_ModifiedOn DEFAULT (getdate()),\r\n [CreatedBy] nvarchar(64) NULL,\r\n [ModifiedBy] nvarchar(64) NULL \r\n);\r\n", sql); }
public void MigrationGenerateDropTablesSql() { //get a table in there to drop Migration m = new MigrationTest001(); m.Migrate("Northwind", Migration.MigrationDirection.Up); DataService.ClearSchemaCache("Northwind"); string sql = m.BuildSqlStatement(Migration.MigrationDirection.Down); Assert.AreEqual("DROP TABLE [dbo].[Distribution];\r\nDROP TABLE [dbo].[ShipStatus];\r\n", sql); }
public void MigrationGenerateDropTablesSql() { // Attempted to read or write protected memory. This is often an indication that other memory is corrupt. //get a table in there to drop // SQLite error near "AUTOINCREMENT": syntax error Migration m = new MigrationTest001(); m.Migrate("Northwind", Migration.MigrationDirection.Up); // The database file is locked DataService.ClearSchemaCache("Northwind"); string sql = m.BuildSqlStatement(Migration.MigrationDirection.Down); Assert.AreEqual("DROP TABLE `main`.`Distribution`;\r\nDROP TABLE `main`.`ShipStatus`;\r\n", sql); }
public void MigrationMySql() { Migration m = new MigrationTest001(); //test the up m.Migrate("Southwind", Migration.MigrationDirection.Up); Assert.IsTrue(DataService.TableExists("Southwind", "Distribution")); Assert.IsTrue(DataService.TableExists("Southwind", "ShipStatus")); //needed to clear schema cache for the DropTable call //in the Down() method of the migration. Not needed //for the above TableExists because that always //goes to the DB to check DataService.ClearSchemaCache("Southwind"); //test the down m.Migrate("Southwind", Migration.MigrationDirection.Down); Assert.IsFalse(DataService.TableExists("Southwind", "Distribution")); Assert.IsFalse(DataService.TableExists("Southwind", "ShipStatus")); }
public void MigrationGenerateCreateTablesSql() { Migration m = new MigrationTest001(); string sql = m.BuildSqlStatement(Migration.MigrationDirection.Up); string expected = "CREATE TABLE `Distribution` (\r\n" + " `Id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\r\n" + " `Name` nvarchar(20) NULL,\r\n" + " `Capacity` INTEGER NULL \r\n" + ");\r\n" + "CREATE TABLE `ShipStatus` (\r\n" + " `ShipStatusId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\r\n" + " `Status` nvarchar(50) NULL,\r\n" + " `Code` nvarchar(4) NULL,\r\n" + " `CreatedOn` datetime ,\r\n" + " `ModifiedOn` datetime ,\r\n" + " `CreatedBy` nvarchar(64) NULL,\r\n" + " `ModifiedBy` nvarchar(64) NULL \r\n" + ");\r\n"; Assert.AreEqual(expected, sql); }
public void MigrationUpDown() { Migration m = new MigrationTest001(); //test the up m.Migrate("Northwind", Migration.MigrationDirection.Up); Assert.IsTrue(DataService.TableExists("Northwind", "Distribution")); Assert.IsTrue(DataService.TableExists("Northwind", "ShipStatus")); //needed to clear schema cache for the DropTable call //in the Down() method of the migration. Not needed //for the above TableExists because that always //goes to the DB to check DataService.ClearSchemaCache("Northwind"); //test the down m.Migrate("Northwind", Migration.MigrationDirection.Down); Assert.IsFalse(DataService.TableExists("Northwind", "Distribution")); Assert.IsFalse(DataService.TableExists("Northwind", "ShipStatus")); }