Drupal Live and Dev sync

When developing Drupal one often needs to pull recent copies of the live database into the dev environment.

Loading a dump into the dev database will update any existing tables, add any new ones - but it won't remove tables from the dev environment that re not in live.

This causes problems with Drupal as module install and update hooks may need to create tables which don't yet exist on live.

My solution which assumes you have .my.cnf set up to provide login locally is below.

Read more

SQL Greatest and Least

Most of the time I can get what I want out of SQL using the standard aggregate functions, but today I needed to find the latest timestamp from any one of three columns.

I achieved this using the GREATEST() function, it's not party of the SQL standard but is commonly available.

GREATEST(value [, ...])

Read more

Updating Drupal

For most of 2008 I've been working on a large Drupal installation (around 10 developers,  something like 100 custom modules, 17 languages, split over 2 sites).

This all adds up to a lot of updates, and schema changes.

Drupal's hook_install, and hook_update_N functions are pretty good, but not perfect at bringing order to this chaos.

Read more

Number Crunching : Database vs OOP

For the last few months I've been working on a project that is part website and part data processing.

In theory the website is the bulk of the project, but in practice processing the data has taken a disproportionate amount of resources.

Data exchange with another organisation is always tricky - and in this case we have incoming data that doesn't conform to specification, business rules that change, and a daily data import to run.

The code I've been working on has been through a couple of versions, and now I have in mind a third

Read more

Drupal multisite with shared tables

Drupal allows you to create multiple sites sharing some or all of the same code and optionally sharing some database tables.

The documentation for the Drupal settings file
http://api.drupal.org/api/file/sites/default/settings.php/5/source

includes the following

<?php
/*
* To have all database names prefixed, set $db_prefix as a string:
*
* $db_prefix = 'main_';
*
* To provide prefixes for specific tables, set $db_prefix as an array.
* The array's keys are the table names and the values are the prefixes.

Read more

SQL for Smarties

cover of SQL for Smarties Joe Celko's SQL for Smarties: Advanced SQL Programming (The Morgan Kaufmann Series in Data Management Systems)
Joe Celko
* *
£44.75

buy from amazon

 

I was really looking forward to reading this book, it had been on my wish list for years....

But it's hard to know how to tackle it.

This is a heavyweight book and it's mostly organised by SQL keyword with some chapters on subjects like temporal queries and statistics.

It seems to me that the best way to read this book is cover to cover - but for me it's just to big to do that.

The book also suffers from being too oriented towards 'pure' SQL, spending pages on features that aren't yet available.

Read more

Adding comments to the database

Comments in code are widely used and generally (but not universally) accepted as a good thing.

Databases can also accommodate comments - but these seem to be very rarely used.

I'm of the opinion that database comments are very useful.

It's often hard to determine the exact meaning of a column - maybe it would be ideal to rename the column but you don't want to risk breaking code.

Read more

Full text searching on PostgreSQL with tsearch2

I’ve just been experimenting with text searches: http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html

It’s worth noting that most of the commands in the above tutorial
assume you are running as the database superuser, this is required to
run the setup script but then you can grant permission for an ordinary
user for the search tables (in the public schema names starting pg_ts_)

Read more