热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为两个开发人员管理sql更改脚本的最佳方法是什么?-What'sthebestwaytomanagesqlchangescriptsfortwodevelopers?

UpuntilnowIvebeenalonewolfonmyclientprojects.AnytimeIwouldmakechangestoSQLServer

Up until now I've been a lone wolf on my client projects. Anytime I would make changes to SQL Server: tables updates, stored procs, etc. I would generate the change script and plop it into a directory. When the application was ready for release, I would run the scripts on the live server and be done.

到目前为止,我一直是我客户项目中的孤狼。任何时候我都会对SQL Server进行更改:表更新,存储过程等。我会生成更改脚本并将其放入目录中。当应用程序准备好发布时,我会在实时服务器上运行脚本并完成。

Soon I will have another developer working on the same project. The project files are all in source control. I'm just not exactly sure how to go about handling the change scripts. I'm guessing they should be under source control as well? If so, what would be the best naming convention? How exactly would I determine which scripts are to be executed on the next release? Keeping in mind that this is a fairly low-key, informal web project that does not have any version numbers or project management software.

很快我将有另一个开发人员在同一个项目上工作。项目文件都在源代码管理中。我只是不确定如何处理更改脚本。我猜它们也应该受源代码控制?如果是这样,最好的命名约定是什么?我究竟如何确定在下一个版本中执行哪些脚本?请记住,这是一个相当低调,非正式的Web项目,没有任何版本号或项目管理软件。

Thanks.

8 个解决方案

#1


1  

I currently store my sql change scripts in a folder and name them, script order number, tablename, description of change

我目前将我的sql更改脚本存储在一个文件夹中并命名它们,脚本订单号,表名,更改说明

1-User-create-table.sql

2-User-added-columns.sql

...

n

When I've executed these scripts I move them into a new folder, named "release 2009-09-01" and and then continue with the next number

当我执行这些脚本时,我将它们移动到一个名为“release 2009-09-01”的新文件夹中,然后继续下一个数字

#2


5  

Yes, you should put them in source control. The naming convention does not matter as much as being consistent with it does. One way is to append an artificial (create one) application version number in the filename of each script. We could probably give you better naming examples with if you give more detail. But, definitely you want them in source control.

是的,你应该把它们放在源代码管理中。命名约定与其一致无关紧要。一种方法是在每个脚本的文件名中附加一个人工(创建一个)应用程序版本号。如果您提供更多详细信息,我们可能会为您提供更好的命名示例。但是,你肯定希望它们在源代码控制中。

#3


2  

We source control the change scripts as .sql files, then keep the order of execution for the sql files in a batch file, which is also under source control. The batch file calls OSQL with the sql file as a parameter:

我们将更改脚本控制为.sql文件,然后将sql文件的执行顺序保存在批处理文件中,该文件也受源代码控制。批处理文件使用sql文件作为参数调用OSQL:

SQLScripts.Bat:

SET BASEDIR=%%1
SET SERVER=%%2
SET DATABASE=%%3

CALL RUNISQLW CreateUserPresets %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW CreateFundWorkflows %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spFundWorkflowAddFromTemplate %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spFundWorkflowListForGrid %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spWorkflowTasksListForGrid %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW fGetToleranceDate %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW fGetNotifyDate %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spWorkflowTasksManager %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spWorkflowTasksAnalyst %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW spWorkflowTasksNotify %BASEDIR% %SERVER% %DATABASE%
CALL RUNISQLW AddGateFrequency %BASEDIR% %SERVER% %DATABASE%

pause

RUNISQLW:

@REM First Parameter: Name of SQL file, without the .SQL extension.
@REM Second Parameter: Base Directory to run the file in.
@REM Third Parameter: Name of the server to run the file on.
@REM Fourth Parameter: Name of the Database on the server.

osql -S %3 -d %4 -E  -i %2\%1.sql -o %2\Output\%1.txt

We then call the SqlScripts batch file from a deployment.bat file for each configuration environemt, Dev, Staging or Production. This keeps it consistent across configs.

然后,我们从deployment.bat文件中为每个配置environemt,Dev,Staging或Production调用SqlScripts批处理文件。这使得它在配置中保持一致。

#4


1  

An important component I would suggest addressing is ordering - the files should include (perhaps at the beginning) some kind of sortable date & time stamp. This way you can accurately test and debug the order that the scripts are executed in.

我建议解决的一个重要组件是订购 - 文件应包括(可能在开头)某种可排序的日期和时间戳。这样,您就可以准确地测试和调试脚本执行的顺序。

#5


0  

If you are using VS Team Edition you can use the database edition to create a database project for the sql server version you are using.

如果您使用的是VS Team Edition,则可以使用数据库版本为正在使用的sql server版本创建数据库项目。

Then, build the project from the database, so you get all the functions, views, tables into the project.

然后,从数据库构建项目,以便将所有函数,视图和表格放入项目中。

Then, whenever you make changes, make it in the project, so it can be in svn easily (each file is there) and then you can just sync up your sql server database.

然后,无论何时进行更改,都可以在项目中进行更改,因此可以轻松地在svn中(每个文件都在那里)然后您可以同步您的sql server数据库。

This way you can update your database from changes your teammate made without messing up your data.

这样,您可以根据队友所做的更改更新数据库,而不会弄乱数据。

#6


0  

Start learning how to use branches with your source control. Which can be very valuable when working collaboratively.

开始学习如何在源代码控制中使用分支。在协同工作时,这可能非常有价值。

Some branching strategies can be:

一些分支策略可以是:

  • Name the branch after the developer (and each developer on the project will then be responsible for keeping their branch in sync with the mainline).
  • 在开发人员之后命名分支(然后项目中的每个开发人员将负责使他们的分支与主线保持同步)。

  • Create a new branch for every feature and then delete the branch once you have merged it back (Only really feasible with a distributed version control system)
  • 为每个功能创建一个新分支,然后在将其合并后再删除分支(仅对分布式版本控制系统真正可行)

