Easy-digital-downloads: Customers/Customer meta table improvements

Created on 15 Jan 2018  路  5Comments  路  Source: easydigitaldownloads/easy-digital-downloads

(See #2256 for the original issue & discussion when this table was introduced.)

Currently:

id bigint(20) NOT NULL AUTO_INCREMENT,
user_id bigint(20) NOT NULL,
email varchar(50) NOT NULL,
name mediumtext NOT NULL,
purchase_value mediumtext NOT NULL,
purchase_count bigint(20) NOT NULL,
payment_ids longtext NOT NULL,
notes longtext NOT NULL,
date_created datetime NOT NULL,
PRIMARY KEY  (id),
UNIQUE KEY email (email),
KEY user (user_id)

Recommended:

id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_id bigint(20) unsigned NOT NULL default '0',
email varchar(100) NOT NULL default '',
name mediumtext NOT NULL default '',
purchase_value mediumtext NOT NULL,
purchase_count bigint(20) unsigned NOT NULL default '0',
payment_ids longtext NOT NULL default '',
date_created datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id),
UNIQUE KEY email (email),
KEY user (user_id)

In English:

  • Make bigint's unsigned because negative numbers should not be allowed in them
  • Enlarge email from 50 to 100 to match what's now in wp_edd_orders
  • Add default values everywhere, because they are NOT NULL
  • Default value for date_created that is a properly formatted empty date string
  • Remove the notes column, which we can move to wp_edd_notes with a customer note type and ID

Tangent

I noticed that wp_edd_customermeta has an un'prefixed customer_id column. This should now be edd_customer_id to avoid collisions and bugs with _get_meta_table() and to be brought up to speed with other work going into EDD3.

component-administration type-feature

Most helpful comment

We should also remove the payment_ids column because the new edd_orders table will store a customer_id linking the two together nicely.

The current method also isn't best when deleting payments - we need to search the array to remove the payment ID (not very efficient if a customer has, say 1,000 orders) and then update the DB.

All 5 comments

Remove the notes column, which we can move to wp_edd_notes with a customer note type and ID

This will require an upgrade routine to migrate existing notes over.

We should also remove the payment_ids column because the new edd_orders table will store a customer_id linking the two together nicely.

The current method also isn't best when deleting payments - we need to search the array to remove the payment ID (not very efficient if a customer has, say 1,000 orders) and then update the DB.

We'll need an upgrade routine that alters the name of the meta column from customer_id to edd_customer_id.

we'll also need an upgrade routine to handle the customer record re-creation for purcahses that had an email address over 50 characters, as the payment would have been successful, but the customer would not have been created.

Merged.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davidsherlock picture davidsherlock  路  4Comments

mihaijoldis picture mihaijoldis  路  5Comments

Ismail-elkorchi picture Ismail-elkorchi  路  3Comments

michaelbeil picture michaelbeil  路  5Comments

mindctrl picture mindctrl  路  4Comments