如何删除 VSTS DacpacTask 中的列?
How can I delete a column in a VSTS DacpacTask?
我在 VSTS 中有一个构建步骤,它生成一个 .dacpac
文件,我将其传递给发布定义,然后使用 Execute Azure SQL:DacpacTask 更新数据库。当我尝试删除列时,这是 DacpacTask 的输出:
2016-10-26T18:12:01.3300540Z ##[section]Starting: Execute Azure SQL : DacpacTask
2016-10-26T18:12:01.3674946Z ==============================================================================
2016-10-26T18:12:01.3674946Z Task : Azure SQL Database Deployment
2016-10-26T18:12:01.3674946Z Description : Deploy Azure SQL DB using DACPAC or run scripts using SQLCMD
2016-10-26T18:12:01.3674946Z Version : 1.1.2
2016-10-26T18:12:01.3674946Z Author : Microsoft Corporation
2016-10-26T18:12:01.3674946Z Help : [More Information](https://aka.ms/sqlazuredeployreadme)
2016-10-26T18:12:01.3674946Z ==============================================================================
2016-10-26T18:12:04.8304591Z packageFile= C:\a\r1\a\MyProject\Database\Database.dacpac
2016-10-26T18:12:07.4389560Z Publishing to database 'MyDB' on server 'mydatabase.database.windows.net'.
2016-10-26T18:12:08.3318189Z Initializing deployment (Start)
2016-10-26T18:12:25.4560124Z *** The column [dbo].[Foo].[Bar] is being dropped, data loss could occur.
2016-10-26T18:12:26.2098293Z Initializing deployment (Complete)
2016-10-26T18:12:26.2098293Z Analyzing deployment plan (Start)
2016-10-26T18:12:26.2098293Z Analyzing deployment plan (Complete)
2016-10-26T18:12:26.2098293Z Updating database (Start)
2016-10-26T18:12:29.5605253Z An error occurred while the batch was being executed.
2016-10-26T18:12:29.5675257Z Updating database (Failed)
2016-10-26T18:12:30.4919483Z
2016-10-26T18:12:30.6439495Z ##[error]
SerializedRemoteException :
SerializedRemoteInvocationInfo :
ErrorRecord : *** Could not deploy package.
StackTrace : at System.Management.Automation.Interpreter.ThrowInstruction.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Int
erpretedFrame frame)
WasThrownFromThrowStatement : True
Message : *** Could not deploy package.
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException :
TargetSite : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
System.Exception)
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
2016-10-26T18:12:30.6629481Z ##[section]Finishing: Execute Azure SQL : DacpacTask
我在那个构建中包含了一些其他的数据库更改,但是当我恢复删除列的提交时,发布成功了。
我还验证了即使 Bar
列中只有 NULL
也会出现同样的问题。
(显然我可以使用 SSMS 手动删除该列,但拥有 CI/CD 系统的目的是自动执行所有操作,因此我不必这样做。)
如何使用 VSTS DacpacTask 删除列?
您需要在执行 Azure SQL 的附加 SqlPackage.exe 参数中将 BlockOnPossibleDataLoss 参数指定为 false:DacpacTask 构建步骤。
我在 VSTS 中有一个构建步骤,它生成一个 .dacpac
文件,我将其传递给发布定义,然后使用 Execute Azure SQL:DacpacTask 更新数据库。当我尝试删除列时,这是 DacpacTask 的输出:
2016-10-26T18:12:01.3300540Z ##[section]Starting: Execute Azure SQL : DacpacTask
2016-10-26T18:12:01.3674946Z ==============================================================================
2016-10-26T18:12:01.3674946Z Task : Azure SQL Database Deployment
2016-10-26T18:12:01.3674946Z Description : Deploy Azure SQL DB using DACPAC or run scripts using SQLCMD
2016-10-26T18:12:01.3674946Z Version : 1.1.2
2016-10-26T18:12:01.3674946Z Author : Microsoft Corporation
2016-10-26T18:12:01.3674946Z Help : [More Information](https://aka.ms/sqlazuredeployreadme)
2016-10-26T18:12:01.3674946Z ==============================================================================
2016-10-26T18:12:04.8304591Z packageFile= C:\a\r1\a\MyProject\Database\Database.dacpac
2016-10-26T18:12:07.4389560Z Publishing to database 'MyDB' on server 'mydatabase.database.windows.net'.
2016-10-26T18:12:08.3318189Z Initializing deployment (Start)
2016-10-26T18:12:25.4560124Z *** The column [dbo].[Foo].[Bar] is being dropped, data loss could occur.
2016-10-26T18:12:26.2098293Z Initializing deployment (Complete)
2016-10-26T18:12:26.2098293Z Analyzing deployment plan (Start)
2016-10-26T18:12:26.2098293Z Analyzing deployment plan (Complete)
2016-10-26T18:12:26.2098293Z Updating database (Start)
2016-10-26T18:12:29.5605253Z An error occurred while the batch was being executed.
2016-10-26T18:12:29.5675257Z Updating database (Failed)
2016-10-26T18:12:30.4919483Z
2016-10-26T18:12:30.6439495Z ##[error]
SerializedRemoteException :
SerializedRemoteInvocationInfo :
ErrorRecord : *** Could not deploy package.
StackTrace : at System.Management.Automation.Interpreter.ThrowInstruction.Run(InterpretedFrame
frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Int
erpretedFrame frame)
WasThrownFromThrowStatement : True
Message : *** Could not deploy package.
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException :
TargetSite : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
System.Exception)
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
2016-10-26T18:12:30.6629481Z ##[section]Finishing: Execute Azure SQL : DacpacTask
我在那个构建中包含了一些其他的数据库更改,但是当我恢复删除列的提交时,发布成功了。
我还验证了即使 Bar
列中只有 NULL
也会出现同样的问题。
(显然我可以使用 SSMS 手动删除该列,但拥有 CI/CD 系统的目的是自动执行所有操作,因此我不必这样做。)
如何使用 VSTS DacpacTask 删除列?
您需要在执行 Azure SQL 的附加 SqlPackage.exe 参数中将 BlockOnPossibleDataLoss 参数指定为 false:DacpacTask 构建步骤。