8000 Simulate a fake DB for psh build hook · symfony-cli/symfony-cli@6f4420d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f4420d

Browse files
committed
Simulate a fake DB for psh build hook
1 parent e8c822f commit 6f4420d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

envs/remote.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,25 @@ func (r *Remote) Relationships() Relationships {
5555
if r.Debug {
5656
fmt.Fprint(os.Stderr, "PLATFORM_RELATIONSHIPS env var does not exist\n")
5757
}
58-
return nil
58+
59+
// during the build hook, force a database version to avoid having Doctrine
60+
// trying to connect to the DB to guess it (as the DB is not available yet).
61+
res := make(Relationships)
62+
res["database"] = []map[string]interface{}{{
63+
"host": "127.0.0.1",
64+
"ip": "127.0.0.1",
65+
"username": "fake-dsn-for-build-hook",
66+
"password": "as-db-is-never-available-yet",
67+
"path": "nowhere",
68+
"port": "3306",
69+
"query": map[string]bool{
70+
"is_master": true,
71+
},
72+
"rel": "mysql",
73+
"scheme": "mysql",
74+
"type": "mysql:1337",
75+
}}
76+
return res
5977
}
6078

6179
var err error

envs/remote_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,20 @@ func (s *RemoteSuite) TestDefaultRoute(c *C) {
256256

257257
func (s *RemoteSuite) TestRelationships(c *C) {
258258
r := &Remote{}
259-
c.Assert(extractRelationshipsEnvs(r), DeepEquals, Envs{})
259+
// build hook on psh
260+
c.Assert(extractRelationshipsEnvs(r), DeepEquals, Envs{
261+
"DATABASE_DATABASE": "nowhere",
262+
"DATABASE_DRIVER": "mysql",
263+
"DATABASE_HOST": "127.0.0.1",
264+
"DATABASE_NAME": "nowhere",
265+
"DATABASE_PASSWORD": "as-db-is-never-available-yet",
266+
"DATABASE_PORT": "3306",
267+
"DATABASE_SERVER": "mysql://127.0.0.1:3306",
268+
"DATABASE_URL": "mysql://fake-dsn-for-build-hook:as-db-is-never-available-yet@127.0.0.1:3306/nowhere?sslmode=disable&charset=utf8mb4&serverVersion=mariadb-1337.0",
269+
"DATABASE_USER": "fake-dsn-for-build-hook",
270+
"DATABASE_USERNAME": "fake-dsn-for-build-hook",
271+
"DATABASE_VERSION": "mariadb-1337.0",
272+
})
260273

261274
os.Setenv("PLATFORM_RELATIONSHIPS", "eyJzZWN1cml0eS1zZXJ2ZXIiOiBbeyJpcCI6ICIxNjkuMjU0LjI2LjIzMSIsICJob3N0IjogInNlY3VyaXR5LXNlcnZlci5pbnRlcm5hbCIsICJzY2hlbWUiOiAiaHR0cCIsICJwb3J0IjogODAsICJyZWwiOiAiaHR0cCJ9XSwgImRhdGFiYXNlIjogW3sidXNlcm5hbWUiOiAibWFpbiIsICJzY2hlbWUiOiAicGdzcWwiLCAiaXAiOiAiMTY5LjI1NC4xMjAuNDgiLCAiaG9zdCI6ICJkYXRhYmFzZS5pbnRlcm5hbCIsICJyZWwiOiAicG9zdGdyZXNxbCIsICJwYXRoIjogIm1haW4iLCAicXVlcnkiOiB7ImlzX21hc3RlciI6IHRydWV9LCAicGFzc3dvcmQiOiAibWFpbiIsICJwb3J0IjogNTQzMn1dfQ==")
262275
c.Assert(extractRelationshipsEnvs(r), DeepEquals, Envs{

0 commit comments

Comments
 (0)
0