private string GenerateSqlStatementConcrete(AddForeignKeyOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.DependentTable); ddlBuilder.AppendSql(" ADD CONSTRAINT "); ddlBuilder.AppendIdentifier(migrationOperation.Name.Replace("dbo.", "")); ddlBuilder.AppendSql(" FOREIGN KEY ("); ddlBuilder.AppendIdentifierList(migrationOperation.DependentColumns); ddlBuilder.AppendSql(")"); ddlBuilder.AppendSql(" REFERENCES "); ddlBuilder.AppendIdentifier(migrationOperation.PrincipalTable); ddlBuilder.AppendSql(" ("); ddlBuilder.AppendIdentifierList(migrationOperation.PrincipalColumns); ddlBuilder.AppendSql(")"); if (migrationOperation.CascadeDelete) { ddlBuilder.AppendSql(" ON DELETE CASCADE "); } return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(HistoryOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); foreach (DbModificationCommandTree commandTree in migrationOperation.CommandTrees) { List <DbParameter> parameters; // Take care because here we have several queries so we can't use parameters... switch (commandTree.CommandTreeKind) { case DbCommandTreeKind.Insert: ddlBuilder.AppendSql(DB2DmlBuilder.GenerateInsertSql((DbInsertCommandTree)commandTree, out parameters, true)); break; case DbCommandTreeKind.Delete: ddlBuilder.AppendSql(DB2DmlBuilder.GenerateDeleteSql((DbDeleteCommandTree)commandTree, out parameters, true)); break; case DbCommandTreeKind.Update: ddlBuilder.AppendSql(DB2DmlBuilder.GenerateUpdateSql((DbUpdateCommandTree)commandTree, out parameters, true)); break; case DbCommandTreeKind.Function: case DbCommandTreeKind.Query: default: throw new InvalidOperationException(string.Format("Command tree of type {0} not supported in migration of history operations", commandTree.CommandTreeKind)); } ddlBuilder.AppendSql(BATCHTERMINATOR); } return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(DropTableOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("DROP TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Name); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(DropPrimaryKeyOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" DROP PRIMARY KEY "); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(DropForeignKeyOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.PrincipalTable); ddlBuilder.AppendSql(" DROP FOREIGN KEY "); ddlBuilder.AppendIdentifier(migrationOperation.Name); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(RenameIndexOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("RENAME INDEX "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" TO "); ddlBuilder.AppendIdentifier(migrationOperation.NewName); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(AddPrimaryKeyOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ADD CONSTRAINT "); ddlBuilder.AppendIdentifier(migrationOperation.Name.Replace("dbo.", "")); ddlBuilder.AppendSql(" PRIMARY KEY ("); ddlBuilder.AppendIdentifierList(migrationOperation.Columns); ddlBuilder.AppendSql(")"); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(RenameColumnOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" RENAME COLUMN "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" TO "); ddlBuilder.AppendIdentifier(migrationOperation.NewName); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(CreateIndexOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("CREATE "); if (migrationOperation.IsUnique) { ddlBuilder.AppendSql("UNIQUE "); } ddlBuilder.AppendSql("INDEX "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" ON "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ("); ddlBuilder.AppendIdentifierList(migrationOperation.Columns); ddlBuilder.AppendSql(")"); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(AlterColumnOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("ALTER TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Table); ddlBuilder.AppendSql(" ALTER COLUMN "); ColumnModel column = migrationOperation.Column; ddlBuilder.AppendIdentifier(column.Name); ddlBuilder.AppendSql(" "); TypeUsage storeType = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeType, column.IsNullable ?? true, column.IsIdentity); ddlBuilder.AppendNewLine(); return(ddlBuilder.GetCommandText()); }
private string GenerateSqlStatementConcrete(CreateTableOperation migrationOperation) { DB2DdlBuilder ddlBuilder = new DB2DdlBuilder(); ddlBuilder.AppendSql("CREATE TABLE "); ddlBuilder.AppendIdentifier(migrationOperation.Name); ddlBuilder.AppendSql(" ("); ddlBuilder.AppendNewLine(); bool first = true; foreach (ColumnModel column in migrationOperation.Columns) { if (first) { first = false; } else { ddlBuilder.AppendSql(","); } ddlBuilder.AppendSql(" "); ddlBuilder.AppendIdentifier(column.Name); ddlBuilder.AppendSql(" "); TypeUsage storeTypeUsage = ProviderManifest.GetStoreType(column.TypeUsage); ddlBuilder.AppendType(storeTypeUsage, column.IsNullable ?? true, column.IsIdentity); ddlBuilder.AppendNewLine(); } ddlBuilder.AppendSql(")"); if (migrationOperation.PrimaryKey != null) { ddlBuilder.AppendSql(BATCHTERMINATOR); ddlBuilder.AppendSql(GenerateSqlStatementConcrete(migrationOperation.PrimaryKey)); } return(ddlBuilder.GetCommandText()); }