File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,47 @@ make/photon/prepare/templates/notary/server-config.mysql.json.jinja
321
321
3 . Transfer postgreSQL data model to MariaDB/MySQL data model.
322
322
4 . Write data to MariaDB/MySQL database
323
323
324
+ We define Migrator interface for different type of database to migrate.
325
+ For every data table, for example, here we will migrate data for table Access.
326
+ We define AccessMigrator interface to dump and insert data.
327
+ Then, we will implement Dump() function to read data from PostgreSQL.
328
+ By implement Insert() function. we will transfer data model and insert data model to MySQL.
329
+
330
+ ```
331
+ type Migrator interface {
332
+ Migrate(dbType string) error
333
+ }
334
+
335
+ type AccessMigrator interface {
336
+ Dump() ([]*dao.Access, error)
337
+ Insert([]*dao.Access) error
338
+ }
339
+
340
+ type AccessMigrators map[string]AccessMigrator
341
+
342
+ func (a AccessMigrators) Migrate(dbType string) error {
343
+ data, err := a[dbType].Dump()
344
+ if err != nil {
345
+ log.Error(err)
346
+ return err
347
+ }
348
+ err = a[dbType].Insert(data)
349
+ if err != nil {
350
+ log.Error(err)
351
+ return err
352
+ }
353
+ return nil
354
+ }
355
+
356
+ func (a *Access) Dump() ([]*dao.Access, error) {
357
+ ...
358
+ }
359
+
360
+ func (a *Access) Insert(objs []*dao.Access) error {
361
+ ...
362
+ }
363
+ ```
364
+
324
365
### Database Compatibility Testing
325
366
326
367
** MySQL 8.0**
You can’t perform that action at this time.
0 commit comments