public TableSpecification CreateTable(string tableName)
        {
            var gene = new CreateTableGene(_gene, tableName, Prerequisites);

            EvolutionHistoryBuilder.Append(gene);
            gene.AddToParent();
            return(new TableSpecification(gene, EvolutionHistoryBuilder));
        }
示例#2
0
        public CustomSqlSpecification Execute(string up, string down = null)
        {
            var gene = new CustomSqlGene(_databaseName, up, down, Prerequisites);

            EvolutionHistoryBuilder.Append(gene);
            gene.AddToParent();
            return(new CustomSqlSpecification(gene, EvolutionHistoryBuilder));
        }
示例#3
0
        public SchemaSpecification UseSchema(string schemaName)
        {
            var gene = new UseSchemaGene(_databaseName, schemaName, Prerequisites);

            EvolutionHistoryBuilder.Append(gene);
            gene.AddToParent();
            return(new SchemaSpecification(gene, EvolutionHistoryBuilder));
        }
示例#4
0
        public void DropColumn()
        {
            var childGene = new DropColumnGene(
                _gene,
                Prerequisites);

            EvolutionHistoryBuilder.Append(childGene);
            childGene.AddToParent();
        }
示例#5
0
        public IndexSpecification CreateIndex(params ColumnSpecification[] columns)
        {
            var childGene = new CreateIndexGene(
                _gene,
                columns.Select(c => c.Gene),
                Prerequisites);

            EvolutionHistoryBuilder.Append(childGene);
            childGene.AddToParent();
            return(new IndexSpecification(childGene, EvolutionHistoryBuilder));
        }
示例#6
0
        private ColumnSpecification CreateColumn(string columnName, string typeDescriptor, bool nullable)
        {
            var childGene = new CreateColumnGene(
                _gene,
                columnName,
                typeDescriptor,
                nullable,
                Prerequisites);

            EvolutionHistoryBuilder.Append(childGene);
            childGene.AddToParent();
            return(new ColumnSpecification(childGene, EvolutionHistoryBuilder));
        }
示例#7
0
        public ForeignKeySpecification CreateForeignKey(PrimaryKeySpecification referencing, bool cascadeDelete = false, bool cascadeUpdate = false)
        {
            var childGene = new CreateForeignKeyGene(
                _gene,
                referencing.Gene,
                cascadeDelete,
                cascadeUpdate,
                Prerequisites);

            EvolutionHistoryBuilder.Append(childGene);
            childGene.AddToParent();
            return(new ForeignKeySpecification(EvolutionHistoryBuilder));
        }
示例#8
0
        public void AddGene(Gene gene)
        {
            var genesAffected = new EvolutionHistoryBuilder();

            genesAffected.Append(gene);
            string[] rollbackSql = gene.GenerateRollbackSql(genesAffected, this);
            var      mementos    = genesAffected.EvolutionHistory.GetMementos().ToList();

            string[] deleteStatements = GenerateDeleteStatements(_databaseName, mementos);
            _sql   = _sql.InsertRange(0, deleteStatements);
            _sql   = _sql.InsertRange(0, rollbackSql);
            _ahead = _ahead.Subtract(genesAffected.EvolutionHistory);
        }
示例#9
0
        public bool AddGene(Gene gene)
        {
            if (_working.Contains(gene))
            {
                return(false);
            }

            foreach (var prerequisite in gene.AllPrerequisites
                     .Where(p => _difference.Contains(p)))
            {
                if (!AddGene(prerequisite))
                {
                    return(false);
                }
            }

            _working = _working.Push(gene);

            var genesAffected = new EvolutionHistoryBuilder();

            genesAffected.Append(gene);
            string[] result = gene.GenerateSql(genesAffected, this);
            _sql = _sql.AddRange(result);
            var mementos = genesAffected.EvolutionHistory.GetMementos().ToList();

            _sql = _sql.Add(GenerateInsertStatement(_databaseName, mementos));
            if (mementos.SelectMany(m => m.Prerequisites).SelectMany(p => p.Value).Any())
            {
                _sql = _sql.Add(GeneratePrerequisiteInsertStatements(_databaseName, mementos));
            }
            _difference = _difference.Subtract(genesAffected.EvolutionHistory);

            _working = _working.Pop();

            return(true);
        }