Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e2f749b
Add dumping the entire applied migrations as a second column of schem…
Mar 11, 2025
ce6d66a
Add missing arguments in sql lite testing.
Mar 11, 2025
eb35cf4
Add missing argument handling in sql.
Mar 11, 2025
c757b90
Add recording both up and down migrations in dump column.
Mar 11, 2025
0971260
Add sync command line argument to synchronize existing database.
Mar 11, 2025
3a1201d
Edit few type mistakes.
Mar 11, 2025
a55ec8d
Cut some unused variables.
Mar 11, 2025
57cb532
Edit wrong return value and for loop.
Mar 11, 2025
ba8356b
Cut mistake in for loop over the map.
Mar 11, 2025
1dc390d
Update db.go
Mar 11, 2025
d7c8d02
Edit tests that had errors.
Mar 11, 2025
2905a94
Add two points for create variables.
Mar 11, 2025
de51878
Add missing columns in schema creation of some sql drivers.
Mar 11, 2025
a142429
Add quotes for from version string in query.
Mar 11, 2025
de366c3
Add selecting all with select query from version.
Mar 11, 2025
b9f5796
Add correct creation of new migration schema.
Mar 11, 2025
b423bb9
Cut strict condition.
Mar 11, 2025
1bd4eed
Add UpdateEmptyDump() function.
Mar 12, 2025
ecc0af1
Cut isEmpty function that doesn't exists.
Mar 12, 2025
0d192a1
Edit some mistakes.
Mar 12, 2025
84894be
Cut another mistake.
Mar 12, 2025
4908a89
Add forgotten print log.
Mar 12, 2025
b12155e
Edit a compile error.
Mar 12, 2025
55371bd
Add missing sprintf argumetns.
Mar 12, 2025
ce53c29
Edit error in postgres and sqlite test.
Mar 12, 2025
c0fbc20
Add missing quotes needed in sqlite.
Mar 12, 2025
acdaefe
Cut adding dump column in existing sqlite db because it doesn't work.
Mar 12, 2025
8886960
Update sqlite.go
Mar 12, 2025
7107dd9
Update clickhouse_test.go
Mar 12, 2025
5c21229
Edit sql procedure to add column because it was wrong.
Mar 12, 2025
a721334
Update mysql.go
Mar 12, 2025
9855666
Edit mysql add column if exists that should now work.
Mar 12, 2025
3a76bff
Update mysql.go
Mar 12, 2025
cea6db3
Update mysql.go
Mar 12, 2025
a34d444
Update mysql.go
Mar 12, 2025
634bc05
Update mysql.go
Mar 12, 2025
10eab03
Update mysql.go
Mar 12, 2025
1014657
Update mysql.go
Mar 12, 2025
7859ad1
Update mysql.go
Mar 12, 2025
78d8423
Update mysql.go
Mar 12, 2025
b14a045
Update mysql.go
Mar 12, 2025
0e59417
Update mysql.go
Mar 12, 2025
15591f0
Update mysql.go
Mar 12, 2025
bce2011
Edit version to v1.0.0.
Mar 12, 2025
48c2700
Add migrations-url argument for getting migrations from another datab…
May 21, 2026
023db22
Edit version to v1.0.1.
May 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ dbmate drop # drop the database
dbmate migrate # run any pending migrations
dbmate rollback # roll back the most recent migration
dbmate down # alias for rollback
dbmate sync # sync the database to most recent migration or downgrade the database in case the available file migrations are older
dbmate status # show the status of all migrations (supports --exit-code and --quiet)
dbmate dump # write the database schema.sql file
dbmate load # load schema.sql file to the database
Expand Down
33 changes: 33 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func NewApp() *cli.App {
Value: cli.NewStringSlice(defaultDB.MigrationsDir[0]),
Usage: "specify the directory containing migration files",
},
&cli.StringFlag{
Name: "migrations-url",
EnvVars: []string{"DBMATE_MIGRATIONS_URL"},
Usage: "specify a database URL to read migrations from (sync only). If set, sync reads migrations from this DB instead of filesystem",
},
&cli.StringFlag{
Name: "migrations-table",
EnvVars: []string{"DBMATE_MIGRATIONS_TABLE"},
Expand Down Expand Up @@ -183,6 +188,28 @@ func NewApp() *cli.App {
return db.Rollback()
}),
},
{
Name: "sync",
Usage: "Strips eventual later migrations or migrate up in case the database is older. Uses filesystem migrations by default; if --migrations-url is set, reads migrations from that database.",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
EnvVars: []string{"DBMATE_VERBOSE"},
Usage: "print the result of each statement execution",
},
},
Action: action(func(db *dbmate.DB, c *cli.Context) error {
db.Verbose = c.Bool("verbose")

// check ambiguità
if db.MigrationsUrl != "" && c.IsSet("migrations-dir") {
return fmt.Errorf("cannot use both --migrations-url and --migrations-dir with sync: choose one source")
}

return db.Synchronize()
}),
},
{
Name: "status",
Usage: "List applied and pending migrations",
Expand Down Expand Up @@ -298,10 +325,16 @@ func action(f func(*dbmate.DB, *cli.Context) error) cli.ActionFunc {
db.SchemaFile = c.String("schema-file")
db.WaitBefore = c.Bool("wait")
waitTimeout := c.Duration("wait-timeout")
db.MigrationsUrl = c.String("migrations-url") // ✅ AGGIUNTO

if waitTimeout != 0 {
db.WaitTimeout = waitTimeout
}

if c.String("migrations-url") != "" && c.Command.Name != "sync" {
return fmt.Errorf("--migrations-url is supported only for the sync command")
}

return f(db, c)
}
}
Expand Down
Loading