Categorygithub.com/chriscasola/pgit
modulepackage
0.0.0-20190214155106-9c8f23545e79
Repository: https://github.com/chriscasola/pgit.git
Documentation: pkg.go.dev

# README

pgit CircleCI

Pronounce "pee-git" - a database migration tool that lets you keep your schema and migrations in a git repository.

Roadmap

  • Implement support for the changeset file type
  • Implement support for the definition file type
  • Build out a CLI

Installing

go get github.com/chriscasola/pgit/cmd/pgit

Usage

With pgit you should place all of the .sql files describing your database and migrations into a single directory inside your project (there can be nested directories).

To perform a migration run pgit -database <database-connection-string> -root <path-to-sql-directory> migrate

File Types

Each file will have -- pgit type=<some_type> on the first line where <some_type> is replace with one of the supported file types:

changeset

This type of file is most useful for statements that create tables, modify tables, or similar operations that you want to record as a sequence of steps in your file.

-- pgit type=changeset

-- change
CREATE TABLE some_table
(
    col_a text
);

-- rollback
DROP TABLE some_table

-- change
ALTER TABLE some_table ADD COLUMN col_b text;

-- rollback
ALTER TABLE some_table DROP COLUMN col_b;

definition

This type of file is most useful for stored procedures or functions. For this type of file pgit will use the git history to track revisions. You need only keep the most recent version of the definition in the file, along with SQL to rollback that version.

-- pgit type=definition

-- definition
CREATE FUNCTION do_something(
    param_a text
)
BEGIN
END;

-- rollback
DROP FUNCTION do_something(text);

Developers

Run tests with go test

# Packages

No description provided by the author

# Functions

New initializes and returns a new Pgit instance.
NewSQLDatabaseConnection returns a new DatabaseConnection using the given database URL and table name to track the migration state.

# Structs

Pgit is an instance of Pgit that is bound to a specific schema directory where the database schema is located and a particular database connection.
SQLDatabaseConnection contains pointers to the data about what migration state the database is in.

# Interfaces

DatabaseConnection defines the interface to connections to various types of databases.