Pronounce "pee-git" - a database migration tool that lets you keep your schema and migrations in a git repository.
- Implement support for the
changeset
file type - Implement support for the
definition
file type - Build out a CLI
go get github.com/chriscasola/pgit/cmd/pgit
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
Each file will have -- pgit type=<some_type>
on the first line where <some_type>
is replace with one of the
supported file types:
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;
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);
Run tests with go test