subversion使用_使用Subversion在SQL数据库中对象更改的修订历史记录

subversion使用

In previous articles, I have already covered the revision history for Git and Team Foundation Server. Similarly, this article covers the revision history of committed changesets using Subversion as the source control system.

在之前的文章中,我已经介绍了GitTeam Foundation Server的修订历史。 同样,本文介绍了使用Subversion作为源代码控制系统的已提交变更集的修订历史。

For the purpose of the article, we’ll use a sample SQL database called MyDatabase whose objects are scripted and committed to the SVN repository. In order to work with Subversion, we’ll use Tortoise SVN, which is a Windows shell extension used to work on a local copy of a database and to communicate (commit changes to, and get changes from) the remote repository. For expediency, I will not go into details about initializing the repository, committing changes, or any other operation. The goal of the article is to cover the following: revision history of all committed changes, comparing two versions of the same object and get a specific version of the object from the revision history.

出于本文的目的,我们将使用一个名为MyDatabase的示例SQL数据库,该数据库的对象已编写脚本并提交到SVN存储库。 为了使用Subversion,我们将使用Tortoise SVN ,它是Windows Shell扩展,用于在数据库的本地副本上进行工作并与远程存储库进行通信(向其提交更改并从中获取更改)。 为了方便起见,我将不介绍有关初始化存储库,提交更改或任何其他操作的详细信息。 本文的目的是涵盖以下内容:所有已提交更改的修订历史记录,比较同一对象的两个版本,并从修订历史记录中获取对象的特定版本。

The following are changes that are committed to the repository, in order to have a history of committed changesets to review:

