简体   繁体   English

安装程序更新中的数据库更改管理

[英]Database changes management in installer updates

How can I run a series of database scripts depending on some condition? 如何根据某些条件运行一系列数据库脚本?

Basically I want to check build installed on user's machine and then want to run all the scripts till the build in the installer. 基本上,我想检查安装在用户计算机上的构建,然后要运行所有脚本,直到安装程序中的构建为止。

Say user has build number 4.10 installed and if he goes to install build 4.15 then I want to run SQL scripts of builds 4.111 to 4.15. 假设用户已安装了内部版本号4.10,并且如果他要安装内部版本4.15,那么我想运行内部版本4.111至4.15的SQL脚本。

I'm trying this but it says condition element can't be nested in SQL script element. 我正在尝试这样做,但是它说条件元素不能嵌套在SQL脚本元素中。

<sql:SqlScript Id="ScriptV11" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV11"  ContinueOnError="no" Sequence="11">
             <Condition>INSTALLED_BUILD < 4.11 </Condition>
 </sql:SqlScript>

Any help would be highly appreciated. 任何帮助将不胜感激。

Note: INSTALLED_BUILD property is set using registry search. 注意:INSTALLED_BUILD属性是使用注册表搜索设置的。

Conditions can be applied to Components, but a gotcha using multiple components is you can't rely on the components being installed in any particular order. 条件可以应用于组件,但是使用多个组件的陷阱是您不能依赖以任何特定顺序安装的组件。 However you can control the sequencing of scripts. 但是,您可以控制脚本的顺序。 See this related question: Can I ensure components installation order? 请参阅以下相关问题:是否可以确保组件安装顺序? .

With this in mind, and you really want to do the upgrade in the installer, you could try something like: 考虑到这一点,并且您确实要在安装程序中进行升级,可以尝试执行以下操作:

<Component Id="UpgradeFromV410" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.10)</Condition>
    <sql:SqlScript Id="ScriptV10V11" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV11" ContinueOnError="no" Sequence="11"/>
    <sql:SqlScript Id="ScriptV10V12" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV12" ContinueOnError="no" Sequence="12"/>
    <sql:SqlScript Id="ScriptV10V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV10V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV10V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV411" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.11)</Condition>
    <sql:SqlScript Id="ScriptV11V12" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV12" ContinueOnError="no" Sequence="12"/>
    <sql:SqlScript Id="ScriptV11V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV11V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV11V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV412" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.12)</Condition>
    <sql:SqlScript Id="ScriptV12V13" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV13" ContinueOnError="no" Sequence="13"/>
    <sql:SqlScript Id="ScriptV12V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV12V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV413" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.13)</Condition>
    <sql:SqlScript Id="ScriptV13V14" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV14" ContinueOnError="no" Sequence="14"/>
    <sql:SqlScript Id="ScriptV13V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

<Component Id="UpgradeFromV414" Guid="--Your GUID--">
    <Condition>INSTALLED AND (INSTALLED_BUILD=4.14)</Condition>
    <sql:SqlScript Id="ScriptV13V15" ExecuteOnInstall="yes" ExecuteOnUninstall="no" BinaryKey="FileV15" ContinueOnError="no" Sequence="15"/>
</Component>

As a solution this is just about OK, if your releases are relatively few and far between. 作为解决方案,如果您的发行版相对较少且相差很远,那就可以了。 If you have a frequent release schedule, this solution would quickly become un-maintainable. 如果发布计划很频繁,则此解决方案将很快变得难以维护。

@Stein's comment about running the upgrade scripts at start would offer you much more control and be easier to maintain in the long term. @Stein关于在开始时运行升级脚本的评论将为您提供更多控制权,并且从长远来看更易于维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM