예제 #1
0
        public static Migration Load(MigrationMemento memento, IImmutableDictionary <BigInteger, Migration> migrationsByHashCode)
        {
            switch (memento.Type)
            {
            case nameof(UseSchemaMigration):
                return(UseSchemaMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreateTableMigration):
                return(CreateTableMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreateColumnMigration):
                return(CreateColumnMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreatePrimaryKeyMigration):
                return(CreatePrimaryKeyMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreateUniqueIndexMigration):
                return(CreateUniqueIndexMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreateIndexMigration):
                return(CreateIndexMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CreateForeignKeyMigration):
                return(CreateForeignKeyMigration.FromMemento(memento, migrationsByHashCode));

            case nameof(CustomSqlMigration):
                return(CustomSqlMigration.FromMemento(memento, migrationsByHashCode));

            default:
                throw new ArgumentException($"Unknown type {memento.Type}");
            }
        }
        public dynamic CreateColumnGenerator(CreateColumnMigration createColumnMigration)
        {
            var column_migration_expr = new CreateColumnExpression
                                            {
                                                Column = build_column_definition(createColumnMigration)
                                            };

            return column_migration_expr;
        }
        public void CreateColumn()
        {
            var context   = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of <ILogger>());
            var migration = new CreateColumnMigration(new SqlCeSyntaxProvider(), Mock.Of <ILogger>());

            migration.GetUpExpressions(context);

            Assert.That(context.Expressions.Count, Is.EqualTo(1));
            Assert.That(context.Expressions.Single().ToString(), Is.EqualTo("ALTER TABLE [bar] ADD [foo] UniqueIdentifier NOT NULL"));
        }
예제 #4
0
        private ColumnSpecification CreateColumn(string columnName, string typeDescriptor, bool nullable)
        {
            var childMigration = new CreateColumnMigration(
                _migration,
                columnName,
                typeDescriptor,
                nullable,
                Prerequisites);

            MigrationHistoryBuilder.Append(childMigration);
            childMigration.AddToParent();
            return(new ColumnSpecification(childMigration, MigrationHistoryBuilder));
        }
        public void CreateColumn()
        {
            var database  = new TestDatabase();
            var context   = new MigrationContext(database, _logger);
            var migration = new CreateColumnMigration(context);

            migration.Migrate();

            foreach (var op in database.Operations)
            {
                Console.WriteLine("{0}\r\n\t{1}", op.Text, op.Sql);
            }

            Assert.That(database.Operations.Count, Is.EqualTo(1));
            Assert.That(database.Operations[0].Sql, Is.EqualTo("ALTER TABLE [bar] ADD [foo] UniqueIdentifier NOT NULL"));
        }
        ColumnDefinition build_column_definition(CreateColumnMigration columnMigration)
        {
            var column = columnMigration.Column;
            return new ColumnDefinition
                       {
                           TableName = column.TableName,
                           Name = column.ColumnName,
                           DefaultValue = column.DefaultValue,
                           IsForeignKey = column.IsForiegnKey,
                           IsIdentity = column.IsIdentity,
                           IsNullable = column.IsNullable,
                           IsPrimaryKey = column.IsPrimaryKey,
                           Precision = column.Precision,
                           PrimaryKeyName = column.PrimaryKeyName,
                           Size = column.Size,
                           Type = column.DatabaseType

                       };
        }
예제 #7
0
 internal ColumnSpecification(CreateColumnMigration migration, MigrationHistoryBuilder migrationHistoryBuilder) :
     base(migrationHistoryBuilder)
 {
     _migration = migration;
 }