From 1571ebe4ebc09ba9b8c97d749e7d3033d8f7ea48 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Tue, 27 Jun 2023 00:35:17 +0300 Subject: [PATCH] use microseconds when inserting the auto generated migration --- plugins/migratecmd/automigrate.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/migratecmd/automigrate.go b/plugins/migratecmd/automigrate.go index 3ed31003..6c20eb0a 100644 --- a/plugins/migratecmd/automigrate.go +++ b/plugins/migratecmd/automigrate.go @@ -62,15 +62,16 @@ func (p *plugin) afterCollectionChange() func(*core.ModelEvent) error { action = "updated_" + old.Name } - appliedTime := time.Now().Unix() - name := fmt.Sprintf("%d_%s.%s", appliedTime, action, p.config.TemplateLang) + name := fmt.Sprintf("%d_%s.%s", time.Now().Unix(), action, p.config.TemplateLang) filePath := filepath.Join(p.config.Dir, name) return p.app.Dao().RunInTransaction(func(txDao *daos.Dao) error { // insert the migration entry _, err := txDao.DB().Insert(migrate.DefaultMigrationsTable, dbx.Params{ - "file": name, - "applied": appliedTime, + "file": name, + // use microseconds for more granular applied time in case + // multiple collection changes happens at the ~exact time + "applied": time.Now().UnixMicro(), }).Execute() if err != nil { return err