github.com/team-ide/go-dialect@v1.9.20/test/task_test.go (about)

     1  package test
     2  
     3  //func TestMysqlSyncMysql(t *testing.T) {
     4  //	initMysql()
     5  //	task := worker.NewTaskSync(MysqlDb, MysqlDialect, MysqlDb, MysqlDialect, func(ownerName string) (db *sql.DB, err error) {
     6  //
     7  //		return
     8  //	},
     9  //		&worker.TaskSyncParam{
    10  //			Owners: []*worker.TaskSyncOwner{
    11  //				{SourceName: "information_schema", TargetName: "XXX1"},
    12  //				{SourceName: "mysql", TargetName: "XXX2"},
    13  //				{SourceName: "performance_schema", TargetName: "XXX3"},
    14  //			},
    15  //			SyncStruct: true,
    16  //			SyncData:   true,
    17  //			//FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
    18  //			//	return tableName + "_" + index.Name
    19  //			//},
    20  //		})
    21  //	err := task.Start()
    22  //	if err != nil {
    23  //		panic(err)
    24  //	}
    25  //	bs, _ := json.Marshal(task)
    26  //	println(string(bs))
    27  //}
    28  //
    29  //func TestMysqlSyncSqlite(t *testing.T) {
    30  //	initMysql()
    31  //	initSqlite()
    32  //	task := worker.NewTaskSync(MysqlDb, MysqlDialect, SqliteDb, SqliteDialect, func(ownerName string) (db *sql.DB, err error) {
    33  //
    34  //		return
    35  //	},
    36  //		&worker.TaskSyncParam{
    37  //			Owners: []*worker.TaskSyncOwner{
    38  //				{SourceName: "mysql", TargetName: "main"},
    39  //			},
    40  //			SyncStruct: true,
    41  //			SyncData:   true,
    42  //			FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
    43  //				return tableName + "_" + index.Name
    44  //			},
    45  //		})
    46  //	err := task.Start()
    47  //	if err != nil {
    48  //		panic(err)
    49  //	}
    50  //	bs, _ := json.Marshal(task)
    51  //	println(string(bs))
    52  //}
    53  //
    54  //func TestMysqlExportSql(t *testing.T) {
    55  //	initMysql()
    56  //	_, _ = worker.DoExec(MysqlDb, []string{"set global show_compatibility_56=on"})
    57  //	owners := []*worker.TaskExportOwner{
    58  //		//{SourceName: "information_schema", TargetName: "main"},
    59  //		{SourceName: "mysql", TargetName: "main"},
    60  //		//{SourceName: "performance_schema", TargetName: "main"},
    61  //	}
    62  //	exportSql(MysqlDb, MysqlDialect, dialect.Sqlite, owners)
    63  //}
    64  //func TestMysqlImportSql(t *testing.T) {
    65  //	initMysql()
    66  //	owners := []*worker.TaskImportOwner{
    67  //		{Name: "information_schema", Path: "temp/export/XXX1.sql"},
    68  //		{Name: "mysql", Path: "temp/export/XXX2.sql"},
    69  //		{Name: "performance_schema", Path: "temp/export/XXX3.sql"},
    70  //	}
    71  //	importSql(MysqlDb, MysqlDialect, owners)
    72  //}
    73  //func TestSqliteImportSql(t *testing.T) {
    74  //	initSqlite()
    75  //	owners := []*worker.TaskImportOwner{
    76  //		{Name: "main", Path: "temp/export/main.sql"},
    77  //	}
    78  //	importSql(SqliteDb, dialect.Sqlite, owners)
    79  //}
    80  //func TestMysqlExportStructure(t *testing.T) {
    81  //	initMysql()
    82  //	task := worker.NewTaskExport(MysqlDb, MysqlDialect, MysqlDialect, &worker.TaskExportParam{
    83  //		Owners: []*worker.TaskExportOwner{
    84  //			{SourceName: "information_schema", TargetName: "XXX1"},
    85  //			{SourceName: "mysql", TargetName: "XXX2"},
    86  //			{SourceName: "performance_schema", TargetName: "XXX3"},
    87  //		},
    88  //		ExportStructure: true,
    89  //		//ExportData:      true,
    90  //		Dir:            "temp/export",
    91  //		ExportBatchSql: true,
    92  //		//FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
    93  //		//	return tableName + "_" + index.Name
    94  //		//},
    95  //
    96  //		DataSourceType: worker.DataSourceTypeSql,
    97  //	})
    98  //	err := task.Start()
    99  //	if err != nil {
   100  //		panic(err)
   101  //	}
   102  //	bs, _ := json.Marshal(task)
   103  //	println(string(bs))
   104  //}
   105  //func TestMysqlImportStructure(t *testing.T) {
   106  //	initMysql()
   107  //	task := worker.NewTaskImport(MysqlDb, MysqlDialect, &worker.TaskImportParam{
   108  //		Owners: []*worker.TaskImportOwner{
   109  //			{Name: "XXX1", Path: "temp/export/XXX1.sql"},
   110  //			{Name: "XXX2", Path: "temp/export/XXX2.sql"},
   111  //			{Name: "XXX3", Path: "temp/export/XXX3.sql"},
   112  //		},
   113  //		//FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
   114  //		//	return tableName + "_" + index.Name
   115  //		//},
   116  //		DataSourceType: worker.DataSourceTypeSql,
   117  //	})
   118  //	err := task.Start()
   119  //	if err != nil {
   120  //		panic(err)
   121  //	}
   122  //	bs, _ := json.Marshal(task)
   123  //	println(string(bs))
   124  //}
   125  //func TestMysqlExportData(t *testing.T) {
   126  //	initMysql()
   127  //	task := worker.NewTaskExport(MysqlDb, MysqlDialect, MysqlDialect, &worker.TaskExportParam{
   128  //		Owners: []*worker.TaskExportOwner{
   129  //			{SourceName: "information_schema", TargetName: "XXX1"},
   130  //			{SourceName: "mysql", TargetName: "XXX2"},
   131  //			{SourceName: "performance_schema", TargetName: "XXX3"},
   132  //		},
   133  //		ExportStructure: true,
   134  //		ExportData:      true,
   135  //		Dir:             "temp/export",
   136  //		ExportBatchSql:  true,
   137  //		//FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
   138  //		//	return tableName + "_" + index.Name
   139  //		//},
   140  //		DataSourceType: worker.DataSourceTypeExcel,
   141  //	})
   142  //	err := task.Start()
   143  //	if err != nil {
   144  //		panic(err)
   145  //	}
   146  //	bs, _ := json.Marshal(task)
   147  //	println(string(bs))
   148  //}
   149  //
   150  //func TestMysqlImportData(t *testing.T) {
   151  //	initMysql()
   152  //	task := worker.NewTaskImport(MysqlDb, MysqlDialect, &worker.TaskImportParam{
   153  //		Owners: []*worker.TaskImportOwner{
   154  //			{Name: "XXX1", Dir: "temp/export/XXX1"},
   155  //			{Name: "XXX2", Dir: "temp/export/XXX2"},
   156  //			{Name: "XXX3", Dir: "temp/export/XXX3"},
   157  //		},
   158  //		//FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
   159  //		//	return tableName + "_" + index.Name
   160  //		//},
   161  //		DataSourceType: worker.DataSourceTypeExcel,
   162  //	})
   163  //	err := task.Start()
   164  //	if err != nil {
   165  //		panic(err)
   166  //	}
   167  //	bs, _ := json.Marshal(task)
   168  //	println(string(bs))
   169  //}
   170  //
   171  //func exportSql(db *sql.DB, dia dialect.Dialect, targetDia dialect.Dialect, owners []*worker.TaskExportOwner) {
   172  //	task := worker.NewTaskExport(db, dia, targetDia, &worker.TaskExportParam{
   173  //		Owners:          owners,
   174  //		ExportStructure: true,
   175  //		ExportData:      true,
   176  //		Dir:             "temp/export",
   177  //		ExportBatchSql:  true,
   178  //		FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
   179  //			return tableName + "_" + index.Name
   180  //		},
   181  //		DataSourceType: worker.DataSourceTypeSql,
   182  //	})
   183  //	err := task.Start()
   184  //	if err != nil {
   185  //		panic(err)
   186  //	}
   187  //	bs, _ := json.Marshal(task)
   188  //	println(string(bs))
   189  //	time.Sleep(1 * time.Second)
   190  //}
   191  //func importSql(db *sql.DB, dia dialect.Dialect, owners []*worker.TaskImportOwner) {
   192  //	task := worker.NewTaskImport(db, dia, &worker.TaskImportParam{
   193  //		Owners: owners,
   194  //		FormatIndexName: func(ownerName string, tableName string, index *dialect.IndexModel) string {
   195  //			return tableName + "_" + index.Name
   196  //		},
   197  //		DataSourceType: worker.DataSourceTypeSql,
   198  //	})
   199  //	err := task.Start()
   200  //	if err != nil {
   201  //		panic(err)
   202  //	}
   203  //	bs, _ := json.Marshal(task)
   204  //	println(string(bs))
   205  //	time.Sleep(1 * time.Second)
   206  //}