Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    129
    Plugin Contributions
    5

    Default Comparing tables structure fromdifferent databases (versions)

    Comparing files with a tool like Winmerge is easy but when it comes to database...

    To compare structures changes in Zen Cart tables between two ZC versions or between a default version and a cart with lots of plugins can be pretty hard.

    I found a way to compare two tables using MySQL derivated tables. It might be usefull to others, so here it is:
    This query compares tables 'customers' from two different databases (here 'vanilla' and 'prod').

    Code:
    SELECT column_name,ordinal_position,data_type,column_type FROM 
    ( SELECT column_name,ordinal_position, data_type,column_type,COUNT(1) rowcount FROM information_schema.columns WHERE 
    ( (table_schema='vanilla' AND table_name='customers') OR (table_schema='prod' AND table_name='customers') ) 
    GROUP BY column_name,ordinal_position, data_type,column_type HAVING COUNT(1)=1 ) A;
    Try it by changing tables and databases names.
    The result is a table containing differences bettween the two compared tables.

    By the way I would like to know how do you do this kind of comparaison. Is there a specialized tool I don't know of?
    Tested on ZC 1.5.8a database, PHP 8.1 and MySQL 8.034

  2. #2
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    129
    Plugin Contributions
    5

    Default Re: Comparing tables structure fromdifferent databases (versions)

    Quote Originally Posted by pilou2 View Post
    ...
    I found a way to compare two tables using MySQL derivated tables. It might be usefull to others, so here it is:
    This query compares tables 'customers' from two different databases (here 'vanilla' and 'prod').

    Code:
    SELECT column_name,ordinal_position,data_type,column_type FROM 
    ( SELECT column_name,ordinal_position, data_type,column_type,COUNT(1) rowcount FROM information_schema.columns WHERE 
    ( (table_schema='vanilla' AND table_name='customers') OR (table_schema='prod' AND table_name='customers') ) 
    GROUP BY column_name,ordinal_position, data_type,column_type HAVING COUNT(1)=1 ) A;
    ...
    Well it seems I was tired when I did this post... I use derived table and not 'derivated'... And the SQL query is not optimized at all, there are some useless stuff left over...
    The following query returns differences between tables 'products' in databases 'vanilla' and 'prod' based on GROUP BY parameters:

    Code:
    SELECT db as 'Database',column_name,ordinal_position,data_type,column_type FROM 
    ( SELECT table_schema as db,column_name,ordinal_position,data_type,column_type FROM information_schema.columns WHERE 
    ( (table_schema='vanilla' AND table_name='products') OR (table_schema='prod' AND table_name='products') ) 
    GROUP BY column_name,data_type,column_type HAVING COUNT(1)=1 ) as A 
    ORDER BY ordinal_position ASC;
    Last edited by pilou2; 17 Oct 2023 at 07:36 PM.

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,721
    Plugin Contributions
    124

    Default Re: Comparing tables structure fromdifferent databases (versions)

    phpMyAdmin has an option to export STRUCTURE only. This will allow you to do a quick comparison.
    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  4. #4
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    129
    Plugin Contributions
    5

    Default Re: Comparing tables structure fromdifferent databases (versions)

    Quote Originally Posted by swguy View Post
    phpMyAdmin has an option to export STRUCTURE only. This will allow you to do a quick comparison.
    I actually use this function for backup of structure (for developpement) and comparaison too in combinaison with WinMerge. It is probably the quickest way I know to compare but I am looking for a more 'direct' way that could be incorporated in a script too.
    The SQL query although powerfull needs to be tweaked for each type of comparaison, which makes it a little bit complicated to use. I am now thinking that a PHP script with parameters for the query is the way to go. I just need time to code something...

 

 

Similar Threads

  1. Can Templates from Prior Versions Be Added to Later Versions?
    By PSurf in forum Templates, Stylesheets, Page Layout
    Replies: 18
    Last Post: 6 Dec 2011, 02:38 AM
  2. Question about file comparing
    By bluetooth in forum Upgrading from 1.3.x to 1.3.9
    Replies: 1
    Last Post: 15 Jun 2010, 04:48 PM
  3. Comparing Zen Vesions
    By Renz in forum Upgrading from 1.3.x to 1.3.9
    Replies: 10
    Last Post: 1 Jun 2010, 09:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR