How to merge Drupal database changes
Asked Answered
T

4

9

We currently use an SVN repository to ensure everyone's local environments are kept up-to-date. However, Drupal website development is somewhat trickier in that any custom code you write (for instance, PHP code written for a node body) is stored in the DB and the changes aren't recognized by the SVN working copy.

There are a couple of developers who are presently working on the same area of a Drupal site, but we're uncertain about how to best merge our local Drupal database changes together. Committing patches of database dumps seem clumsy at best and is most likely inefficient and error-prone for this purpose.

Any suggestions about how to approach this issue is appreciated!

Tapping answered 9/10, 2009 at 18:50 Comment(0)
O
5

Unfortunately, database deployment/update is one of Drupals weak spots. See this question & answers as well as this one for some suggestions on how to deal with it.

As for CCK, you could find some hints here.

As for php code in content, I agree with googletorp in that you should avoid doing this. However, if for some reason you absolutely have to do it, you could try to reduce the code to a simple function call. Thus you'd have the function itself in a module (and this would be tracked via SVN). But then you are only a little step from removing the need for the inline code anyways ...

Overhaul answered 9/10, 2009 at 21:52 Comment(0)
P
4

If you are putting php code into your database then you are doing it wrong. Some stuff are inside the database like views and cck fields plus some settings. But if you put php code inside the node body you are creating a big code maintenance problem. You should really use the API and hooks instead. Create modules instead of ugly hacks with eval etc.

Petrology answered 9/10, 2009 at 20:44 Comment(2)
Good suggestion, thanks. However, this still leaves the question open as to how you would merge other database changes that developers make to their local environments (such as adding CCK fields or node settings) before the whole thing goes live on a central database. Custom PHP code is one of the few input types built into Drupal (granted you can disable it in Drupal 6), which suggests that it is a more flexible feature of this CMS than an ugly hack.Tapping
It exists for quick and dirty work, but is generally regarded as a bad idea- all eval'd code is to be avoided. The problem you are facing is a perfect case in point. It is a good feature- it's good for quick experiments and building CCK/Views you know you will export and run as flat file code.Hashish
L
2

All that has been said above is true and good advice.. To answer your practical question, there are a number of recent modules that you could use to transport the changes done by the various developers.

The "Features" modules is a cure the the described issue of Drupal often providing nice features, albeit storing lots of configs and structure in the DB. This module enables you to capture a feature and output it as a pseudo-module (qualifies as a module with .info and code-files and all). Here is how it works:

  1. Select functionality/feature to export
  2. The module analyses the modules, files, DB content that is required to rebuild that feature elsewhere
  3. The module creates a pseudo-module that contains the instructions in #3 and outputs everything (even SQL to rebuild the stuff in the DB) into a module package (as well as sets dependencies for other modules required)
  4. Install the pseudo-module on your new site and enable it
  5. The pseudo-module replicates the feature you exported rebuilding DB data and all

And you can tell your boss you did it all manually with razor focus to avoid even 1 error ;) I hope this helps - http://drupal.org/project/features

Liturgics answered 6/4, 2011 at 17:34 Comment(0)
A
1

By committing patches of database dumps, do you mean taking an entire extract of the db and committing it after each change?

How about a master copy of the database? Extract all tables, views, sps, etc... into individual files, put them into svn and do your merge edits on the individual objects?

Arleta answered 9/10, 2009 at 18:58 Comment(2)
Yep, meant taking entire extract of the database. The output of this dump file really depends on how the developer specifies the output arguments (some may request DROP IF EXISTS statements, or comments to be included, for instance), so this isn't very reliable. Extracting every table seems a bit too tedious for what it's worth and comes with the same inconsistency issues.Tapping
I would standardize how you extract scripts - eg, always have drop if exists and permission statements, standard formatting. Also, if you have your objects individually scripted out, and devs commit all objects related to a change in one commit, it becomes more manageable. I'm assuming when you're committing and doing your resolves, you're looking through a big file and doing alot of scrolling. When you're working with individual files, this forces your focus on one thing. You only need to extract everything once, at the last working production state and work from there.Arleta

© 2022 - 2024 — McMap. All rights reserved.