MCPcopy Create free account
hub / github.com/ddev/ddev / TestDebugMigrateDatabase

Function TestDebugMigrateDatabase

cmd/ddev/cmd/debug-migrate-database_test.go:17–92  ·  view source on GitHub ↗

TestDebugMigrateDatabase checks to see if we can migrate database

(t *testing.T)

Source from the content-addressed store, hash-verified

15
16// TestDebugMigrateDatabase checks to see if we can migrate database
17func TestDebugMigrateDatabase(t *testing.T) {
18 origDir, _ := os.Getwd()
19
20 site := TestSites[0]
21 _ = os.Chdir(site.Dir)
22
23 app, err := ddevapp.NewApp(site.Dir, false)
24 require.NoError(t, err)
25
26 // Remove existing
27 err = app.Stop(true, false)
28 require.NoError(t, err)
29
30 // Use notorious mariadb:11.8 as source and notorious mysql:8.4 as target
31 app.Database.Type = nodeps.MariaDB
32 app.Database.Version = nodeps.MariaDB118
33
34 t.Cleanup(func() {
35 out, err := exec.RunHostCommand(DdevBin, "utility", "migrate-database", fmt.Sprintf("%s:%s", nodeps.MariaDB, nodeps.MariaDBDefaultVersion))
36 require.NoError(t, err, "failed to migrate database; out='%s'", out)
37
38 require.Contains(t, out, fmt.Sprintf("Database was converted to %s:%s", nodeps.MariaDB, nodeps.MariaDBDefaultVersion))
39
40 out, stderr, err := app.Exec(&ddevapp.ExecOpts{
41 Service: "db",
42 Cmd: fmt.Sprintf(`%s -e 'DROP TABLE IF EXISTS %s;'`, app.GetDBClientCommand(), t.Name()),
43 })
44 require.NoError(t, err, "DROP table didn't work, out='%s', stderr='%s'", out, stderr)
45 _ = os.Chdir(origDir)
46 })
47
48 err = app.Start()
49 require.NoError(t, err)
50
51 out, _, err := app.Exec(&ddevapp.ExecOpts{
52 Service: "db",
53 Cmd: fmt.Sprintf(`%s -N -e 'SELECT VERSION();'`, app.GetDBClientCommand()),
54 })
55 require.NoError(t, err)
56 // It should have our default version
57 require.True(t, strings.HasPrefix(out, nodeps.MariaDB118))
58
59 // Import a database so we have something to work with
60 err = app.ImportDB(filepath.Join(origDir, "testdata", t.Name(), "users.sql"), "", false, false, "")
61 require.NoError(t, err)
62
63 _, _, err = app.Exec(&ddevapp.ExecOpts{
64 Service: "db",
65 Cmd: fmt.Sprintf(`%s -e 'CREATE TABLE IF NOT EXISTS example_table (name VARCHAR(255) NOT NULL); INSERT INTO example_table (name) VALUES ("%s");'`, app.GetDBClientCommand(), t.Name()),
66 })
67 require.NoError(t, err)
68
69 // Try a migration
70 out, err = exec.RunHostCommand(DdevBin, "utility", "migrate-database", fmt.Sprintf("%s:%s", nodeps.MySQL, nodeps.MySQL84))
71 require.NoError(t, err, "failed to migrate database; out='%s'", out)
72 require.Contains(t, out, fmt.Sprintf("Database was converted to %s:%s", nodeps.MySQL, nodeps.MySQL84))
73
74 _, err = app.ReadConfig(true)

Callers

nothing calls this directly

Calls 10

NewAppFunction · 0.92
RunHostCommandFunction · 0.92
ChdirMethod · 0.80
StopMethod · 0.80
CleanupMethod · 0.80
ExecMethod · 0.80
GetDBClientCommandMethod · 0.80
StartMethod · 0.80
ImportDBMethod · 0.80
ReadConfigMethod · 0.65

Tested by

no test coverage detected