博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Team Foundation Server在SQL数据库中的对象更改的修订历史记录
阅读量:2513 次
发布时间:2019-05-11

本文共 10494 字,大约阅读时间需要 34 分钟。

Similarly, as described previously in , where the revision history is covered for the Git source control system, we’ll present the workflow of reviewing the history of committed SQL database objects using Team Foundation Server (TFS) source control system. In order to use TFS and have SQL database objects being version controlled, is required, as well as , either installed on a machine or TFS through , which is actually TFS “in the cloud”.

同样,如前面所述,Git源代码控制系统涵盖了修订历史记录,我们将介绍使用Team Foundation Server(TFS)源代码控制系统来审查已提交SQL数据库对象的历史记录的工作流程。 为了使用TFS并控制SQL数据库对象的版本,需要以及 ,它们既可以安装在计算机上,也可以通过安装在TFS上,而实际上是“在云中”的TFS。

This article covers the following: revision history review, comparing between versions of the same SQL database object in two changesets, getting specific version of an object, and applying it against a database.

本文涵盖以下内容:修订历史记录回顾,在两个变更集中比较同一SQL数据库对象的版本,获取对象的特定版本,并将其应用于数据库。

For the purpose of this article, TFS server is installed and initially set. Using Visual Studio, a new TFS project (repository) called StoreDB is created. It is assumed that the Visual Studio is installed in order to access the TFS server (in particular TFS repository). In addition to this, SQL database objects are already , initially committed to the repository, and additional changes (shown below) are made against a database and committed to the TFS project in order to show the history of committed changesets. There will be no explanation about the installation process or setting up for the TFS server/repository, performing commits, and making changes in SQL database.

出于本文的目的,已安装TFS服务器并进行了初始设置。 使用Visual Studio,创建一个名为StoreDB的新TFS项目(存储库)。 假定已安装Visual Studio,以便访问TFS服务器(特别是TFS存储库)。 除此之外,SQL数据库对象已被 ,最初已提交给存储库,并且针对数据库进行了其他更改(如下所示)并提交给TFS项目,以显示提交的更改集的历史记录。 对于安装过程或对TFS服务器/存储库的设置,执行提交以及在SQL数据库中进行更改,将没有任何解释。

As a starting point, the following changes are committed to the repository:

首先,将对存储库进行以下更改:

  • Initial commit of all database objects

    初始提交所有数据库对象

  • Created a new table dbo.Currency using the following script:

    使用以下脚本创建一个新表dbo.Currency

    CREATE TABLE [dbo].[Currency]( [CurrencyCode] [nchar](3) NOT NULL ,[Name] NVARCHAR(20) NOT NULL ,[ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Currency_ModifiedDate] DEFAULT(getdate()) );
  • A column renamed from Name to CurrencyName in the dbo.Currency table using the following script:

    使用以下脚本将dbo.Currency表中的从Name命名CurrencyName的列:

    EXEC [sys].[sp_rename] N'dbo.Currency.Name' ,'CurrencyName'

使用Visual Studio的修订历史记录查看 (Revision history review using Visual Studio)

In order to get to the history of committed changes in Visual Studio, navigate to the Source Control Explorer pane, from the Team Explorer pane:

为了获取在Visual Studio中提交的更改的历史记录,请从“团队资源管理器”窗格导航到“ 源代码控制资源管理器”窗格:

This shows a list of all objects that are being version controlled, under the StoreDB project:

这显示了StoreDB项目下所有受版本控制的对象的列表:

To access the project history, make sure that the Folders icon is selected in the main toolbar, which will show the TFS project structure. Right click the project (in this case StoreDB) and select the View history option:

要访问项目历史记录,请确保在主工具栏中选择了Folders图标,这将显示TFS项目结构。 右键单击项目(在本例中为StoreDB ),然后选择“ 查看历史记录”选项:

This initiates the History tab, showing the list of all committed changes:

这将启动“ 历史记录”选项卡,显示所有已提交更改的列表:

For instance, the list shown in the above image represents changes performed against a database that are committed to the TFS project. From this point, the only way to explore the exact changeset is using the Comment column. To inspect the specific changeset in details, right click on it and select the Changeset Details option:

例如,上图所示的列表表示针对数据库执行的,已提交给TFS项目的更改。 从这一点出发,探索确切变更集的唯一方法是使用“ 注释”列。 要检查特定变更集的详细信息,请右键单击它,然后选择“ 变更集详细信息”选项:

