public SchemaIndexQuery(string schemaName, string tableName, string indexName, IMigrationContext context)
 {
     _schemaName = schemaName;
     _tableName = tableName;
     _indexName = indexName;
     _context = context;
 }
 /// <summary>
 /// Constricts a new instance of a <see cref="IfDatabaseExpressionRoot"/> that will only add expressions to the provided <see cref="context"/> if <see cref="databaseType"/> matches the migration processor
 /// </summary>
 /// <remarks>If the database type does not apply then a <seealso cref="NullIfDatabaseProcessor"/> will be used as a container to void any fluent expressions that would have been executed</remarks>
 /// <param name="context">The context to add expressions to if the database type applies</param>
 /// <param name="databaseType">The database type that the expressions relate to</param>
 public IfDatabaseExpressionRoot(IMigrationContext context, params string[] databaseType)
 {
     if (databaseType == null) throw new ArgumentNullException("databaseType");
     _origContext = context;
     _databaseType = databaseType;
     _context = DatabaseTypeApplies(context, databaseType) ? context : new MigrationContext(new MigrationConventions(), new NullIfDatabaseProcessor(), context.MigrationAssembly, context.ApplicationContext);
 }
 public static Migration GetMigrationInstance(
     this Assembly assembly,
     IMigrationContext migrationContext)
 {
     return (Migration) assembly.GetTypeInstance(DefaultMigrationName,
                                                 migrationContext);
 }
 public ForEachFederationExpressionBuilder(IMigrationContext context, ForEachFederationExpression expression)
 {
     _expression = expression;
      expression.Context = new MigrationContext (context.Conventions, context.QuerySchema,
                                             context.MigrationAssembly,
                                             context.ApplicationContext);
 }
 public SchemaColumnQuery(string schemaName, string tableName, string columnName, IMigrationContext context)
 {
     _schemaName = schemaName;
     _tableName = tableName;
     _columnName = columnName;
     _context = context;
 }
 public PageTypeAction(
     IPageType pageType,
     IMigrationContext context)
 {
     this.pageType = pageType;
     this.context = context;
 }
Example #7
0
 public virtual void GetUpExpressions(IMigrationContext context)
 {
     lock (_mutex)
     {
         _context = context;
         Up();
         _context = null;
     }
 }
Example #8
0
 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)
 {
     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);
 }
Example #10
0
 public IEnumerable<string> ToSql(IProvider provider, IMigrationContext context)
 {
     var runtimeContext = context as IRuntimeContext;
     if (runtimeContext != null) // the runtimeContext == null, when recording the changes to the RecordingProvider for validation
     {
         Log.Verbose(LogCategory.Sql, "Performing call-back");
         _action(runtimeContext);
     }
     yield break;
 }
		public virtual void GetDownExpressions(IMigrationContext context)
		{
			lock (_lock)
			{
				ApplicationContext = context.ApplicationContext;
				Database = new TransformationProvider(context);
				Down();
				Database = null;
			}
		}
Example #12
0
 public virtual void GetDownExpressions(IMigrationContext context)
 {
     lock (_mutex)
     {
         _context = context;
         ApplicationContext = context.ApplicationContext;
         Down();
         _context = null;
     }
 }
 /// <summary>
 /// Circumvents actual SQL task migration code and records its "execution" to the test migration
 /// context. It allows the actual execution of .NET code patches.
 /// </summary>
 /// <param name="context">the migration context</param>
 /// <param name="task">the task to migrate</param>
 public override void MigrateTask(IMigrationContext context, IMigrationTask task)
 {
     if (task is SqlScriptMigrationTask)
     {
         ((TestMigrationContext)context).RecordExecution(task.Name);
     }
     else
     {
         base.MigrateTask(context, task);
     }
 }
Example #14
0
 public virtual void GetUpExpressions(IMigrationContext context)
 {
     lock (_mutex)
     {
         _context = context;
         ApplicationContext = context.ApplicationContext;
         ConnectionString = context.Connection;
         Up();
         _context = null;
     }
 }
Example #15
0
 public override void Migrate(IMigrationContext context)
 {
     if (!ForceFail)
     {
         TestMigrationContext ctx = (TestMigrationContext)context;
         ctx.RecordExecution(Name);
     }
     else
     {
         throw new MigrationException("Something went wrong running '" + Name + "'");
     }
 }
Example #16
0
 protected Database GetDatabaseContainingMigrationChanges(MigrationDirection direction, IMigrationContext context)
 {
     var database = new Database(context);
     if (direction == MigrationDirection.Up)
     {
         _migration.Up(database);
     }
     else
     {
         Debug.Assert(direction == MigrationDirection.Down);
         var migration = _migration as IReversibleMigration;
         if (migration == null)
         {
             throw new InvalidOperationException("Cannot downgrade an irreversible migration."); // this should never happen
         }
         migration.Down(database);
     }
     return database;
 }
Example #17
0
 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.");
     }
 }
Example #18
0
        public static MigrationReport Create(Database database, string migrationName, IMigrationContext context)
        {
            // execute changes in 'database' against a RecordingProvider
            var recordingProvider = new RecordingProvider();
            var translator = new CommandsToSqlTranslator(recordingProvider);
            string error = string.Empty;
            try
            {
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
                translator.TranslateToSql(database, context).ToList(); // .ToList() is important to effectively trigger the iteration
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
            }
            catch (InvalidCommandException x)
            {
                error = x.Message;
            }

            // create MigrationReport
            return new MigrationReport(migrationName, error, recordingProvider);
        }
Example #19
0
 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;
 }
