mysql / schematic
A simple MySQL migration management tool in PHP, create and update databases automatically with a config json file without having to use inbuilt ORM functions.
Installs: 723
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 7
Forks: 6
Open Issues: 12
Requires
- php: >=5.3.2
- symfony/console: v2.5.6
- symfony/yaml: *
Requires (Dev)
- phpunit/phpunit: 3.7.*
README
NO LONGER MAINTAINED
Due to the fact that Schematic was never truly fully completed with all the features I wanted it to have, I'm shelving it for the time being, if anyone would like to become the new active contributer let me know. However I've now moved on to Laravel as my main framework and Laravel migrations have now taken over from Schematic.
A database migrations tool, allows for easy database maintenance in a way that is easy to setup in a continuous integration environment.
###Install locally via Composer
{
require: {
"mysql/schematic": "1.*.*"
}
}
###Install it Globally
- Run the following commands:
Download the PHAR file:
wget --no-check-certificate https://github.com/andrefigueira/Schematic/raw/master/schematic.phar
Make the PHAR package executable
chmod +x schematic.phar
Move it to the user bin folder
mv schematic.phar /usr/local/bin/schematic
Then use Schematic
schematic
Schematic will now be available globally for you!
###Schema format
Schema is defined in schema files, these must be stored in the schema folder in json files representing the table they are for, e.g. (Make sure that you create the schema folder in the root of your project)
~/ProjectFolder/schemas/table_name.yaml
The schema file contains all of the configuration of the database in order to create it or amend it, see an example below.
In the current version you need to pass a type and null through always, you pass the length in parenthesis on the type field.
Schematic uses all of the base MySQL values so you just need to put them into this file and they will work, if you spell something incorrectly, it will stop running and throw and exception.
###Example Schema
schematic:
name: Schematic
version: 1.4.5
database:
general:
name: schematic
charset: utf8
collation: utf8_general_ci
engine: InnoDB
tables:
hello_world:
fields:
id:
type: int(11)
'null': false
unsigned: true
autoIncrement: true
index: 'PRIMARY KEY'
client_id:
type: int(24)
'null': false
unsigned: true
autoIncrement: false
name:
type: varchar(128)
'null': false
unsigned: false
autoIncrement: false
rename: full_name
description:
type: varchar(256)
'null': false
unsigned: false
autoIncrement: false
created_date:
type: datetime
'null': false
unsigned: false
autoIncrement: false
Note that currently foreign keys are only added, but not removed, If created a new database with constraints, you must run the update twice to add the constraints.
Usage:
schematic [options] command [arguments]
Options:
--help -h Display this help message.
--quiet -q Do not output any message.
--verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version -V Display this application version.
--ansi Force ANSI output.
--no-ansi Disable ANSI output.
--no-interaction -n Do not ask any interactive question.
Available commands:
help Displays help for a command
list Lists commands
Migrations
migrations:execute Executes the database migration based on the JSON schema files
migrations:generate Generates the database schema JSON files
migrations:mapping Generates the database schema based on an existing database
The script also creates a log of all of the database changes which are made.