diff --git a/metatags_quick.install b/metatags_quick.install index 71f2821..e62c0ab 100644 --- a/metatags_quick.install +++ b/metatags_quick.install @@ -30,7 +30,10 @@ function metatags_quick_schema() { 'description' => 'Language code', ), ), - 'primary key' => array('id', 'path', 'lang',), + 'primary key' => array('id'), + 'unique keys' => array( + 'lang_path' => array('lang', 'path'), + ), ); return $schema; } @@ -99,4 +102,22 @@ function metatags_quick_update_7003() { db_drop_field('metatags_quick_path_based', 'fid'); db_drop_field('metatags_quick_path_based', 'value'); } -} \ No newline at end of file +} + +/** + * Change primary key to id field and add unique index on path and lang. + */ +function metatags_quick_update_7004() { + /* + * Normally we'd use db_drop_primary_key()/db_add_primary_key(), but MySQL + * wont let us drop the primary key if it's an autoincrement field. Altering + * like this, however, works. + * + * This will fail on SQLite, as its ALTER TABLE is rather simplified, but as + * this change is introduced because of SQLites failure to install in the + * first place, that's irrelevant. PostgreSQL seems to support the same + * syntax, so it should work. + */ + db_query('ALTER TABLE {metatags_quick_path_based} DROP PRIMARY KEY, ADD PRIMARY KEY (`id`)'); + db_add_unique_key('metatags_quick_path_based', 'lang_path', array('lang', 'path')); +}