Maggy is a tool written in PHP to facilitate the making and applying of migrations for SQL databases.
In order to install Maggy:
- Clone this repository
git clone https://github.com/JoelNiemela/Maggy.git
- Download an SQL server, such as
mariadb
- Configure
config.ini
to connect to your database
In Maggy, each migration is described by a Maggy file. Maggy files consist of vanilla SQL with Maggy macros that enable maggy migrate
and maggy rollback
.
Maggy files end with the .sql.maggy
file extension;
An example Maggy file:
--@Version 42 "Add user table"
--@Up
CREATE TABLE IF NOT EXISTS user (
user_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
--@Down
DROP TABLE user;
There are three types of Macros in Maggy:
- Segment macros (
--@Segment
):- Introduce new segments, such as
--@Up
and--@Down
. - Declare the context of a file with the
--@Version
macro.
- Introduce new segments, such as
- Attribute macros (
--#Attribute
):- Modify the behavior of SQL queries or other macros.
- Command macros (
--!Command
):- Enable Maggy for a database with the
--!Maggy
macro. - Shorthand for SQL queries.
- Enable Maggy for a database with the
Every Maggy file must start with the --@Version
macro.
--@Version [version] [description]
- Declare migration version of a file, along with a short description describing the migration.
--@Up
- Initiates the
Up
segment; all subsequent lines (until the next segment macro) belong to theUp
segment.
- Initiates the
--@Down
- Initiates the
Down
segment; all subsequent lines (until the next segment macro) belong to theDown
segment.
- Initiates the
--!Maggy
- Enables Maggy support for the database. The first migration for a database with Maggy should use this command.