Giter VIP home page Giter VIP logo

dblint's Introduction

dblint

dblint examines a relational database and makes suggestions to improve structure.

dblint's suggestions come from my experience as a relational database user and DBA.

At the moment, more is unimplemented than implemented, but it is a short example of the kinds of problems Prolog is good at solving.

Example Session

The sample database's structure is in basic.sql and looks something like this:

CREATE TABLE managers (id SERIAL PRIMARY KEY);

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR UNIQUE,
  manager_id INTEGER
);

CREATE TABLE projects (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users,
  tag1 VARCHAR,
  tag2 VARCHAR,
  tag3 VARCHAR,
  access1 VARCHAR,
  access2 VARCHAR
);

This is an example suggestion session:

$ swilgt
?- [loader].
true.

?- main::run_on_file('basic.sql').
Missing foreign key from projects (user_id) to users

  [alter,table,projects,add,constraint,projects_users_fk,foreign,key, (,user_id,),references,users, (,id,),;]
  
Missing foreign key from users (manager_id) to managers

  [alter,table,users,add,constraint,users_managers_fk,foreign,key, (,manager_id,),references,managers, (,id,),;]
  
Unindexed foreign key on projects (user_id)

  [create,index,on,projects, (,user_id,)]
  
Repeating group on projects with name access

  [begin,;,create,table,projects_accesses, (,),;,;,;,commit,;]
  
Repeating group on projects with name tag

  [begin,;,create,table,projects_tags, (,),;,;,;,commit,;]
  
Unnecessary surrogate key on users (use name instead)

  [alter,table,users,drop,column,id,,,add,primary,key, (,name,),;]

true.

So you can see that dblint correctly identified several types of problems, including repeating groups, a redundant surrogate key, an unindexed foreign key and a column that probably is a foreign key but lacks the constraint, and it even attempted to output SQL to correct it.

Future

My goal is to improve dblints suggestions. I don't mind staying relatively PostgreSQL specific, at least in terms of advice; I would like to be able to parse MySQL and others SQL even if I'm assuming that PostgreSQL is the actual target. I would like to ensure that the generated SQL takes into account earlier suggestions and can be configured to display particular categories of suggestion, such as style, normalization, etc.

dblint's People

Contributors

fusiongyro avatar

Watchers

 avatar

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.