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

Method getDBVersionFromVolume

pkg/ddevapp/db.go:32–94  ·  view source on GitHub ↗

getDBVersionFromVolume inspects the database volume to determine version info Returns the raw version string found in the volume, or empty string if none found

()

Source from the content-addressed store, hash-verified

30// getDBVersionFromVolume inspects the database volume to determine version info
31// Returns the raw version string found in the volume, or empty string if none found
32func (app *DdevApp) getDBVersionFromVolume() (string, error) {
33 // Command to check for database version files:
34 // 1. MySQL/MariaDB: /var/tmp/mysql/db_mariadb_version.txt
35 // 2. PostgreSQL <=17: /var/tmp/postgres/PG_VERSION
36 // 3. PostgreSQL 18+: /var/tmp/postgres/[version]/docker/PG_VERSION (check common versions)
37 cmd := []string{"sh", "-c", `
38 # Check MySQL/MariaDB version file
39 if [ -f /var/tmp/mysql/db_mariadb_version.txt ]; then
40 cat /var/tmp/mysql/db_mariadb_version.txt
41 exit 0
42 fi
43
44 # Check PostgreSQL version file (pre-18 location)
45 if [ -f /var/tmp/postgres/PG_VERSION ]; then
46 cat /var/tmp/postgres/PG_VERSION
47 exit 0
48 fi
49
50 # Check PostgreSQL 18+ version files in version-specific directories
51 for version_file in /var/tmp/postgres/*/docker/PG_VERSION; do
52 if [ -f "$version_file" ]; then
53 cat "$version_file"
54 exit 0
55 fi
56 done
57
58 # No version file found
59 exit 0
60 `}
61
62 var volumesNeeded []string
63 if dockerutil.VolumeExists(app.GetMariaDBVolumeName()) {
64 volumesNeeded = append(volumesNeeded, app.GetMariaDBVolumeName()+":/var/tmp/mysql")
65 }
66 if dockerutil.VolumeExists(app.GetPostgresVolumeName()) {
67 volumesNeeded = append(volumesNeeded, app.GetPostgresVolumeName()+":/var/tmp/postgres")
68 }
69 // No database volumesNeeded exist
70 if len(volumesNeeded) == 0 {
71 return "", nil
72 }
73
74 _, out, err := dockerutil.RunSimpleContainer(
75 versionconstants.UtilitiesImage,
76 "GetExistingDBType-"+app.Name+"-"+util.RandString(6),
77 cmd,
78 []string{}, // envVars
79 []string{}, // uid
80 volumesNeeded,
81 "", // workingDir
82 true, // rm
83 false, // detach
84 map[string]string{`com.ddev.site-name`: ""}, // labels
85 nil, // networks
86 nil, // healthcheck
87 )
88
89 if err != nil {

Callers 1

GetExistingDBTypeMethod · 0.95

Calls 6

GetMariaDBVolumeNameMethod · 0.95
GetPostgresVolumeNameMethod · 0.95
VolumeExistsFunction · 0.92
RunSimpleContainerFunction · 0.92
RandStringFunction · 0.92
FailedFunction · 0.92

Tested by

no test coverage detected