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

Function GetDBTypeVersionFromString

pkg/ddevapp/db.go:101–146  ·  view source on GitHub ↗

GetDBTypeVersionFromString takes an input string and derives the info from the uses There are 3 possible cases here: 1. It has an _, meaning it's a current MySQL or MariaDB version. Easy to parse. 2. It has N+.N, meaning it's a pre-v1.19 MariaDB or MySQL version 3. It has N+, meaning it's PostgreSQL

(in string)

Source from the content-addressed store, hash-verified

99// 2. It has N+.N, meaning it's a pre-v1.19 MariaDB or MySQL version
100// 3. It has N+, meaning it's PostgreSQL
101func GetDBTypeVersionFromString(in string) string {
102 idType := ""
103
104 postgresStyle := regexp.MustCompile(`^[0-9]+$`)
105 postgresV9Style := regexp.MustCompile(`^9\.?`)
106 oldStyle := regexp.MustCompile(`^[0-9]+\.[0-9]$`)
107 newStyleV119 := regexp.MustCompile(`^(mysql|mariadb)_[0-9]+\.[0-9][0-9]?$`)
108
109 if newStyleV119.MatchString(in) {
110 idType = "current"
111 } else if postgresStyle.MatchString(in) || postgresV9Style.MatchString(in) {
112 idType = "postgres"
113 } else if oldStyle.MatchString(in) {
114 idType = "old_pre_v1.19"
115 }
116
117 dbType := ""
118 dbVersion := ""
119
120 switch idType {
121 case "current": // Current representation, <type>_version
122 res := strings.Split(in, "_")
123 dbType = res[0]
124 dbVersion = res[1]
125
126 // PostgreSQL: value is an int
127 case "postgres":
128 dbType = nodeps.Postgres
129 parts := strings.Split(in, `.`)
130 dbVersion = parts[0]
131
132 case "old_pre_v1.19":
133 dbType = nodeps.MariaDB
134
135 // Both MariaDB and MySQL have 5.5, but we'll give the win to MariaDB here.
136 if in == "5.6" || in == "5.7" || in == "8.0" {
137 dbType = nodeps.MySQL
138 }
139 dbVersion = in
140
141 default: // Punt and assume it's an old default db
142 dbType = nodeps.MariaDB
143 dbVersion = "10.3"
144 }
145 return dbType + ":" + dbVersion
146}
147
148// GetPostgresDataDir returns the correct PostgreSQL data directory path for the given app version
149// PostgreSQL 18+ changed the mount point from /var/lib/postgresql/data to /var/lib/postgresql

Callers 2

GetExistingDBTypeMethod · 0.70

Calls

no outgoing calls

Tested by 1