Pluto ♇ This tool will help you better control a non-versioned database project.
English | Português
Pluto is a dwarf planet and it represents transformation, change and reform. And our pluto helps the project that doesn't have database versioning to organize itself and be able to count on this very important resource these days.
Thanks Laravel our migrations project was inspired by how it handles this.
- Supports several types of databases: MySQL and PostgreSQL(Implemented);
- The executable file is less than 20mb in size;
- Supports Linux and Mac OS;
- Multi Projects, you can have several projects connecting to the same database, and sharing migrations;
- Uses XML as input language, being less bureaucratic and accepting very large sql statements
Download the latest installation package
curl -L -o pluto https://github.com/astrolink/pluto/releases/download/v0.1.19/pluto-osx
sudo chmod +x pluto
sudo mv pluto /usr/local/bin/pluto
or
curl -L -o pluto https://github.com/astrolink/pluto/releases/download/v0.1.19/pluto-linux
sudo chmod +x pluto
sudo mv pluto /usr/local/bin/pluto
To check pluto is properly installed use
pluto version
You must be at the root of the project
pluto init
It will create a file called pluto.yml and the migrations folder with an example
What the file created by pluto will look like:
mysql:
host: "127.0.0.1"
port: 3306
database: "api"
username: "root"
password: "secret"
log: "mysql"
source: "api" // What is the data source for that migration
Checks if the connection file has been set up correctly
pluto test
After that we can run pluto
pluto run
With the pluto.yml file configured with the database data When running run, all migrations that have not yet run will be executed
pluto rollback step=-1
If it is necessary to go back some step, you can run the rollback and the opposite instruction will be run.
pluto make create_users_table
To create a new migration run the make command with the name that the migration will have it is suggested to keep the naming standard.
pluto restart
Reset the pluto table in the database be careful when running
The migration file has four fields
<?xml version="1.0" encoding="UTF-8"?>
<pluto>
<database>
mysql
</database>
<run>
CREATE TABLE users (name VARCHAR(20),email VARCHAR(20),created_at DATE);
</run>
<rollback>
DROP TABLE users;
</rollback>
<author>
John Doe - john.doe@example.com
</author>
<description>
PLUTO - User table created
</description>
</pluto>
The XML file must be around the pluto structure this field and all others are mandatory.
Database: is which connection it will use from pluto.yml (Possible mysql and postgre)
Run: SQL statement that will be run for the next step
Rollback: SQL statement that will be run on rollback
Author: Who created the SQL statement (Optional)
Description: Description of what is done in that migration will be saved in the database
If you have a massive volume of data, try using CDATA
tag to organize and scape your query string. Like this:
<![CDATA[ <insert_query_here> ]]>
Full documentation is available on the website: https://astrolink.github.io/pluto
A pluto_logs table will be created in the database where you can check what was or was not run and what is the origin of that migration
First download the project as a package
go get -v github.com/astrolink/pluto@v0.1.19
go mod vendor
If you want to run the migrations from a point, use
package main
import (
"github.com/astrolink/pluto/general/pluto"
)
func main() {
pluto.RunMigrations()
}
If you want to run the rollback
package main
import (
"github.com/astrolink/pluto/general/pluto"
)
func main() {
pluto.RunRollback()
}
That way you can launch go from within your project and package it together.
Remembering that even in this mode you need to have the migrations folder and the pluto.yaml file
Fork or download the source code
Use Golang 1.19+
and run the following commands
go mod tidy
// osx
go build -x
file pluto
mv pluto pluto-osx
// linux
GOOS=linux GOARCH=amd64 go build -x
file pluto
mv pluto pluto-linux
// install on OSX to test
mv pluto pluto-osx /usr/local/bin/pluto
The project uses git flow, so do the following:
git flow release start v0.1.x
git flow release finish 'v0.1.x'
git push origin v0.1.x
- PostgreSQL
- Improve error handling
- 100% code coverage with testing
- More useful health check commands
Thank you for your interest in contributing! Please refer to CONTRIBUTING.md
Many thanks to everyone who helped:
The source code in pluto
is available under the MIT License.