-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Adapter interface to include function to return adapter name #345
Comments
could you give examples? and is the database type specific code will be in sql package? |
no it's for usage in user code later on, for one I would want this to use in migrator package for such code to be able to lock down migrations so that if multiple instances are started at same time (for example in containers) they would not run same migrations: if m.typ == DatabaseSQLite3 {
if err := m.sync(ctx); err != nil {
cancelUpdate(err)
}
return func(ctx context.Context, vers int64) {
if vers == 0 {
return
}
if err := m.repo.Insert(ctx, &version{Version: vers}); err != nil {
cancelUpdate(err)
}
}, func() {}
}
updZeroVersion := "INSERT INTO versions(version, created_at) VALUES (0, current_timestamp) ON CONFLICT(version) DO UPDATE SET updated_at = current_timestamp"
if m.typ == DatabaseMySQL {
updZeroVersion = "INSERT INTO versions(version, created_at) VALUES (0, current_timestamp) ON DUPLICATE KEY UPDATE updated_at = current_timestamp"
} currently because of that I have to copy over migrator code and can not really implement it upstream as instead of go-rel/migration package: https://github.com/go-rel/migration/blob/dbef2632dc4efecbb107b4c61648a0d0d255c0ac/migration.go#L170 // New migratorr.
func New(typ string, repo rel.Repository) *Migrator {
return &Migrator{
typ: typ,
repo: repo,
}
} instead I could use for db specific code something like |
got it, I think it's should be okay to add some metadata information like this I prefer |
Ok, I will create PR |
@Fs02 please review: If naming/implementation looks good I will create PRs for other adapters |
@lafriks need to be updated too |
Would be useful to allow check what adapter is used currently so that database type specific code could be executed only on right adapters.
or
that would return
mysql
,postgres
,sqlite3
etcThe text was updated successfully, but these errors were encountered: