简体   繁体   English

代码和数据跟踪/部署

[英]Code & data tracking / deployment

For a long time now, we've held our data within the project's repository. 长期以来,我们一直将数据保存在项目存储库中。 We just held everything under data/sql, and each table had its own create_tablename.sql and data_tablename.sql files. 我们只是将所有内容都保存在data / sql下,并且每个表都有其自己的create_tablename.sql和data_tablename.sql文件。

We have now just deployed our 2nd project onto Scalr and we've realised it's a bit messy. 现在,我们刚刚将第二个项目部署到了​​Scalr上,并且我们意识到它有点混乱。

The way we deploy: 我们的部署方式:

We have a "packageup" collection of scripts which tear apart the project into 3 archives (data, code, static files) which we then store in 3 separate buckets on S3. 我们有一个“打包”脚本集合,这些脚本将项目分解为3个归档文件(数据,代码,静态文件),然后将它们存储在S3上的3个单独的存储桶中。

Whenever a role starts up, it downloads one of the files (depending on the role: data, nfs or web) and then a "unpackage" script sets up everything for each role, loads the data into mysql, sets up the nfs, etc. 每当角色启动时,它都会下载一个文件(取决于角色:数据,nfs或Web),然后“解包”脚本为每个角色设置所有内容,将数据加载到mysql中,设置nfs等。 。

We do it like this because we don't want to save server images, we always start from vanilla instances onto which we install everything from scratch using various in-house built scripts. 之所以这样做是因为我们不想保存服务器映像,我们总是从原始实例开始,使用各种内部构建的脚本从头开始安装所有内容。 Startup time isn't an issue (we have a ready to use farm in 9 minutes). 启动时间不是问题(我们可以在9分钟内准备使用场)。

The issue is that it's a pain trying to find the right version of the database whenever we try to setup a new development build (at any point in time, we've got about 4 dev builds for a project). 问题是,每当我们尝试建立新的开发版本时(尝试在任何时间点上为一个项目获得大约4个开发版本),都很难找到正确的数据库版本。 Also, git is starting to choke once we go into production, as the sql files end up totalling around 500mb. 另外,一旦我们投入生产,git就开始令人窒息,因为sql文件最终总计约500mb。

The question is: 问题是:

How is everyone else managing databases? 其他人如何管理数据库? I've been looking for something that makes it easy to take data out of production into dev, and also migrating data from dev into production, but haven't stumbled upon anything. 我一直在寻找可以轻松地将数据从生产环境转移到开发环境,以及将数据从开发环境迁移到生产环境的东西,但是并没有发现任何问题。

You should seriously take a look at dbdeploy (dbdeploy.com). 您应该认真看一下dbdeploy(dbdeploy.com)。 It is ported to many languages, the major ones being Java and PHP. 它被移植到许多语言中,主要是Java和PHP。 It is integrated in build-tools like Ant and Phing, and allows easy sharing of so called delta files. 它集成在Ant和Phing等构建工具中,并允许轻松共享所谓的增量文件。

A delta file always consists of a deploy section, but can also contain an undo section. 增量文件始终包含一个deploy部分,但也可以包含一个undo部分。 When you commit your delta file and another developer checks it out, he can just run dbdeploy and all new changes are automatically applied to his database. 当您提交增量文件而另一位开发人员将其签出时,他只需运行dbdeploy,所有新更改都将自动应用于他的数据库。

I'm using dbdeploy for my open source blog, so you can take a look on how delta files are organized: http://site.svn.dasprids.de/trunk/sql/deltas/ 我将dbdeploy用于我的开源博客,因此您可以看一下增量文件的组织方式: http ://site.svn.dasprids.de/trunk/sql/deltas/

How I understand your main question is expirience of other people in migrating of SQL data from dev into production. 我如何理解您的主要问题是其他人在将SQL数据从开发人员迁移到生产环境中的经验。

I use Microsoft SQL Server instead of My SQL, so I am not sure, that my expirience you can use directly. 我使用Microsoft SQL Server而不是My SQL,所以我不确定您可以直接使用我的经验。 Nevertheless this way works very good. 不过,这种方式非常有效。

I use Visual Studio 2010 Ultimate edition to compare data in two databases. 我使用Visual Studio 2010 Ultimate版来比较两个数据库中的数据。 The same feature exist also in Vinsual Studio Team Edition 2008 (or Database edition). Vinsual Studio Team Edition 2008(或数据库版本)中也存在相同的功能。 You can read http://msdn.microsoft.com/en-us/library/dd193261.aspx to understand how it works. 您可以阅读http://msdn.microsoft.com/en-us/library/dd193261.aspx以了解其工作原理。 You can compare two databases (dev and prod) and generate SQL Script for modifying the data. 您可以比较两个数据库(dev和prod),并生成用于修改数据的SQL脚本。 You can easy exclude some tables or some columns from the comparing. 您可以轻松地从比较中排除某些表或某些列。 You can also examine the results and exclude some entries from generation of the script. 您还可以检查结果,并从脚本生成中排除某些条目。 So one can easy and flexible generate scripts which can de used for deployment of the changes in the database. 因此,可以轻松灵活地生成脚本,这些脚本可用于部署数据库中的更改。 You can separetely compare the data of two databases from the sructure (schema compareing). 您可以从结构中分别比较两个数据库的数据(模式比较)。 So you can refresh data in dev with the data from prod or generate scripts which modify prod database to the last version of the dev database. 因此,您可以使用prod中的数据刷新dev中的数据,或生成将prod数据库修改为dev数据库的最新版本的脚本。 I recommend you to look at this features and some products of http://www.red-gate.com/ (like http://www.red-gate.com/products/SQL_Compare/index.htm ). 我建议您查看此功能以及http://www.red-gate.com/的某些产品(例如http://www.red-gate.com/products/SQL_Compare/index.htm )。

Check out capistrano . 退房capistrano It's a tool the ruby community uses for deployment to different enviroments and I find it really useful. 这是ruby社区用于部署到不同环境的工具,我发现它确实很有用。

Also if your deployment is starting to choke try a tool twitter built called Murder . 另外,如果您的部署开始受阻,请尝试构建一个名为Murder的工具twitter。

Personally i'd look at Toad 我个人会看蟾蜍

http://www.toadworld.com/ http://www.toadworld.com/

Less than 10k ;) ... will analyse database structures, produce scripts to modify them and also will migrate data. 少于10k;)...将分析数据库结构,生成修改它们的脚本,还将迁移数据。

One part of the solution is to capture the version of each of your code modules and their corresponding data resources in a single location, and compare them to ensure consistency. 解决方案的一部分是在单个位置捕获每个代码模块的版本及其对应的数据资源,并进行比较以确保一致性。 For example, an increment in the version number of your, say, customer_comments module will require a corresponding SQL delta file to upgrade the relevant DB tables to the equal version number for the data. 例如, customer_comments模块的版本号增加将需要一个相应的SQL delta文件,以将相关的DB表升级到该数据的相同版本号。

For an example, have a look at Magento's core_resource approach as documented by @AlanStorm. 例如,看看core_resource记录的Magento的core_resource 方法

Cheers, JD 欢呼,京东

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

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