8000 Merge pull request #322 from symfony-cli/relax-db-checks · glengemann/symfony-cli@fdc6a3c · GitHub
[go: up one dir, main page]

Skip to content

Commit fdc6a3c

Browse files
authored
Merge pull request symfony-cli#322 from symfony-cli/relax-db-checks
Relax DB check
2 parents 535b326 + f8b5337 commit fdc6a3c

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

commands/db_versions.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ func readDBVersionFromDotEnv(projectDir string) (string, error) {
5454
return "", err
5555
}
5656

57-
databaseUrl, defined := vars["DATABASE_URL"]
57+
databaseURL, defined := vars["DATABASE_URL"]
5858
if !defined {
5959
return "", nil
6060
}
6161

62-
if !strings.Contains(databaseUrl, "serverVersion=") {
62+
if !strings.Contains(databaseURL, "serverVersion=") {
6363
return "", nil
6464
}
6565

66-
url, err := url.Parse(databaseUrl)
66+
url, err := url.Parse(databaseURL)
6767
if err != nil {
6868
return "", err
6969
}
@@ -95,3 +95,9 @@ func readDBVersionFromDoctrineConfigYAML(projectDir string) (string, error) {
9595
}
9696
return doctrineConfig.Doctrine.Dbal.ServerVersion, nil
9797
}
98+
99+
func databaseVersiondUnsynced(providedVersion, dbVersion string) bool {
100+
providedVersion = strings.Replace(providedVersion, "mariadb-", "", 1)
101+
102+
return providedVersion != "" && !strings.HasPrefix(providedVersion, dbVersion)
103+
}

commands/platformsh_hooks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var platformshBeforeHooks = map[string]console.BeforeFunc{
3535
if err != nil {
3636
return err
3737
}
38+
3839
if len(platformsh.FindLocalApplications(projectDir)) > 1 {
3940
// not implemented yet as more complex
4041
return nil
@@ -61,16 +62,15 @@ Before deploying, fix the version mismatch.
6162
if err != nil {
6263
return nil
6364
}
64-
if dotEnvVersion != "" && dotEnvVersion != dbVersion {
65+
if databaseVersiondUnsynced(dotEnvVersion, dbVersion) {
6566
return fmt.Errorf(errorTpl, fmt.Sprintf("the \".env\" file requires version %s", dotEnvVersion))
6667
}
6768

6869
doctrineConfigVersion, err := readDBVersionFromDoctrineConfigYAML(projectDir)
6970
if err != nil {
70-
fmt.Printf("%+v", err)
7171
return nil
7272
}
73-
if doctrineConfigVersion != "" && doctrineConfigVersion != dbVersion {
73+
if databaseVersiondUnsynced(doctrineConfigVersion, dbVersion) {
7474
return fmt.Errorf(errorTpl, fmt.Sprintf("the \"config/packages/doctrine.yaml\" file requires version %s", doctrineConfigVersion))
7575
}
7676

commands/platformsh_hooks_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestDeployHook(t *testing.T) {
3636
"testdata/platformsh/version-mismatch-env/": `The ".platform/services.yaml" file defines a "postgresql" version 14 database service but the ".env" file requires version 13.`,
3737
"testdata/platformsh/version-mismatch-config/": `The ".platform/services.yaml" file defines a "postgresql" version 14 database service but the "config/packages/doctrine.yaml" file requires version 13.`,
3838
"testdata/platformsh/ok/": ``,
39+
"testdata/platformsh/mariadb-version/": ``,
3940
"testdata/platformsh/missing-version/": `Set the "server_version" parameter to "14" in "config/packages/doctrine.yaml".`,
4041
} {
4142
flags.Set("dir", dir)
@@ -47,6 +48,9 @@ func TestDeployHook(t *testing.T) {
4748
continue
4849
}
4950
errString := strings.ReplaceAll(err.Error(), "\n", " ")
51+
if expected == "" {
52+
t.Errorf("TestDeployHook(%q): got %s, expected no errors", dir, errString)
53+
}
5054
if !strings.Contains(errString, expected) {
5155
t.Errorf("TestDeployHook(%q): got %s, expected %s", dir, errString, expected)
5256
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
###> doctrine/doctrine-bundle ###
2+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
3+
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
4+
#
5+
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
6+
# DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7"
7+
DATABASE_URL="postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=mariadb-10.6.12&charset=utf8"
8+
###< doctrine/doctrine-bundle ###
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: app
2+
3+
type: php:8.2
4+
5+
relationships:
6+
database: "mysqldb:mysql"
7+
8+
web:
9+
locations:
10+
"/":
11+
root: "public"
12+
expires: 1d
13+
passthru: "/index.php"
14+
15+
disk: 8192
16+
17+
hooks:
18+
build: |
19+
set -x -e
20+
21+
curl -s https://get.symfony.com/cloud/configurator | bash
22+
symfony-build
23+
24+
deploy: |
25+
set -x -e
26+
27+
symfony-deploy
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mysqldb:
2+
type: mysql:10.6
3+
disk: 512
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
doctrine:
22
dbal:
33
driver: pdo_pgsql
4-
server_version: '13'
4+
server_version: '14'
55
url: '%env(resolve:DATABASE_URL)%'

0 commit comments

Comments
 (0)
0