GithubHelp home page GithubHelp logo

dlevsha / compalex Goto Github PK

View Code? Open in Web Editor NEW
433.0 18.0 120.0 94 KB

Lightweight script to compare two database

PHP 87.24% CSS 5.36% JavaScript 2.06% Dockerfile 5.34%
database-schema compared-databases database-management database-migrations database-structure mysqldiff mysql-diff postgresql-diff pgsql-http mssql-diff

compalex's Introduction

README

What is Compalex?

Compalex is a lightweight script to compare two database schemas. It supports MySQL, MS SQL Server and PostgreSQL.

Try demo or visit http://compalex.net/

How to use

The easiest way to use Compalex is to use Docker.

You can build your own container using Dockerfile or use Docker Hub image:

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

You need to change variables for your own

DATABASE_DRIVER - database driver, possible value

  • mysql - for MySQL database
  • pgsql - for PostgreSQL database
  • dblib - for Microsoft SQL Server database
  • oci - for Oracle database

DATABASE_HOST and DATABASE_HOST_SECONDARY - database host name or IP for first and second server

If your compared DB run locally:

  • for MacOS and Windows user: use host.docker.internal instead of localhost in DATABASE_HOST and DATABASE_HOST_SECONDARY param. Because we run script inside container we need to use Host machine IP for connection.

  • for Linux user: use --network host option and localhost in DATABASE_HOST and DATABASE_HOST_SECONDARY param.

If you connect to DB outside your machine (external IP) use: -e DATABASE_HOST='[Your external IP]'.

DATABASE_PORT and DATABASE_PORT_SECONDARY - database port for first and second server

Default ports for DB:

  • 3306 - Mysql
  • 5432 - PostgreSQL
  • 1433 - MSSQL
  • 1521 - Oracle

DATABASE_NAME and DATABASE_NAME_SECONDARY - first and second database name

DATABASE_USER / DATABASE_PASSWORD and DATABASE_USER_SECONDARY / DATABASE_PASSWORD_SECONDARY - login and password to access your databases

DATABASE_DESCRIPTION and DATABASE_DESCRIPTION_SECONDARY - server description (not necessary). For information only. These names will display as a database name.

You can also use docker-compose.yml.

version: "3.7"

services:
  compalex:
    image: dlevsha/compalex
    container_name: compalex
    environment:
      - DATABASE_DRIVER=mysql
      - DATABASE_ENCODING=utf8
      - SAMPLE_DATA_LENGTH=100
      - DATABASE_HOST=host.docker.internal
      - DATABASE_PORT=3306
      - DATABASE_NAME=compalex_dev
      - DATABASE_USER=root
      - DATABASE_PASSWORD=password
      - DATABASE_DESCRIPTION=Developer database
      - DATABASE_HOST_SECONDARY=host.docker.internal
      - DATABASE_PORT_SECONDARY=3306
      - DATABASE_NAME_SECONDARY=compalex_prod
      - DATABASE_USER_SECONDARY=root
      - DATABASE_PASSWORD_SECONDARY=password
      - DATABASE_DESCRIPTION_SECONDARY=Production database
    ports:
      - "8000:8000"

Requirements

If you prefer use Compalex as PHP script please read instruction bellow.

Compalex is only supported by PHP 5.4 and up with PDO extension.

Installation

$ git clone https://github.com/dlevsha/compalex.git
$ cd compalex

Open .environment. You'll see configuration params

[ Main settings ]
; Possible DATABASE_DRIVER: 'mysql', 'pgsql', 'dblib', 'oci'.
; Please use 'dblib' for Microsoft SQL Server
DATABASE_DRIVER = mysql
DATABASE_ENCODING = utf8
SAMPLE_DATA_LENGTH = 100

[ Primary connection params ]
DATABASE_HOST = localhost
DATABASE_PORT = 3306
DATABASE_NAME = compalex_dev
DATABASE_USER = root
DATABASE_PASSWORD =
DATABASE_DESCRIPTION = Developer database

[ Secondary connection params ]
DATABASE_HOST_SECONDARY = localhost
DATABASE_PORT_SECONDARY = 3306
DATABASE_NAME_SECONDARY = compalex_prod
DATABASE_USER_SECONDARY = root
DATABASE_PASSWORD_SECONDARY =
DATABASE_DESCRIPTION_SECONDARY = Production database

where

DATABASE_DRIVER - database driver, possible value

  • mysql - for MySQL database
  • pgsql - for PostgreSQL database
  • dblib - for Microsoft SQL Server database
  • oci - for Oracle database

