public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { if (_columnNames.Count == 0) { throw new InvalidCommandException("At least one column must be added to the AddForeignKeyTo command."); } string effectiveConstraintName = GetEffectiveConstraintName(); return provider.AddForeignKey(new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()), new TableName(_referencedTableName, ReferencedTableSchema ?? Parent.Schema ?? context.GetDefaultSchema()), _columnNames.Select(p => new ColumnReference(p.Key, p.Value)), effectiveConstraintName, CascadeOnDelete); }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { if (_columnNames.Count == 0) { throw new InvalidCommandException("At least one column must be added to the AddIndex command."); } string effectiveIndexName = GetEffectiveIndexName(); return provider.AddIndex(new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()), _columnNames, effectiveIndexName); }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { AlterTableCommand parentAlterTableCommand; AlterColumnCommand parentAlterColumnCommand; AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand; if ((parentAlterTableCommand = Parent as AlterTableCommand) != null) { return provider.RenameTable(new TableName(parentAlterTableCommand.TableName, parentAlterTableCommand.Schema ?? context.GetDefaultSchema()), _newName); } else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null) { return provider.RenameColumn(new TableName(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterColumnCommand.ColumnName, _newName); } else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null) { return provider.RenamePrimaryKey(new TableName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterPrimaryKeyCommand.ConstraintName, _newName); } else { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unknown parent command of a RenameCommand: {0}.", Parent.GetType())); } }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { string effectivePkConstraintName = GetEffectivePkConstraintName(); List<CreateColumnCommand> createColumnCommands = GetCreateColumnCommands().ToList(); if (createColumnCommands.Count == 0) { throw new InvalidCommandException("At least one column must be added to the CreateTable command."); } return provider.CreateTable( new TableName(TableName, Schema ?? context.GetDefaultSchema()), createColumnCommands.Select(c => new CreatedColumn( c.ColumnName, new DataType(c.Type, c.Size, c.Scale), c.IsNullable, c.IsPrimaryKey, GetEffectiveUniqueConstraintName(c), c.IsIdentity, c.DefaultValue, c.IsRowVersion)), effectivePkConstraintName); }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { string effectivePkConstraintName = GetEffectivePkConstraintName(); List <CreateColumnCommand> createColumnCommands = GetCreateColumnCommands().ToList(); if (createColumnCommands.Count == 0) { throw new InvalidCommandException("At least one column must be added to the CreateTable command."); } return(provider.CreateTable( new TableName(TableName, Schema ?? context.GetDefaultSchema()), createColumnCommands.Select(c => new CreatedColumn( c.ColumnName, new DataType(c.Type, c.Size, c.Scale), c.IsNullable, c.IsPrimaryKey, GetEffectiveUniqueConstraintName(c), c.IsIdentity, c.DefaultValue, c.IsRowVersion)), effectivePkConstraintName)); }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { AlterTableCommand parentAlterTableCommand; AlterSchemaCommand parentAlterSchemaCommand; AlterColumnCommand parentAlterColumnCommand; AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand; AlterIndexCommand parentAlterIndexCommand; AlterUniqueConstraintCommand parentAlterUniqueConstraintCommand; AlterForeignKeyCommand parentAlterForeignKeyCommand; if ((parentAlterTableCommand = Parent as AlterTableCommand) != null) { return provider.DropTable(new TableName(parentAlterTableCommand.TableName, parentAlterTableCommand.Schema ?? context.GetDefaultSchema()), Check == Check.IfExists); } else if ((parentAlterSchemaCommand = Parent as AlterSchemaCommand) != null) { return provider.DropSchema(parentAlterSchemaCommand.Schema); } else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null) { return provider.DropColumn(new TableName(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterColumnCommand.ColumnName); } else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null) { string effectiveConstraintName = DefaultObjectNameProvider.GetPrimaryKeyConstraintName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.ConstraintName); return provider.DropPrimaryKey(new TableName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), effectiveConstraintName); } else if ((parentAlterIndexCommand = Parent as AlterIndexCommand) != null) { return provider.DropIndex(new TableName(parentAlterIndexCommand.Parent.TableName, parentAlterIndexCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterIndexCommand.IndexName); } else if ((parentAlterUniqueConstraintCommand = Parent as AlterUniqueConstraintCommand) != null) { return provider.DropUniqueConstraint(new TableName(parentAlterUniqueConstraintCommand.Parent.TableName, parentAlterUniqueConstraintCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterUniqueConstraintCommand.ConstraintName); } else if ((parentAlterForeignKeyCommand = Parent as AlterForeignKeyCommand) != null) { return provider.DropForeignKey(new TableName(parentAlterForeignKeyCommand.Parent.TableName, parentAlterForeignKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterForeignKeyCommand.ConstraintName); } else { throw new InvalidOperationException("Unsupported parent command of a DropCommand."); } }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { if (_columnNames.Count == 0) { throw new InvalidCommandException("At least one column must be added to the AddIndex command."); } string effectiveIndexName = GetEffectiveIndexName(); return(provider.AddIndex(new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()), _columnNames, effectiveIndexName)); }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { AlterTableCommand parentAlterTableCommand; AlterColumnCommand parentAlterColumnCommand; AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand; if ((parentAlterTableCommand = Parent as AlterTableCommand) != null) { return(provider.RenameTable(new TableName(parentAlterTableCommand.TableName, parentAlterTableCommand.Schema ?? context.GetDefaultSchema()), _newName)); } else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null) { return(provider.RenameColumn(new TableName(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterColumnCommand.ColumnName, _newName)); } else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null) { return(provider.RenamePrimaryKey(new TableName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterPrimaryKeyCommand.ConstraintName, _newName)); } else { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unknown parent command of a RenameCommand: {0}.", Parent.GetType())); } }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { if (_columnNames.Count == 0) { throw new InvalidCommandException("At least one column must be added to the AddForeignKeyTo command."); } string effectiveConstraintName = GetEffectiveConstraintName(); return(provider.AddForeignKey(new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()), new TableName(_referencedTableName, ReferencedTableSchema ?? Parent.Schema ?? context.GetDefaultSchema()), _columnNames.Select(p => new ColumnReference(p.Key, p.Value)), effectiveConstraintName, CascadeOnDelete)); }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { var dataType = new DataType(_type, Size, Scale); var column = new Column(Parent.ColumnName, dataType, _isNullable, DefaultValue, false); return provider.AlterColumn(new TableName(Parent.Parent.TableName, Parent.Parent.Schema ?? context.GetDefaultSchema()), column); }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { AlterTableCommand parentAlterTableCommand; AlterSchemaCommand parentAlterSchemaCommand; AlterColumnCommand parentAlterColumnCommand; AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand; AlterIndexCommand parentAlterIndexCommand; AlterUniqueConstraintCommand parentAlterUniqueConstraintCommand; AlterForeignKeyCommand parentAlterForeignKeyCommand; if ((parentAlterTableCommand = Parent as AlterTableCommand) != null) { return(provider.DropTable(new TableName(parentAlterTableCommand.TableName, parentAlterTableCommand.Schema ?? context.GetDefaultSchema()), Check == Check.IfExists)); } else if ((parentAlterSchemaCommand = Parent as AlterSchemaCommand) != null) { return(provider.DropSchema(parentAlterSchemaCommand.Schema)); } else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null) { return(provider.DropColumn(new TableName(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterColumnCommand.ColumnName)); } else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null) { string effectiveConstraintName = DefaultObjectNameProvider.GetPrimaryKeyConstraintName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.ConstraintName); return(provider.DropPrimaryKey(new TableName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), effectiveConstraintName)); } else if ((parentAlterIndexCommand = Parent as AlterIndexCommand) != null) { return(provider.DropIndex(new TableName(parentAlterIndexCommand.Parent.TableName, parentAlterIndexCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterIndexCommand.IndexName)); } else if ((parentAlterUniqueConstraintCommand = Parent as AlterUniqueConstraintCommand) != null) { return(provider.DropUniqueConstraint(new TableName(parentAlterUniqueConstraintCommand.Parent.TableName, parentAlterUniqueConstraintCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterUniqueConstraintCommand.ConstraintName)); } else if ((parentAlterForeignKeyCommand = Parent as AlterForeignKeyCommand) != null) { return(provider.DropForeignKey(new TableName(parentAlterForeignKeyCommand.Parent.TableName, parentAlterForeignKeyCommand.Parent.Schema ?? context.GetDefaultSchema()), parentAlterForeignKeyCommand.ConstraintName)); } else { throw new InvalidOperationException("Unsupported parent command of a DropCommand."); } }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { if (IsNullable && DefaultValue != null) { throw new InvalidCommandException("Adding nullable columns with default values is not supported: some database platforms (like SQL Server) leave missing values NULL and some update missing values to the default value. Consider adding the column first as not-nullable, and then altering it to nullable."); } TableName tableName = new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()); var dataType = new DataType(Type, Size, Scale); var column = new Column(ColumnName, dataType, IsNullable, DefaultValue, IsRowVersion); IEnumerable <string> commands = provider.AddColumn(tableName, column); if (DropThereafter) { commands = commands.Concat(provider.DropDefault(tableName, new Column( column.Name, column.DataType, column.IsNullable, null, false))); } return(commands); }
public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context) { var dataType = new DataType(_type, Size, Scale); var column = new Column(Parent.ColumnName, dataType, _isNullable, DefaultValue, false); return(provider.AlterColumn(new TableName(Parent.Parent.TableName, Parent.Parent.Schema ?? context.GetDefaultSchema()), column)); }
public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context) { if (IsNullable && DefaultValue != null) { throw new InvalidCommandException("Adding nullable columns with default values is not supported: some database platforms (like SQL Server) leave missing values NULL and some update missing values to the default value. Consider adding the column first as not-nullable, and then altering it to nullable."); } TableName tableName = new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema()); var dataType = new DataType(Type, Size, Scale); var column = new Column(ColumnName, dataType, IsNullable, DefaultValue, IsRowVersion); IEnumerable<string> commands = provider.AddColumn(tableName, column); if (DropThereafter) { commands = commands.Concat(provider.DropDefault(tableName, new Column( column.Name, column.DataType, column.IsNullable, null, false))); } return commands; }