This will open the changeset details in the Team Explorer pane, showing all information from the previously inspected list of committed changesets that includes the timestamp of the commit (in this case 05/27/2016 11:04:14 AM), changeset ID (Changeset 7), comment (Created new table dbo.Currency) and a list of all files included in the changeset (in this case it is a single SQL file for the dbo.Currency table):

这将在“ 团队资源管理器”窗格中打开变更集详细信息,显示先前检查的已提交变更集列表中的所有信息,包括提交的时间戳记(在本例中为05/27/2016 11:04:14 AM ),变更集ID( 变更集7 ),注释( 创建新表dbo.Currency )和变更集中包含的所有文件的列表(在本例中,它是dbo.Currency表的单个SQL文件):

In the right click menu of any file from the changeset, there are options to open/review the file (either in the Source Control Explorer pane or to review the actual script in the new tab):

在变更集中的任何文件的右键菜单中,都有用于打开/查看文件的选项(在“ 源代码管理浏览器”窗格中或在新选项卡中查看实际脚本):

For instance, clicking the Open command opens the actual SQL script of the selected object:

例如,单击“ 打开”命令将打开所选对象的实际SQL脚本:

The above image shows the version of the dbo.Currency table from the specific changeset (in this case Changeset 7). To view the entire history for the single object, right click on it (from the specific changeset through the Team Explorer menu as shown above, or from the Source Control Explorer tree), and select the View history option. Since the above right-click menu is shown from the Team Explorer pane, the following is the option shown in the Source Control Explorer right click menu:

上图显示了来自特定变更集(在本例中为Changeset 7 )的dbo.Currency表的版本。 要查看单个对象的全部历史记录,请右键单击它(从特定的变更集中,通过如上所示的Team Explorer菜单,或从Source Control Explorer树中),然后选择“ 查看历史记录”选项。 由于上面的右键单击菜单是从Team Explorer窗格显示的,因此以下是Source Control Explorer右键单击菜单中显示的选项:

Choosing any of the above presented options to review the history of committed changesets for the specific object gives the same result:

选择上述提供的任何选项来查看特定对象的已提交变更集的历史记录,将得到相同的结果:

The above image shows the list of all changes made against the specific object (in this case the dbo.Currency table), along with the information who made changes, when, and what is the comment used when the change was committed.

上图显示了针对特定对象(在本例中为dbo.Currency表)所做的所有更改的列表,以及进行更改的信息,更改时间以及提交更改时使用的注释。

比较版本 (Compare between versions)

There are a lot of comparison options in TFS. On top of that, you can compare one project with any other project as well as any folder/file under the project with any folder/file from other project. For expedience sake, we’ll not go in details about explaining all of the combinations. Instead, we’ll focus on a comparison between different version of the same object in two changesets. For this purpose, we’ll use the dbo.Currency table since it is initially added in the first commit, the Name column is renamed to CurrencyName, and committed in another changeset.

TFS中有很多比较选项。 最重要的是,您可以将一个项目与任何其他项目进行比较,并将该项目下的任何文件夹/文件与其他项目中的任何文件夹/文件进行比较。 为了方便起见,我们将不详细解释所有组合。 相反,我们将重点放在两个变更集中同一对象的不同版本之间的比较。 为此,我们将使用dbo.Currency表,因为它最初是在第一次提交中添加的, Name列被重命名为CurrencyName ,并在另一个变更集中提交。

To compare two changesets, right click on one of them, from the history of committed changesets and choose the Compare option (the same can be achieved by highlighting the changeset and clicking the Compare button from the toolbar):

要比较两个变更集,请从已提交的变更集的历史记录中右键单击其中之一,然后选择“ 比较”选项(突出显示变更集并单击工具栏上的“ 比较”按钮,即可实现此目的):

This initiates the Compare form, where the source and the target for the comparison should be specified. By default, the changeset that is highlighted in the list or right-clicked, will be set as a source (The Source Path field is set to point to the StoreDB project, and the previously highlighted Changeset 7 is already specified). The user should specify the target changeset (in this case, we specified the same project as the Target Path value).

这将启动“ 比较”表单,其中应指定比较的源和目标。 默认情况下,列表中突出显示或右键单击的变更集将被设置为源(“ 源路径”字段设置为指向StoreDB项目,并且已经指定了先前突出显示的变更集7 )。 用户应指定目标变更集(在这种情况下,我们指定了与“ 目标路径”值相同的项目)。