[ Primary connection params ] and [ Secondary connection params ]sections describes settings for first and second databases.

Where

DATABASE_HOST and DATABASE_HOST_SECONDARY - database host name or IP for first and second server

DATABASE_PORT and DATABASE_PORT_SECONDARY - database port for first and second server

Default ports:

  • 3306 - Mysql
  • 5432 - PostgreSQL
  • 1433 - MSSQL
  • 1521 - Oracle

DATABASE_NAME and DATABASE_NAME_SECONDARY - first and second database name

DATABASE_USER / DATABASE_PASSWORD and DATABASE_USER_SECONDARY / DATABASE_PASSWORD_SECONDARY - login and password to access your databases

DATABASE_DESCRIPTION and DATABASE_DESCRIPTION_SECONDARY - server description (not necessary). For information only. These names will display as a database name.

Inside compalex directory run

$ php -S localhost:8000

Now open your browser and type http://localhost:8000/

You'll see database schema of two compared databases.

Database Compare Panel

You can run this script in terminal (for example, if you don't have direct connection to database).

I recommend eLinks (free text-based console web browser) because it supports HTML-formatting and colors.

Install the script and run web-server as described above on your server.

Then run:

$ elinks http://localhost:8000

You'll see database schema in your terminal

Database schema in terminal

Sometimes you have only SSH access to remote database server and you can't open port for external connections. In this case you can use port forwarding via SSH

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

This command will forward 1521 port from remote servers to local 1522 and 1523 respectively.

LICENSE

Copyright (c) 2021, Levsha Dmitry

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

compalex's People

Contributors

amarjitsingh52922 avatar dlevsha avatar gareth-ib avatar georgynet avatar vaalon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compalex's Issues

Docker deploy?

For those of us not using PHP, this seems like the ideal app to deploy in a Docker - anyone able to do this?

Connection is Microsoft Azure SQL

Hello i try to compare two Azure MS SQL Databases but i always get:

Compalex
Database schema compare tool
ERROR:
SQLSTATE[01002] Adaptive Server connection failed (COOLHOSTNAME:1433) (severity 9)
Stack trace:
#0 /usr/src/compalex/driver/abstract.php(34): PDO->__construct('dblib:host=COOL...', 'ACOOLUSERNAME...', 'CRYPTICPASSWORD...', Array)
#1 /usr/src/compalex/driver/abstract.php(17): BaseDriver->_getConnect('dblib:host=COOLHost...', 'cooldatabasename...')
#2 /usr/src/compalex/driver/abstract.php(65): BaseDriver->_getSecondConnect()
#3 /usr/src/compalex/driver/mssql.php(22): BaseDriver->_getCompareArray('SELECT DISTINCT...')
#4 /usr/src/compalex/index.php(28): Driver->getCompareTables()
#5 {main}

I added a dns server to the docker-compose so i am sure he can resolve the hostname, also i am sure about the used usernames/passwords/databasenames.

What could i do wrong ?

Warning with php > 7.1

When a table does not exist on either primary or secondary, the page displays the following php warning under the table name when using php versions greater than 7.1.

Warning: count(): Parameter must be an array or an object that implements Countable in home/vagrant/Compalex/compalex/template/compare.php on line 72

This warning is also displayed on the CLI screen.

Sorry I have not had enough time to suggest a fix yet.

Can't connect if database password includes a question mark

If the user's password contains a question mark "?" then Compalex fails with error "compare’s server IP address could not be found". This is because the generated URL can not be parsed with PHPs parse_url and returns false instead, causing the connection to fail.

I could only get around this by creating a new sql account without this character in the randomly generated password

ERROR: could not find driver

image

I setup Apache2.4.26(Win64) and PHP Version 7.0.21 added php_pdo_sqlsrv_7_ts_x64.dll and php_sqlsrv_7_ts_x64.dll. As result i got this error. Please give me the tip to solve this problem. Thank you.

Improvements by a real life need

Sorry, could not easily find where to submit a request for new feature.
We are designing an internal tool that does something similar, but would be happy to use this.
We have several databases on our server, and some of them have a delta database. This is a database that tracks changes in each field (basically, copies the field before the change+ adds four meta fields unique id, delta date, delta type, delta comment). The point is, I need to compare the delta db to its real life counterpart and make sure they are 100% same. With the exceptions of the added 4 fields.

That was a real life example to what we need a schema checker like that + the ability to add exceptions.
Is it in the road map?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.