public virtual void RemoveConstraint(string table, string name) { if (TableExists(table) && ConstraintExists(table, name)) { table = _dialect.TableNameNeedsQuote ? _dialect.Quote(table) : table; name = _dialect.ConstraintNameNeedsQuote ? _dialect.Quote(name) : name; ExecuteNonQuery(String.Format("ALTER TABLE {0} DROP CONSTRAINT {1}", table, name)); } }
public virtual string QuoteTableNameIfRequired(string name) { if (Dialect.TableNameNeedsQuote || Dialect.IsReservedWord(name)) { return(Dialect.Quote(name)); } return(name); }
public virtual void RemoveColumn(string table, string column) { if (!ColumnExists(table, column)) { throw new MigrationException(string.Format("The table '{0}' does not have a column named '{1}'", table, column)); } var existingColumn = GetColumnByName(table, column); ExecuteNonQuery(String.Format("ALTER TABLE {0} DROP COLUMN {1} ", table, Dialect.Quote(existingColumn.Name))); }
public virtual void RenameColumn(string tableName, string oldColumnName, string newColumnName) { if (ColumnExists(tableName, newColumnName)) { throw new MigrationException(String.Format("Table '{0}' has column named '{1}' already", tableName, newColumnName)); } if (!ColumnExists(tableName, oldColumnName)) { throw new MigrationException(string.Format("The table '{0}' does not have a column named '{1}'", tableName, oldColumnName)); } var column = GetColumnByName(tableName, oldColumnName); var quotedNewColumnName = QuoteColumnNameIfRequired(newColumnName); ExecuteNonQuery(String.Format("ALTER TABLE {0} RENAME COLUMN {1} TO {2}", tableName, Dialect.Quote(column.Name), quotedNewColumnName)); }