public virtual IReadOnlyList <MigrationOperation> CreateSchema([NotNull] IModel model) { Check.NotNull(model, "model"); _operations = new MigrationOperationCollection(); _operations.AddRange(GetSequences(model) .Select(s => OperationFactory.CreateSequenceOperation(s))); _operations.AddRange(model.EntityTypes .Select(t => OperationFactory.CreateTableOperation(t))); // TODO: GitHub#1107 _operations.AddRange(_operations.Get <CreateTableOperation>() .SelectMany(o => o.ForeignKeys)); _operations.AddRange(_operations.Get <CreateTableOperation>() .SelectMany(o => o.Indexes)); return(OperationProcessor.Process(_operations, new Model(), model)); }
private void HandleTransitiveRenames() { const string temporaryNamePrefix = "__mig_tmp__"; var temporaryNameIndex = 0; _operations.Set(HandleTransitiveRenames( _operations.Get <RenameSequenceOperation>(), op => null, op => op.SequenceName, op => new SchemaQualifiedName(op.NewSequenceName, op.SequenceName.Schema), op => new SchemaQualifiedName(temporaryNamePrefix + temporaryNameIndex++, op.SequenceName.Schema), (parentName, name, newName) => new RenameSequenceOperation(name, SchemaQualifiedName.Parse(newName).Name))); _operations.Set(HandleTransitiveRenames( _operations.Get <RenameTableOperation>(), op => null, op => op.TableName, op => new SchemaQualifiedName(op.NewTableName, op.TableName.Schema), op => new SchemaQualifiedName(temporaryNamePrefix + temporaryNameIndex++, op.TableName.Schema), (parentName, name, newName) => new RenameTableOperation(name, SchemaQualifiedName.Parse(newName).Name))); _operations.Set(HandleTransitiveRenames( _operations.Get <RenameColumnOperation>(), op => op.TableName, op => op.ColumnName, op => op.NewColumnName, op => temporaryNamePrefix + temporaryNameIndex++, (parentName, name, newName) => new RenameColumnOperation(parentName, name, newName))); _operations.Set(HandleTransitiveRenames( _operations.Get <RenameIndexOperation>(), op => op.TableName, op => op.IndexName, op => op.NewIndexName, op => temporaryNamePrefix + temporaryNameIndex++, (parentName, name, newName) => new RenameIndexOperation(parentName, name, newName))); }