Example #20
0
 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);
 }
Example #21
0
 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 CreateColumnMigration(IMigrationContext context)
     : base(context)
 {
 }
Example #23
0
 public AddMainDomLock(IMigrationContext context)
     : base(context)
 {
 }
 public AlterColumnBuilder(IMigrationContext context, DatabaseProviders[] databaseProviders, AlterColumnExpression expression)
     : base(expression)
 {
     _context           = context;
     _databaseProviders = databaseProviders;
 }
 public CreateTableOfTDtoMigration(IMigrationContext context)
     : base(context)
 {
 }
 public void ApplyConventions(IMigrationContext context)
 {
     foreach (var expression in context.Expressions)
         expression.ApplyConventions(context.Conventions);
 }
Example #27
0
 public GoodMigration(IMigrationContext context)
     : base(context)
 {
 }
 public AlterDefaultConstraintExpression(IMigrationContext context)
     : base(context)
 { }
 public DeleteConstraintExpression(IMigrationContext context, ConstraintType type)
     : base(context)
 {
     Constraint = new ConstraintDefinition(type);
 }
 public TestPostMigration(IMigrationContext context) : base(context)
 {
 }
 public CreateForeignKeyExpression(IMigrationContext context, ForeignKeyDefinition fkDef)
     : base(context)
 {
     ForeignKey = fkDef;
 }
 public CreateForeignKeyExpression(IMigrationContext context)
     : base(context)
 {
     ForeignKey = new ForeignKeyDefinition();
 }
Example #33
0
 public FixRootKeyValue(IMigrationContext context, IContentService contentService, ILogger <FixRootKeyValue> logger) : base(context)
 {
     _contentService = contentService;
     _logger         = logger;
 }
Example #34
0
 public InsertBuilder(IMigrationContext context)
 {
     _context = context;
 }
 public SchemaSchemaQuery(IMigrationContext context, string schemaName)
 {
     _context    = context;
     _schemaName = schemaName;
 }
 public SchemaTableQuery(IMigrationContext context, string schemaName, string tableName)
 {
     _context = context;
     _schemaName = schemaName;
     _tableName = tableName;
 }
Example #37
0
 public BadMigration2(IMigrationContext context)
     : base(context)
 {
 }
Example #38
0
 public IMigrationReport Report(IMigrationContext context)
 {
     Database database = GetDatabaseContainingMigrationChanges(_metadata.Direction, context);
     return MigrationReport.Create(database, MigrationName);
 }
Example #39
0
 public Dummy(IMigrationContext context)
     : base(context)
 {
 }
Example #40
0
 public UpdateBuilder(IMigrationContext context)
 {
     _context = context;
 }
 public CreateKeysAndIndexesMigration(IMigrationContext context)
     : base(context)
 {
 }
Example #42
0
 public NopForeignKeyConvention(INopDataProvider dataProvider, IMigrationContext context)
 {
     _dataProvider = dataProvider;
     _context      = context;
 }
Example #43
0
 public DropMigrationsTable(IMigrationContext context)
     : base(context)
 {
 }
Example #44
0
 public DeleteKeysAndIndexesBuilder(IMigrationContext context, params DatabaseType[] supportedDatabaseTypes)
 {
     _context = context;
     _supportedDatabaseTypes = supportedDatabaseTypes;
 }
 public UpdateCmsPropertyGroupIdSeed(IMigrationContext context) : base(context)
 {
 }
Example #46
0
 public async Task Preprocess(IMigrationContext migrationContext, IBatchMigrationContext batchContext, IList <WorkItem> sourceWorkItems, IList <WorkItem> targetWorkItems)
 {
 }
 public ExternalLoginTableIndexesFixup(IMigrationContext context) : base(context)
 {
 }
Example #48
0
        public string GetUpdatedTagsFieldWithPostMove(IMigrationContext migrationContext, string tagFieldValue)
        {
            string postMoveTag = migrationContext.Config.SourcePostMoveTag;

            return($"{tagFieldValue}; {postMoveTag}");
        }
Example #49
0
 public UpdateRelationTypesToHandleDependencies(IMigrationContext context)
     : base(context)
 {
 }
Example #50
0
 public AddColumnMigration(IMigrationContext context)
     : base(context)
 {
 }
 public virtual void GetUpExpressions(IMigrationContext context)
 {
     lock (_mutex)
     {
         _context = context;
         ApplicationContext = context.ApplicationContext;
         Up();
         _context.VersionMetadata = VersionMetadata;
         _context = null;
     }
 }
Example #52
0
 public UpdateDataExpressionBuilder(UpdateDataExpression expression, IMigrationContext context)
 {
     _context    = context;
     _expression = expression;
 }
 public SchemaSchemaQuery(IMigrationContext context, string schemaName)
 {
     _context = context;
     _schemaName = schemaName;
 }
Example #54
0
 public UpdateUniqueIndexOnPropertyData(IMigrationContext context)
     : base(context)
 {
 }
 public AlterExpressionRoot(IMigrationContext context)
 {
     _context = context;
 }
Example #56
0
 public ExternalLoginTableUserData(IMigrationContext context)
     : base(context)
 {
 }
 public DeleteExpressionRoot(IMigrationContext context)
 {
     _context = context;
 }
Example #58
0
 public AddTypedLabels(IMigrationContext context)
     : base(context)
 {
 }
 public void GetUpExpressions(IMigrationContext context)
 {
     throw new NotImplementedException();
 }
 public CreateTableExpressionBuilder(CreateTableExpression expression, IMigrationContext context)
     : base(expression)
 {
     _context = context;
 }