#7


0  

Have a look at the patching engine used in DBSourceTools.
It's been specifically designed to help developers get SQL server databases under source-code control.

看看DBSourceTools中使用的修补引擎。它专门用于帮助开发人员在源代码控制下获得SQL服务器数据库。

This tool will allow you to baseline your database at a specific point, and create a named version (v1).
Then, create a deployment target - and increment the named version to v2.
Add patch scripts to the Patches directory for any changes to schema or data.
Finally, check the database and all patches into source-code control, to distribute with devs.

此工具允许您在特定点建立数据库基线,并创建命名版本(v1)。然后,创建部署目标 - 并将命名版本增加到v2。将补丁脚本添加到Patches目录,以获取对架构或数据的任何更改。最后,检查数据库和所有补丁到源代码控制中,与devs一起分发。

What this gives you is a repeatable process to test all patches to be applied from v1 to v2.
DBSourceTools also has functionality to help you create these scripts, i.e. schema compare or script data tools.

这给您带来了一个可重复的过程来测试从v1到v2应用的所有补丁。 DBSourceTools还具有帮助您创建这些脚本的功能,即模式比较或脚本数据工具。

Once you are done, all of the files in your patches directory become your release, and will upgrade your database from v1 to v2.

完成后,补丁目录中的所有文件都将成为您的版本,并将您的数据库从v1升级到v2。

Have fun.

#8


0  

Another way is to have a tool like http://www.red-gate.com/products/SQL_Compare/index.htm

另一种方法是使用像http://www.red-gate.com/products/SQL_Compare/index.htm这样的工具

It generates a change script for a single deployment. The good thing is that you don't have to count on the discipline of developers anymore.

它为单个部署生成更改脚本。好消息是你不必依赖开发人员的纪律了。

Apart from that, I still like to have the DB in SVN. I use SQLScript for that, see free utility to script DB objects in ms sql.

除此之外,我还是喜欢在SVN中使用DB。我使用SQLScript,请参阅ms sql中的脚本DB对象的免费实用程序。

EDIT

I now use Redgate SQL Version. Its pretty easy to put the changes into SVN with it. The only problem is that I have to start and use the Application, its not an automated process.

我现在使用Redgate SQL版本。使用它很容易将更改放入SVN。唯一的问题是我必须启动并使用应用程序,它不是自动化过程。


推荐阅读
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • ASP.NET2.0数据教程之十四:使用FormView的模板
    本文介绍了在ASP.NET 2.0中使用FormView控件来实现自定义的显示外观,与GridView和DetailsView不同,FormView使用模板来呈现,可以实现不规则的外观呈现。同时还介绍了TemplateField的用法和FormView与DetailsView的区别。 ... [详细]
  • MongoDB用户验证auth的权限设置及角色说明
    本文介绍了MongoDB用户验证auth的权限设置,包括readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase、cluster相关的权限以及root权限等角色的说明和使用方法。 ... [详细]
  • Week04面向对象设计与继承学习总结及作业要求
    本文总结了Week04面向对象设计与继承的重要知识点,包括对象、类、封装性、静态属性、静态方法、重载、继承和多态等。同时,还介绍了私有构造函数在类外部无法被调用、static不能访问非静态属性以及该类实例可以共享类里的static属性等内容。此外,还提到了作业要求,包括讲述一个在网上商城购物或在班级博客进行学习的故事,并使用Markdown的加粗标记和语句块标记标注关键名词和动词。最后,还提到了参考资料中关于UML类图如何绘制的范例。 ... [详细]
  • SpringBoot整合SpringSecurity+JWT实现单点登录
    SpringBoot整合SpringSecurity+JWT实现单点登录,Go语言社区,Golang程序员人脉社 ... [详细]
  • 在Kubernetes上部署JupyterHub的步骤和实验依赖
    本文介绍了在Kubernetes上部署JupyterHub的步骤和实验所需的依赖,包括安装Docker和K8s,使用kubeadm进行安装,以及更新下载的镜像等。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • 本文介绍了Python高级网络编程及TCP/IP协议簇的OSI七层模型。首先简单介绍了七层模型的各层及其封装解封装过程。然后讨论了程序开发中涉及到的网络通信内容,主要包括TCP协议、UDP协议和IPV4协议。最后还介绍了socket编程、聊天socket实现、远程执行命令、上传文件、socketserver及其源码分析等相关内容。 ... [详细]
  • Elasticsearch1Elasticsearch入门1.1Elasticsearch术语1.1.16.0以前的Elasticsearch术语1.1.26.0以后的Elasti ... [详细]
  • Java 11相对于Java 8,OptaPlanner性能提升有多大?
    本文通过基准测试比较了Java 11和Java 8对OptaPlanner的性能提升。测试结果表明,在相同的硬件环境下,Java 11相对于Java 8在垃圾回收方面表现更好,从而提升了OptaPlanner的性能。 ... [详细]
  • Postgresql备份和恢复的方法及命令行操作步骤
    本文介绍了使用Postgresql进行备份和恢复的方法及命令行操作步骤。通过使用pg_dump命令进行备份,pg_restore命令进行恢复,并设置-h localhost选项,可以完成数据的备份和恢复操作。此外,本文还提供了参考链接以获取更多详细信息。 ... [详细]
  • 上图是InnoDB存储引擎的结构。1、缓冲池InnoDB存储引擎是基于磁盘存储的,并将其中的记录按照页的方式进行管理。因此可以看作是基于磁盘的数据库系统。在数据库系统中,由于CPU速度 ... [详细]
author-avatar
人走茶凉
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有