Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imantung/postgres_to_gomigrate
Prepare migration files in the existing Postgres database
https://github.com/imantung/postgres_to_gomigrate
Last synced: 15 days ago
JSON representation
Prepare migration files in the existing Postgres database
- Host: GitHub
- URL: https://github.com/imantung/postgres_to_gomigrate
- Owner: imantung
- Created: 2021-10-07T06:21:08.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-05-05T05:57:10.000Z (over 2 years ago)
- Last Synced: 2024-06-19T16:37:22.435Z (7 months ago)
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# POSTGRES_TO_GOMIGRATE
Simple script to prepare [gomigrate](https://github.com/golang-migrate/migrate) migration files from existing postgres database
1. Setup Postgres (we setup using docker-compose)
```bash
# start postgres
docker compose up -d# stop and clean postgres
docker compose down -v# execute initial database script
PGPASSWORD=pass psql -h localhost -p 5434 -U user -d user -f initial_database.sql# postgres cli
PGPASSWORD=pass psql -h localhost -p 5434 -U user -d user
```2. Generate migrations file (edit the script for different configs)
```bash
# remove the previous generated files
rm -rf migrations# run the script
go run generate_migration.go
```3. Test for GoMigrate (don't forget to clean your database before)
```bash
# install gomigrate
brew install golang-migrate# migrate database
migrate -path migrations -database "postgresql://user:pass@localhost:5434/user?sslmode=disable" up# rollback database
migrate -path migrations -database "postgresql://user:pass@localhost:5434/user?sslmode=disable" down
```