Jump to content

WHMCS tables lack primary keys


Recommended Posts

While trying to import a WHMCS installation's (8.5.1) mysql dump into a replicated high available Mysql 8 database at Upcloud, the server gave me the warning that the tables lacked primary keys and this could cause issues with mysql replication.

What is the recommended practice in this case? Should I just go ahead and make the "id" columns in the tables into primary keys?

Link to comment
Share on other sites

There are two things causing this problem:

1 - Mysqldump and phpmyadmin both export a table in two stages - first they export the statement for creating the table, then they export an alter table statement to set the keys. This is easily fixable with mysqldump client command by using  --single-transaction flag so that mysqldump will export the table definition in one single statement. This makes the import go around that problem.

2 - However, there is a very oddly designed table in WHMCS db:

DROP TABLE IF EXISTS `tblticketpendingimports`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tblticketpendingimports` (
  `ticketmaillog_id` int NOT NULL,
  `ticket_id` int NOT NULL,
  UNIQUE KEY `ticketmaillog_id_ticket_id` (`ticketmaillog_id`,`ticket_id`),
  KEY `idx_ticket_id` (`ticket_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

This table does not have a primary key, instead, it uses a composite unique key. It doesn't even use a composite, non-named primary key made up from those two fields even. This breaks any import to high available Mysql databases because it hampers row-based replication.

I added a totally dummy primary key to this table and that made the import go through.


DROP TABLE IF EXISTS `tblticketpendingimports`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tblticketpendingimports` (
  `ticketmaillog_id` int NOT NULL,
  `ticket_id` int NOT NULL,
  `dummy_primary_key` int NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`dummy_primary_key`),
  UNIQUE KEY `ticketmaillog_id_ticket_id` (`ticketmaillog_id`,`ticket_id`),
  KEY `idx_ticket_id` (`ticket_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

Moreover, it seems like its working at WHMCS admin and user interfaces as well - they load without problems, and the email ticket interfaces also work normally. 

I think that this should be ok since the code would be constructing the queries by explicitly specifying column names, is this correct?

 

 


 

 

Edited by unity100
Link to comment
Share on other sites

Support says that WHMCS is not made for HA situations, however they confirmed that this change should not have noticeable impact since WHMCS already constructs the sql queries using field names. So the dummy primary key will mostly be ignored and it will only be used by the underlying replication of Mysql. This sounds workable.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated