我如何从通过 clickonce 部署的 WinForms 应用程序中调用/使用 Subsonic(使用 Sqlite DB)
背景 - 我需要一个框架/方法来管理通过 clickonce 部署在用户 PC 上部署的 .NET Winforms 应用程序的数据库更新。该应用程序使用 sqlite 数据库。
Q1. Subsonic 使用什么机制在本地 PC 上运行此类迁移?例如,它会是 MSBuild
Q2吗?如果它确实需要像我的应用程序如何稳健地启动 MsBuild 这样的工具?即如何确定它安装在哪个路径,如果没有安装怎么办,我是否应该将 MSBuild.exe 包含在 clickonce 包中,以便我自己确定它在那里?
Q3。关于如何在此特定用例中使用 Subsonic 有其他建议吗?
Q4。关于 MigratorDotNet 是否更适合有什么评论吗? (如果有人两者都有过经验)
Q5。我可以使用 subsonic 的裸迁移框架并仅使用一组 SQL 文件来进行升级/降级吗?即仅使用框架来检查数据库版本以及要运行哪些脚本等?
Background - I need a framework/approach to managed database updates for a .NET Winforms app being deployed on users PC's via clickonce deploy. The app uses a sqlite database.
Q1. What mechanism does Subsonic use to run such migrations on the local PC? e.g. would it be MSBuild
Q2. If it does need a tool like how can my application robustly kick off MsBuild? i.e. how can it be sure what path it is installed, what if it is not installed, should I be including the MSBuild.exe in the clickonce package so that I know it is there for sure myself?
Q3. Any other suggestions on how to use Subsonic in this specific use case?
Q4. Any comments on whether MigratorDotNet would be a better fit? (if someone has had experience with both)
Q5. Could I use subsonic's bare migration framework and just have a set of SQL files to do the upgrade/downgrade? i.e. just use the framework to check database version and which scripts to run etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,这篇文章有点旧,但也许我的答案仍然有用。
Q1:SubSonic 迁移是由子命令 (sonic.exe) 在运行时编译和执行的代码文件,这意味着代码文件必须位于磁盘上,并且必须遵循命名约定 001_migration_name.cs,以便子命令知道执行顺序。
Q2:您不需要 msbuild 来进行迁移。您唯一需要的是 sonic.exe 及其依赖项。
Q3:可以(而且不是很难)创建自己的逻辑来在运行时执行项目中的迁移,而无需使用子命令。
我基本上找到了从 Migration 派生的每个类,并且(因为类不能以数字开头)我的约定是类名的最后 3 位数字是迁移编号(例如 001_migration_name.cs 我的类被定义为 Migration001 :迁移)
在您的程序中,您可以通过 MigrationHelper.CurrentVersion 确定当前版本,然后执行从当前版本到最大版本(如果您想升级)或其他版本的每个迁移。以下是如何使用它。
Q4:我没有使用 MigratorDotNet 的经验,但如果您的应用程序使用亚音速,那么亚音速迁移是一个不错的选择,因为您不需要部署任何额外的库。
Q5:您可以为此使用亚音速迁移。只需执行:
在 Up() 或 Down() 方法中即可。但是使用预定义方法的优点是(除了它们跨多个 dbms 工作的事实之外,如果您只使用 sqlite,这可能不那么重要)是您有一些飞行前检查(例如,如果您定义了一个迁移将会失败)在执行实际的sql之前两次字段)
Well, the post is a little old but maybe my answers are still of use.
Q1: SubSonic Migrations are code files that are complied and executed at runtime by subcommander (sonic.exe) which means the code files have to be on disk and must follow the naming convention 001_migration_name.cs for subcommander to know the execution order.
Q2: You don't need msbuild for migrations. The only thing you need is the sonic.exe and it's dependencies.
Q3: It is possible (and not very hard) to create your own logik to execute the migrations in your project at runtime without using subcommander.
I basically find every class that is derived from Migration and (since a class cannot start with a number) my convention is that the last 3 digits from the class name are the migration number (like the 001_migration_name.cs my classes are defined as Migration001 : Migration)
In your programm you can determine the current version by MigrationHelper.CurrentVersion and then execute every single migration from current to max (if you wanne go up) or some other number. Here is how you use it.
Q4: I don't have experience with MigratorDotNet but if your app uses subsonic than the subsonic migrations are a good choise since you don't need to deploy any additional libs.
Q5: You can use subsonic migrations for that. Just do:
in the Up() or Down() method. But the advantage of using the predefined methods are (besides the fact that they work across multiple dbms' which is propable not so importent if you only use sqlite) is that you have some pre flight checks (e.g. a migration will fail if you define a field twice before the actual sql is executed)