https://github.com/chriscasola/pgit
A database migration tool that lets you keep your schema in git, with the rest of your project.
https://github.com/chriscasola/pgit
database database-migrations git migration schema version-control
Last synced: about 2 months ago
JSON representation
A database migration tool that lets you keep your schema in git, with the rest of your project.
- Host: GitHub
- URL: https://github.com/chriscasola/pgit
- Owner: chriscasola
- License: mit
- Created: 2017-09-16T02:53:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T15:51:06.000Z (over 7 years ago)
- Last Synced: 2025-08-14T18:09:24.797Z (11 months ago)
- Topics: database, database-migrations, git, migration, schema, version-control
- Language: Go
- Size: 27.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changeset_file.go
- License: LICENSE
Awesome Lists containing this project
README
# pgit [](https://circleci.com/gh/chriscasola/pgit)
Pronounce "pee-git" - a database migration tool that lets you keep your schema and migrations in a git repository.
## Roadmap
- [x] Implement support for the `changeset` file type
- [x] Implement support for the `definition` file type
- [x] 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 -root migrate`
### File Types
Each file will have `-- pgit type=` on the first line where `` 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.
```SQL
-- 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.
```SQL
-- 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`