Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Last active March 20, 2024 13:06
Show Gist options
  • Save julienbourdeau/cca88e986a75e19488c2397f1386a3dc to your computer and use it in GitHub Desktop.
Save julienbourdeau/cca88e986a75e19488c2397f1386a3dc to your computer and use it in GitHub Desktop.
Clean PrestaShop database - Drop old and unless data
# Delete all logs
TRUNCATE ps_log;
# Delete old connection data (only used for stats)
# change 2016-02-01 00:00:00 according to you needs
DELETE c, cs
FROM ps_connections c
LEFT JOIN ps_connections_source cs ON (c.id_connections = cs.id_connections)
WHERE c.date_add < '2016-02-01 00:00:00';
OPTIMIZE TABLE ps_connections, ps_connections_source;
# Delete all guest without entry in ps_customer table
DELETE g
FROM ps_guest g
LEFT JOIN ps_customer c ON (g.id_customer = c.id_customer)
WHERE c.id_customer IS NULL;
OPTIMIZE TABLE ps_guest;
# Delete tables
# Scenes are deprecated in 1.6 (used only if upgrading with feature active)
DROP TABLE `ps_scene`;
DROP TABLE `ps_scene_category`;
DROP TABLE `ps_scene_lang`;
TRUNCATE `ps_scene_products`;
DROP TABLE `ps_scene_shop`;
UPDATE `ps_configuration` SET value='0', date_upd=NOW() WHERE `name` = 'PS_SCENE_FEATURE_ACTIVE';
@ingenium13
Copy link

Do these not work on some versions of mysql/mariadb? All of these queries that contain both DELETE and LEFT JOIN error out with:

Unrecognized keyword. (near LEFT JOIN)
Unrecognized statement type. (near LEFT JOIN)

@Skinperforator
Copy link

Do these not work on some versions of mysql/mariadb? All of these queries that contain both DELETE and LEFT JOIN error out with:

Unrecognized keyword. (near LEFT JOIN)
Unrecognized statement type. (near LEFT JOIN)

I have the same problem.

@dave-lw
Copy link

dave-lw commented Sep 15, 2022

curious, will deleting old carts of COMPLETED orders cause an error 500 opening the order should it ever be reviewed? Someone just asked me to help them remove all carts over 1 yr old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment