tworzenieweb / sql-provisioner
Simple CLI tool for validating SQL files before inserting them into DB.
Requires
- php: >=7.0
- ext-pdo: *
- cweiske/php-sqllint: ^0.1.3
- jdorn/sql-formatter: ^1.2
- swiftmailer/swiftmailer: ^6.0
- symfony/config: ^3.2
- symfony/console: ^3.2
- symfony/dependency-injection: ^3.2
- symfony/expression-language: ^3.4
- symfony/filesystem: ^3.2
- symfony/finder: ^3.2
- symfony/process: ^3.2
- twig/twig: ^2.4
- vlucas/phpdotenv: ^2.4
Requires (Dev)
- bossa/phpspec2-expect: ^3.0
- leanphp/phpspec-code-coverage: ^4.2
- leaphub/phpcs-symfony2-standard: ~2.0.0
- memio/spec-gen: ^0.8
- phpspec/phpspec: ^4.0
README
SQL Provisioner
Simple CLI tool for database changes deploying. It allows to review each dbdeploy file before executution.
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.
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
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
composer require tworzenieweb/sql-provisioner
Then you should be able to run command from vendor/bin/sql-provisioner
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.
The script will look for .env
file containing connection information in format:
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
vendor/bin/sql-provisioner --init [path-to-folder]
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.
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
Demo
This is cinerama demo of usage
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Luke Adamczewski - Initial work - tworzenieweb
License
This project is licensed under the MIT License - see the LICENSE.md file for details