Manage postgresql cluster migration easly
-
Postgresql 9.5 or above
-
Go 1.16 or above
-
pg_dump
(optional) to support reverse migration
-
Support multiple connections and schemas
-
Reverse migration from existing database
-
Auto clean dirty migration
-
Download latest release
https://github.com/suryakoinworks/kw-migrate/tags
-
Extract source
-
Download dependencies
cd kmt && go get && go mod tidy
-
Build
go build -o kmt
-
Run
mv kmt /usr/local/bin/kmt
-
Set executable
chmod a+x /usr/local/bin/kmt
-
Check using
kmt --help
-
kmt create <schema> <name>
to create new migration file -
kmt up <db> <schema>
to deploy migration(s) from database and schema -
kmt drop <db> <schema>
to drop migration(s) from database and schema -
kmt generate <schema>
to reverse migration from yoursource
database -
kmt rollback <db> <schema> <step>
to rollback migration version from database and schema -
kmt run <db> <schema> <step>
to run migration version from database and schema -
kmt sync <cluster> <schema>
to sync migration in cluster for schema -
kmt set <db> <schema>
to set migration to specific version -
kmt clean <db> <schema>
to clean migration on database and schema -
kmt version <db> <schema>
to show migration version on database and schema -
kmt compare <db1> <db2>
to compare migration from databases -
kmt make <schema> <source> <destination>
to makeschema
ondestination
has same version with thesource
-
kmt test
to test configuration -
kmt upgrade
to upgrade cli -
kmt about
to show version
Run kmt --help
for complete commands
-
Create new project folder
-
Copy Kmtfile.yml below
version: 1.0
migration:
pg_dump: /usr/bin/pg_dump
folder: migrations
source: default
clusters:
local: [local]
connections:
default:
host: default
port: 5432
name: database
user: user
password: s3cret
local:
host: localhost
port: 5432
name: database
user: user
password: s3cret
schemas:
public:
excludes:
- exclude_tables
with_data:
- data_included_tables
user:
excludes:
- exclude_tables
with_data:
- data_included_tables
- Create new migration or generate from
source
- Migrate tables
- Migrate enums (UDT)
- Migrate functions
- Migrate views
- Migrate materialized views
- Show migration version
- Show State/Compare
- Upgrade Command
- Refactor Codes