use microseconds when inserting the auto generated migration

This commit is contained in:
Gani Georgiev 2023-06-27 00:35:17 +03:00
parent b8bb5e8d72
commit 1571ebe4eb
1 changed files with 5 additions and 4 deletions

View File

@ -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,
// 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