2017 © Pedro Peláez
 

library sql-provisioner

Simple CLI tool for validating SQL files before inserting them into DB.

image

tworzenieweb/sql-provisioner

Simple CLI tool for validating SQL files before inserting them into DB.

  • Monday, April 16, 2018
  • by tworzenieweb
  • Repository
  • 3 Watchers
  • 2 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Build Status Scrutinizer Code Quality, (*1)

SensioLabsInsight, (*2)

SQL Provisioner

Simple CLI tool for database changes deploying. It allows to review each dbdeploy file before executution., (*3)

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system., (*4)

Prerequisites

To use this library, you would need to have composer installed and have a table for storing already performed DB deploys. Lastly, you would need to provide .env file with connection information and table and column name for checks, (*5)

DATABASE_USER=[user]
DATABASE_PASSWORD=[password]
DATABASE_HOST=[host]
DATABASE_PORT=[port]
DATABASE_NAME=[database]
PROVISIONING_TABLE=changelog_database_deployments
PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN=deploy_script_number

Installing

It installs just like any other composer project, (*6)

composer require tworzenieweb/sql-provisioner

Then you should be able to run command from vendor/bin/sql-provisioner, (*7)

vendor/bin/sql-provisioner /location/to/your/sql/files

Using

The vendor/bin/sql-provisioner [path-to-folder] command will scan the content of [path-to-folder] directory., (*8)

The script will look for .env file containing connection information in format:, (*9)

DATABASE_USER=[user]
DATABASE_PASSWORD=[password]
DATABASE_HOST=[host]
DATABASE_PORT=[port]
DATABASE_NAME=[database]
PROVISIONING_TABLE=changelog_database_deployments
PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN=deploy_script_number

If you want to create initial .env use --init, (*10)

vendor/bin/sql-provisioner --init [path-to-folder], (*11)

The next step is searching for sql files and trying to queue them in numerical order. First n-th digits of a filename will be treated as candidate number. This will be used then to check in database if a certain file was already deployed (PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN). Before the insert, it will print the formatted output of a file and result of internal syntax check. Then you can either skip or execute each., (*12)

If you would like to skip already provisioned candidates use --skip-provisioned If you would like to skip syntax checking (for speed purpose) of candidates use --skip-syntax-check, (*13)

Demo

This is cinerama demo of usage, (*14)

asciicast, (*15)

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository., (*16)

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details, (*17)

The Versions