Comparing the schemas of the two databases

When developing applications, sometimes there is a need to compare two databases (for example, prod and dev).

There are a number of approaches to solving this issue - from creating a dump file with a db structure and then using diff, to using specialized paid solutions like dbForge or RedGate (there is a large list here ).

Compalex is one such solution that combines free and easy to use.

Compalex is a set of scripts for quickly comparing two database schemas. For ease of use, all this is packaged in a Docker container, which contains both the scripts itself and the configured environment for connecting to the DB.

To start the container, you must specify:

docker run -it -e DATABASE_DRIVER='mysql' \
-e DATABASE_ENCODING='utf8' \
-e SAMPLE_DATA_LENGTH='100' \
-e DATABASE_HOST='host.docker.internal' \
-e DATABASE_PORT='3306' \
-e DATABASE_NAME='compalex_dev' \
-e DATABASE_USER='root' \
-e DATABASE_PASSWORD='password' \
-e DATABASE_DESCRIPTION='Developer database' \
-e DATABASE_HOST_SECONDARY='host.docker.internal' \
-e DATABASE_PORT_SECONDARY='3306' \
-e DATABASE_NAME_SECONDARY='compalex_prod' \
-e DATABASE_USER_SECONDARY='root' \
-e DATABASE_PASSWORD_SECONDARY='password' \
-e DATABASE_DESCRIPTION_SECONDARY='Production database' \
-p 8000:8000 dlevsha/compalex

Where:

DATABASE_DRIVER - used driver for connection

  • mysql - for MySQL

  • pgsql - for PostgreSQL

  • dblib - for Microsoft SQL Server

  • oci - for Oracle

DATABASE_HOSTand DATABASE_HOST_SECONDARY is the hostname or IP to connect to the first and second server.

If the bases are deployed locally to localhost:

For MacOS and Windows users : use host.docker.internalinstead localhost, as the script running inside the container should connect to the host machine.

Linux: --network host ( "" ) DB localhost, ip a docker0 ip .

3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500
    link/ether 02:42:e8:a9:95:58 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
DB SSH

SSH DB - SSH localhost , .

:

ssh -L 1522:localhost:1521 [user name]@[remote host 1]
ssh -L 1523:localhost:1521 [user name]@[remote host 2]

1521 remote host 1 remote host 2 localhost 1522 1523 .

DB, application , DB, :

ssh -L 1522:[remote database server 1]:1521 [user name]@[remote application host 1]
ssh -L 1523:[remote database server 2]:1521 [user name]@[remote application host 2]

DATABASE_HOST and DATABASE_HOST_SECONDARY ip, , .

- IP DB ( , ).

DATABASE_PORT and DATABASE_PORT_SECONDARY - .

:

  • 3306 - Mysql

  • 5432 - PostgreSQL

  • 1433 - MSSQL

  • 1521 - Oracle

DATABASE_NAME and DATABASE_NAME_SECONDARY -

DATABASE_USER / DATABASE_PASSWORD and DATABASE_USER_SECONDARY / DATABASE_PASSWORD_SECONDARY -

DATABASE_DESCRIPTION and DATABASE_DESCRIPTION_SECONDARY - (, ).

, http://localhost:8000. -, , .

.

eLinks, HTML- .

, ( ) :

$ elinks http://localhost:8000

:

( ).

.

Project on GitHub .

View on DockerHub




All Articles