以下是已提交给存储库的更改,以便可以查看已提交的更改集的历史记录:

  • Initial commit of all database objects

    初始提交所有数据库对象
  • Added a new table dbo.Resellers using the following script:

    使用以下脚本添加了新表dbo.Resellers

    USE [MyDatabase]
    GO
     
    CREATE TABLE [dbo].[Resellers](
    	[ResellerID] [int] IDENTITY(1,1) NOT NULL,
    	[ResellerName] [nvarchar](50) NULL,
    	[AddressLine1] [nvarchar](50) NULL,
    	[AddressLine2] [nvarchar](50) NULL,
    	[City] [nvarchar](50) NULL,
    	[ZipCode] [int] NULL,
    	[DateOfContract] [date] NULL,
    	[Active] [bit] NULL,
     CONSTRAINT [PK_Resellers] PRIMARY KEY CLUSTERED 
    (
    	[ResellerID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
     
    GO
    
  • Modified the AddressLine1 column from the previously created dbo.Resellers table, by renaming it to StreetAddress. In the same changeset the AddressLine2 column is dropped in favor of creating the ApptNo column. The following scripts are used:

    通过将先前创建的dbo.Resellers表重命名为StreetAddress ,修改了AddressLine1 在同一变更集中,放置了AddressLine2列,以创建ApptNo列。 使用以下脚本:

    EXEC sp_rename 'dbo.Resellers.AddressLine1', 'StreetAddress', 'COLUMN';
    GO
     
    ALTER TABLE dbo.Resellers ADD ApptNo int;
     
    ALTER TABLE dbo.Resellers DROP COLUMN AddressLine2;
    
  • Creating the usp_ResellersInfo stored procedure

    创建usp_ResellersInfo存储过程

    USE [MyDatabase]
    GO
     
    CREATE PROCEDURE dbo.usp_ResellersInfo  
     
    AS
        SET NOCOUNT ON;  
        SELECT ResellerID, ResellerName, City, ZipCode   
        FROM dbo.Resellers;  
    GO
    

修订记录 (Revision history)

Once we have all of the above committed, let’s inspect the revision history. Since TotroiseSVN is a shell extension, all available options can be found in the right-click context menu of the working copy folder. To review the entire history of committed changesets, right-click the folder that represents the working copy of a remote repository and select the SVN Show log option. The same option is available on right-click menu inside the folder:

完成上述所有操作后,让我们检查修订历史。 由于TotroiseSVN是shell扩展,因此可以在工作副本文件夹的右键单击上下文菜单中找到所有可用选项。 要查看已提交变更集的全部历史记录,请右键单击代表远程存储库工作副本的文件夹,然后选择SVN Show log选项。 文件夹内的右键菜单上提供了相同的选项:

This initiates the History form:

这将启动“ 历史记录”表单:

All committed changes will be listed in the upper section, showing the exact revision ID (in this case from 1 to 4), the appropriate actions (added, modified, deleted), the user who performed the commit (in the Author column), timestamp of the commit, and the commit message.

所有已提交的更改将在上部列出,显示确切的修订ID(在这种情况下为1到4),适当的操作(添加,修改,删除),执行提交的用户(在“ 作者”列中),提交的时间戳和提交消息。

By highlighting any of the changesets from the list, the full commit message appears in the section below. In this case, for the selected changeset 4, the commit message says that the usp_ResellersInfo stored procedure is created/committed in this changeset. The last section shows the list of files committed in the selected changeset. For instance, we have committed only one file in Changeset 4, and that is a SQL script of the mentioned stored procedure.

通过突出显示列表中的任何变更集,完整的提交消息将显示在下面的部分中。 在这种情况下,对于选定的变更集4,提交消息指出在该变更集中已创建/提交了usp_ResellersInfo存储过程。 最后一部分显示了在所选变更集中提交的文件的列表。 例如,我们在Changeset 4中仅提交了一个文件,这是上述存储过程SQL脚本。

The history form contains all the information about the general overview of committed changes, such as who committed what and when. However, when it comes to reverting from the history, such changes need to be compared with the working copy (or even with other changesets) before applying.

历史记录表单包含有关已落实更改的一般概述的所有信息,例如谁在什么时间何时提交。 但是,当要从历史记录还原时,需要在应用之前将此类更改与工作副本(甚至与其他更改集)进行比较。

比较版本 (Compare between revisions)

In order to inspect specific change in details and compare between revisions, right click any of the changeset and click the Compare with previous revision option. Specifically, we’ll compare between Changeset 3 (where the dbo.Resellers table is created) and Changeset 4 (where we made some modifications in the dbo.Resellers table, and therefore it is expected to have some differences when comparing):

为了检查细节上的特定更改并在修订之间进行比较,请右键单击任何更改集,然后单击“ 与以前的修订比较”选项。 具体来说,我们将在Changeset 3 (在其中创建dbo.Resellers表的位置)和Changeset 4 (在dbo.Resellers表中进行了一些修改的位置之间进行比较 ,因此,在进行比较时,预计会有一些差异):

In case there are differences between the selected changeset (in this case Changeset 3 and the previous one (Changeset 2), the list of files where differences are detected will be shown. Since we have committed a single file (the Resellers table), it is the only one listed below:

如果所选变更集(在本例中为变更集3与上一个变更集(变更集2 )之间存在差异,则将显示检测到差异的文件列表。由于我们已提交了一个文件(“ 转销商”表),是下面列出的唯一一个:

The Changed Files form, shown in the above image, gives only the list of files where differences are detected. At this point, you can specify any other changeset as a source or the target for the comparison. This can be achieved by clicking any of the revisions, and specifying another revision for comparison:

如上图所示,“ 更改的文件”表单仅提供检测到差异的文件列表。 此时,您可以将任何其他变更集指定为比较的源或目标。 这可以通过单击任何一个修订,并指定另一个修订进行比较来实现:

To review the exact differences, right click on the file from the list, and from the context menu, choose the Compare revisions option:

要查看确切的差异,请右键单击列表中的文件,然后从上下文菜单中选择“ 比较修订”选项:

This initiates the form where the exact differences are available for review:

这将启动表格,其中可以查看确切的差异:

Specifically, the comparison between the version of the Resellers table from Changeset 3 and Changeset 2 gives the expected result. The AddressLine1 column was renamed to StreetAddress (line 7), the AddressLine2 column was dropped (line 8), and a new column ApptNo was created (line 12). These changes are committed in Changeset 3.

特别是,来自变更集3变更集2转销商表版本之间的比较给出了预期的结果。 将AddressLine1列重命名为StreetAddress (第7行) 删除AddressLine2列(第8行),并创建一个新列ApptNo (第12行)。 这些更改在Changeset 3中提交。

In addition to this, differences between two versions of the same object can be shown within a single form instead of showing the two tabs in parallel. To review differences in a single tab, right-click the file in the Changed Files form, and from the context menu, select the Show difference as unified diff option:

除此之外,同一对象的两个版本之间的差异可以用单一形式显示,而不必并行显示两个选项卡。 要在单个选项卡中查看差异,请在“ 更改的文件”表单中右键单击该文件,然后从上下文菜单中选择“将差异显示为统一的差异”选项:

This will combine object differences in a single form highlighting added lines in green, and removed ones in red. In this particular case, differences between the version of the Resellers table across two changesets will be as follows:

这将以单一形式组合对象差异,以绿色突出显示已添加的行,以红色突出显示已删除的行。 在这种特殊情况下,两个变更集之间的转销商表版本之间的差异如下:

特定对象的修订历史 (Revision history of the specific object)

In addition to reviewing the entire history, there is an option to review the history for a single object, ignoring any other objects and changesets that do not contain the specific object. In the example included in this article, there are 4 commits only, so it is not that hard to review the history. However, in case of having numerous commits from multiple users, where each commit contains a set of files, it is necessary to have a mechanism to show the history for a single file, isolated from the rest of the history. In order to achieve this, navigate to a file inside any changeset and from the right-click context menu, select the Show log option. In this case, we have selected the Resellers table inside the Changeset 3:

除了查看整个历史记录之外,还有一个选项可以查看单个对象的历史记录,而忽略其他任何对象和不包含特定对象的变更集。 在本文包含的示例中,仅4次提交,因此查看历史记录并不难。 但是,如果有来自多个用户的大量提交,其中每个提交都包含一组文件,则必须具有一种机制来显示单个文件的历史记录,并与历史记录的其余部分隔离开来。 为了实现此目的,请导航到任何变更集中的文件,然后从右键单击上下文菜单中选择“ 显示日志”选项。 在这种情况下,我们在Changeset 3中选择了Resellers表:

The complete history of a single object is shown, no matter in which changeset is selected (if the object is selected in the Changeset 5 for example, the Show log option will give the complete history for the selected objects, and not just up to the selected changeset). The form that the Show log option initiates is the same as the form for the history of all objects, but with the difference being that changesets containing the selected objects are the only ones that will be shown:

无论选择哪个变更集,都将显示单个对象的完整历史记录(例如,如果在Changeset 5中选择了该对象,则“ 显示日志”选项将提供所选对象的完整历史记录,而不仅限于此)。选择的变更集)。 “ 显示日志”选项启动的格式与所有对象的历史记录格式相同,但不同之处在于,仅显示包含所选对象的变更集:

In this case, only Changeset 2 (where the Resellers table is committed initially) and the Changeset 3 (where it is modified) will be shown.

在这种情况下,将仅显示变更集2(最初提交了Resellers表)和变更集3(在其中对其进行了修改)。

从历史记录中获取对象的特定版本 (Get a specific version of an object from history)

To get a specific version of an object from history and apply it on a working copy of a database, navigate to the specific object in the changeset that contains the version of the object to be applied. In this case, we’ll apply the initial version of the dbo.Resellers table initially committed in Changeset 2. Right-click on the object under the list of files from the single changeset, and from the context menu, select the Revert changes from this revision option:

要从历史记录中获取对象的特定版本并将其应用到数据库的工作副本中,请导航至包含要应用的对象版本的变更集中的特定对象。 在这种情况下,我们将应用最初在Changeset 2中提交的dbo.Resellers表的初始版本。 右键单击单个变更集中文件列表下的对象,然后从上下文菜单中选择“ 从此修订版本还原变更”选项:

Confirm reverting in the next dialog, and the summary of the operation will appear as follows:

在下一个对话框中确认还原,操作摘要将如下所示:

Checking the working copy shows that reverting was finished successfully, as the current version of the object is with the originally created columns AddresLine1, and AddressLine2, without the ApptNo column that was created in the next changeset:

检查工作副本显示还原成功完成,因为对象的当前版本具有最初创建的列AddresLine1AddressLine2,而没有在下一个变更集中创建的ApptNo列:

USE [MyDatabase]
GO
 
CREATE TABLE [dbo].[Resellers](
	[ResellerID] [int] IDENTITY(1,1) NOT NULL,
	[ResellerName] [nvarchar](50) NULL,
	[AddressLine1] [nvarchar](50) NULL,
	[AddressLine2] [nvarchar](50) NULL,
	[City] [nvarchar](50) NULL,
	[ZipCode] [int] NULL,
	[DateOfContract] [date] NULL,
	[Active] [bit] NULL,

By following these steps, any specific version of an object can be retrieved from the history and made the current version.

通过执行以下步骤,可以从历史记录中检索对象的任何特定版本,并将其作为当前版本。

有用的链接: ( Useful links: )

翻译自: https://www.sqlshack.com/revision-history-of-an-object-change-in-a-sql-database-using-subversion/

subversion使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值