Code Monkey home page Code Monkey logo

compare-sql-schema's Introduction

compare-sql-schema

Objective

As its name, this tool is implemented mainly to compare SQL schemas.

Usage

node src/app.js first_path sec_path

Output

Markdown file is exported. Check ./reports folders for example.

Caveat

We use this sql-ddl-to-json-schema lib as a parser, but it is not perfect. We have to clean the input before feeding it in the parser. Here are some regexps that we use to ignore some sections of the input file

const nonDDLRegex = /(--.*(\n)?)|(\/\*.*(\n?))|(DELIMITER.*(\n.*)*\nDELIMITER.*(\n)?)|(CONSTRAINT.*CHECK.*\n)|(INSERT INTO.*(\n.*)*)/g;
  • Ignore comments
  --
  -- Table structure for table `corebanking_fx_requests`
  --
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
  • Ignore functions (usually start and end with DELIMITER
DELIMITER ;;
CREATE FUNCTION `DATE_TRUNC`(...
END ;;
DELIMITER ;
  • Ignore constraint with check
CONSTRAINT `token_address_check` CHECK (regexp_like(`token_address`,_utf8mb4'^0x[0-9a-fA-F]{40}$')),
CONSTRAINT `wallet_address_check` CHECK (regexp_like(`wallet_address`,_utf8mb4'^0x[0-9a-fA-F]{40}$'))
  • Ignore data generation part
INSERT INTO `schema_migrations` (version) VALUES
('20120129231330'),
('20120705005644'),
('20120711033715'),
('20120711044839'),
('20120711054138'),
...
const edgeCasesRegex = /((?<!((PRIMARY|FOREIGN) )|\S)KEY.*\n)|(UNIQUE KEY.*\n)/g;
  • Ignore normal keys and unique keys (keep primary and foreign keys). If we parse these keys, the parser will take forever. This is probably a tool bug.
PRIMARY KEY (`id`),
UNIQUE KEY `index_xfers_transitions_on_sort_key_and_xfers_transaction_id` (`sort_key`,`xfers_transaction_id`), -- ignore
UNIQUE KEY `index_xfers_transitions_parent_most_recent` (`xfers_transaction_id`,`most_recent`), -- ignore
KEY `index_xfers_transitions_on_xfers_transaction_id` (`xfers_transaction_id`) -- ignore

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.