Skip to content

Commit

Permalink
feat: enrich migrate tool desigin (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyang Huang <huangyiyang.huangyy@bytedance.com>

Signed-off-by: Yiyang Huang <huangyiyang.huangyy@bytedance.com>
  • Loading branch information
hyy0322 authored Dec 14, 2022
1 parent 167c450 commit 47e3f25
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions proposals/adapt_multiple_type_of_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,47 @@ make/photon/prepare/templates/notary/server-config.mysql.json.jinja
3. Transfer postgreSQL data model to MariaDB/MySQL data model.
4. Write data to MariaDB/MySQL database

We define Migrator interface for different type of database to migrate.
For every data table, for example, here we will migrate data for table Access.
We define AccessMigrator interface to dump and insert data.
Then, we will implement Dump() function to read data from PostgreSQL.
By implement Insert() function. we will transfer data model and insert data model to MySQL.

```
type Migrator interface {
Migrate(dbType string) error
}
type AccessMigrator interface {
Dump() ([]*dao.Access, error)
Insert([]*dao.Access) error
}
type AccessMigrators map[string]AccessMigrator
func (a AccessMigrators) Migrate(dbType string) error {
data, err := a[dbType].Dump()
if err != nil {
log.Error(err)
return err
}
err = a[dbType].Insert(data)
if err != nil {
log.Error(err)
return err
}
return nil
}
func (a *Access) Dump() ([]*dao.Access, error) {
...
}
func (a *Access) Insert(objs []*dao.Access) error {
...
}
```

### Database Compatibility Testing

**MySQL 8.0**
Expand Down

0 comments on commit 47e3f25

Please sign in to comment.