Code Monkey home page Code Monkey logo

maggy's Introduction

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:

--@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.