pluto

command module
v0.1.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 1 Imported by: 0

README ΒΆ

Pluto ♇ This tool will help you better control a non-versioned database project.

Releases All Releases Last commit Go Report Go Build

English | PortuguΓͺs

πŸ“– Introduction:

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.

πŸš€ Features:

  • 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

🧰 How to install

Download the latest installation package

Install on OSX

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

Install on Linux

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
Check install

To check pluto is properly installed use

pluto version

πŸƒ Using

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

How to use

Releases

πŸ’» Migration file

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

Dealing with large volumes

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> ]]>

πŸ“š Documentation (in progress)

Full documentation is available on the website: https://astrolink.github.io/pluto

πŸ–₯️ Database

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

πŸ”₯ How to use pluto inside another project in Go

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

🏠 How to test location

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

⚑ How to generate a new release

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

πŸ–ŠοΈ To Do

  • PostgreSQL
  • Improve error handling
  • 100% code coverage with testing
  • More useful health check commands

πŸ—οΈ Contributing (in progress)

Thank you for your interest in contributing! Please refer to CONTRIBUTING.md

πŸ‘‹ Contributors

Many thanks to everyone who helped:

Contributors

πŸ“„ License

The source code in pluto is available under the MIT License.

Documentation ΒΆ

Overview ΒΆ

Copyright Β© 2022 Roger Souza <rogersilvasouza@hotmail.com>

Directories ΒΆ

Path Synopsis
general
internal
env

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL