예제 #1
0
        private void SyncColumn(ITableContext table, IField field, bool hasRow)
        {
            //TODO 实现迁移策略
            var columnInfo = table.GetColumn(field.Name);

            //varchar(n) 类型的 n 变化了
            if (field.Type == FieldType.Chars && field.Size != columnInfo.Length)
            {
                //TODO:转换成可移植数据库类型
                var sqlType = string.Format("VARCHAR({0})", field.Size);
                table.AlterColumnType(this.context.DataContext, field.Name, sqlType);
            }


            if (!columnInfo.Nullable && !field.IsRequired) //"NOT NULL" to nullable
            {
                this.SetColumnNullable(table, field);
            }
            else if (columnInfo.Nullable && field.IsRequired) //Nullable to 'NOT NULL'
            {
                this.SetColumnNotNullable(table, field, hasRow);
            }
        }