如何应用 SubSonic 3“SimpleRepository”生产系统的改变

发布于 2024-08-08 10:45:12 字数 334 浏览 7 评论 0原文

我一直在使用 SubSonic 的 SimpleRepository,它非常棒。但是,我想知道是否有一种简单的方法可以将待处理的更改应用到生产系统。

之前,我通过批处理文件使用了 SubSonic 2 的“Migrations”;当我准备好转移到生产环境时,我只需针对生产服务器运行所有待处理的迁移,然后就可以开始了。又好又简单。

SimpleRepostitory 更多地采用“在需要时运行它们”的迁移方法,但我不想在生产中保留该选项。

有没有办法获取待处理更改的列表?我知道我可以使用 SqlDiff 之类的东西,但由于我之前有一个有效的解决方案,失去它会很遗憾......

有人吗?

I've been playing with SubSonic's SimpleRepository, and it's awesome. However, I would like to know if there's an easy way to apply pending changes to a production system.

Previously, I used SubSonic 2's "Migrations" via a batch file; when I was ready to move to production, I'd just run all the pending migrations against the production server, and I'd be ready to go. Nice and simple.

The SimpleRepostitory takes more of a "run them when you need them" approach to migrations, but I don't want to leave that option on when in production.

Is there a way to get a list of pending changes? I know I could use something like SqlDiff, but since I had a working solution before, it'd be a shame to lose it...

Anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑凤梨 2024-08-15 10:45:12

如果您使用 reflector 您可以轻松了解 SimpleRepository 如何管理迁移。

我实际上并没有尝试过这段代码,但您可以简单地以与 SimpleRepository 相同的方式进行迁移:

  • 创建一个新的迁移器,将您的程序集传递给构造函数。
  • 如果要使用事务,请创建 BatchQuery
  • 迭代要迁移的类型,
  • 如果要使用 BatchQuery,则通过调用迁移器对象上的 MigrateFromModel 方法获取 SQL 字符串,创建一个新的 QueryCommand 并将该对象传递给BatchQuery 的 QueueForTransaction 方法。

这是 Reflector 中的方法:(遵循 MigrateFromModel 如何确定需要更改的内容的逻辑留给读者作为练习:))

private void Migrate<T>() where T: class, new()
{
    Type item = typeof(T);
    if (!this.migrated.Contains(item))
    {
        BatchQuery query = new BatchQuery(this._provider);
        Migrator migrator = new Migrator(Assembly.GetExecutingAssembly());
        foreach (string str in migrator.MigrateFromModel(item, this._provider))
        {
            query.QueueForTransaction(new QueryCommand(str, this._provider));
        }
        query.ExecuteTransaction();
        this.migrated.Add(item);
    }
}

If you use reflector you can easily find how SimpleRepository manages Migrations.

I haven't actually tried this code, but you could simply do the Migrations the same way the SimpleRepository does:

  • Create a new Migrator, passing in your Assembly to the constructor.
  • Create a BatchQuery if you want to use transactions
  • Iterate through the types you want to migrate, getting the SQL string by calling the MigrateFromModel method on the migrator object
  • if you want to use the BatchQuery, create a new QueryCommand and pass in the object to the BatchQuery's QueueForTransaction method.

Here is the method in Reflector: (following the logic on how MigrateFromModel figures out what needs to change is left as an exercise for the reader :) )

private void Migrate<T>() where T: class, new()
{
    Type item = typeof(T);
    if (!this.migrated.Contains(item))
    {
        BatchQuery query = new BatchQuery(this._provider);
        Migrator migrator = new Migrator(Assembly.GetExecutingAssembly());
        foreach (string str in migrator.MigrateFromModel(item, this._provider))
        {
            query.QueueForTransaction(new QueryCommand(str, this._provider));
        }
        query.ExecuteTransaction();
        this.migrated.Add(item);
    }
}
只是在用心讲痛 2024-08-15 10:45:12

您有机会将其打包并分享回项目吗? :)

我一直在使用更“穷人”的迁移解决方案,但它没有回滚或其他功能。

Any chance you can package this up and share it back to the project? :)

I've been using a much more "poor man's" migration solution but it doesn't have rollback or other features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文