The target version can be either a changeset, the latest version, a label, or the version of an object from the local workspace, which is actually the latest state of the object that is not yet committed to the repository. Since the goal is to compare the version of the dbo.Currency table from the Changeset 7 (where the initial version of the table is committed), and the Changeset 8 (one of the columns is renamed), we will set the target to Changeset 8:

目标版本可以是变更集,最新版本,标签或本地工作空间中对象的版本,实际上是尚未提交到存储库的对象的最新状态。 由于目标是比较Changeset 7提交表的初始版本)和Changeset 8 (重命名其中一列)中dbo.Currency表的版本,因此我们将目标设置为Changeset 8

After clicking the OK button, the comparison will run, giving the following results in this particular case:

单击确定按钮后,将运行比较,在这种特殊情况下,将给出以下结果:

At this point, the comparison confirms that there are differences. In case there are multiple files committed in a single changeset, all of them will be shown after the comparison, on the appropriate side (source or target), along with the information about the differences. In order to see the exact differences, right click on the pair of objects in the list, and select the Compare Files option (or highlight the pair and click the Compare button from the upper toolbar):

此时,比较确认存在差异。 如果在一个变更集中提交了多个文件,则将在比较后在适当的一面(源或目标)上显示所有文件以及有关差异的信息。 为了查看确切的差异,请右键单击列表中的一对对象,然后选择“ 比较文件”选项(或突出显示该对对象,然后单击上方工具栏中的“ 比较”按钮):

This will give the line-by-line comparison of two different version of an object:

这将提供对象的两个不同版本的逐行比较:

The result shows that there are actually two different lines, the one for the renamed column, and another one that holds the timestamp of saving the script. This way, the version of an object from one changeset can be compared with another version of the same object from another changeset.

结果显示实际上有两行,一行用于重命名的列,另一行包含保存脚本的时间戳。 这样,可以将来自一个变更集的对象版本与来自另一个变更集的同一对象的另一个版本进行比较。

获取特定版本 (Get specific version)

To get specific version of an object, navigate to the history for that object, and right click on the changeset and select the Rollback Entire Changeset option:

要获取对象的特定版本,请导航至该对象的历史记录,然后右键单击更改集,然后选择“ 回滚整个更改集”选项:

All changes from the selected changeset will be reverted locally, and prepared to be committed:

所选变更集的所有变更都将在本地还原,并准备提交:

In case there are multiple files in a single changeset, but only specific ones are meant to be reverted, simply undo the unwanted files using the Undo option from the right-click context menu:

如果在一个变更集中有多个文件,但是只打算还原特定的文件,只需使用右键单击上下文菜单中的“ 撤消”选项来撤消不需要的文件:

Since the changeset where the dbo.Currency table is committed contains a single object, there’s nothing to be reverted. By providing the check-in comment and clicking the Check-in button, the previously reverted change will replace the latest version of the dbo.Currency table on the repository. This way any version of an object from the history of committed changesets can be reverted.

由于提交dbo.Currency表的更改集包含单个对象,因此没有任何要还原的内容。 通过提供签入注释并单击“签入”按钮,以前还原的更改将替换存储库上dbo.Currency表的最新版本。 这样,可以还原已提交变更集历史记录中的对象的任何版本。

翻译自:

转载地址:http://jgiwd.baihongyu.com/

你可能感兴趣的文章
java InputStream读取数据问题
查看>>
学习感悟1
查看>>
树莓派VNC
查看>>
bzoj4004: [JLOI2015]装备购买
查看>>
web文件上传的实现
查看>>
SpringMVC_2
查看>>
Hadoop点滴-初识MapReduce(1)
查看>>
[专栏]壹周技术秀(第2期)
查看>>
js JSON
查看>>
该内存不能read 或written数值 叙述
查看>>
少个人保护?我来!——阿里云在ICANN第3届GDD峰会纪实
查看>>
[Spark性能调优] 第四章 : Spark Shuffle 中 JVM 内存使用及配置内幕详情
查看>>
虚拟机安装
查看>>
L1-045 宇宙无敌大招呼
查看>>
[笔记]Android 源码编译
查看>>
EasyUI特殊情况下的BUG整理
查看>>
10个最实用的Linux命令
查看>>
poj2155二维树状数组区间更新
查看>>
iOS开发UI篇—UIWindow简单介绍
查看>>
在sap系统设置纸张打印格式
查看>>