-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migration adding vcl_rcv config to a table
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"io/ioutil" | ||
|
||
"github.com/jackc/pgx/v5/pgtype" | ||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
type vclRcv struct { | ||
id string | ||
file string | ||
serviceVersionID string | ||
} | ||
|
||
func init() { | ||
goose.AddMigrationContext(upAddVclRcv, downAddVclRcv) | ||
} | ||
|
||
func upAddVclRcv(ctx context.Context, tx *sql.Tx) error { | ||
// This code is executed when the migration is applied. | ||
|
||
vclRcvs := []vclRcv{ | ||
{ | ||
id: "00000000-0000-0000-0000-000000000028", | ||
serviceVersionID: "00000000-0000-0000-0000-000000000015", | ||
file: "testdata/vcl/vcl_rcv/content1.vcl", | ||
}, | ||
} | ||
|
||
for _, vclRcv := range vclRcvs { | ||
var vclID, serviceVersionID pgtype.UUID | ||
err := vclID.Scan(vclRcv.id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = serviceVersionID.Scan(vclRcv.serviceVersionID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
contentBytes, err := ioutil.ReadFile(vclRcv.file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = tx.Exec("INSERT INTO service_vcl_rcv (id, service_version_id, content) VALUES($1, $2, $3)", vclID, serviceVersionID, contentBytes) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func downAddVclRcv(ctx context.Context, tx *sql.Tx) error { | ||
// This code is executed when the migration is rolled back. | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# The usage of the proxy module is possible because haproxy is configured | ||
# to set PROXY SSL headers for us. | ||
if (proxy.is_ssl()) { | ||
std.syslog(180, "vcl_rcv: this is https"); | ||
} else { | ||
std.syslog(180, "vcl_rcv: this is http"); | ||
} |