Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joelniemela/maggy
SQL Migration Tool
https://github.com/joelniemela/maggy
cli macros migration-tool sql
Last synced: 2 months ago
JSON representation
SQL Migration Tool
- Host: GitHub
- URL: https://github.com/joelniemela/maggy
- Owner: JoelNiemela
- Created: 2022-07-31T18:34:17.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-06T20:16:06.000Z (about 2 years ago)
- Last Synced: 2023-03-06T00:58:18.663Z (almost 2 years ago)
- Topics: cli, macros, migration-tool, sql
- Language: PHP
- Homepage:
- Size: 2.44 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Maggy — An SQL Migration Tool ##
Maggy is a tool written in PHP to facilitate the making and applying of migrations for SQL databases.
## Installation ##
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## Maggy files ##
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:
```sql
--@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;
```## Maggy Syntax ##
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.
- 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.Every Maggy file must start with the `--@Version` macro.
### Full list of macros ###
- `--@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 the `Up` segment.
- `--@Down`
- Initiates the `Down` segment; all subsequent lines (until the next segment macro) belong to the `Down` segment.
- `--!Maggy`
- Enables Maggy support for the database. The first migration for a database with Maggy should use this command.