Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds a flag for specifying the db name for migrations #185

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
corsAllowOriginsFlag = "cors-allow-origins"
corsAllowCredentialsFlag = "cors-allow-credentials" //nolint: gosec
clamavServerFlag = "clamav-server"
hasuraDbNameFlag = "hasura-db-name"
)

func ginLogger(logger *logrus.Logger) gin.HandlerFunc {
Expand Down Expand Up @@ -158,6 +159,7 @@ func applymigrations(
hasuraMetadata bool,
hasuraEndpoint string,
hasuraSecret string,
hasuraDbName string,
logger *logrus.Logger,
) {
if postgresMigrations {
Expand All @@ -174,7 +176,7 @@ func applymigrations(

if hasuraMetadata {
logger.Info("applying hasura metadata")
if err := migrations.ApplyHasuraMetadata(hasuraEndpoint, hasuraSecret); err != nil {
if err := migrations.ApplyHasuraMetadata(hasuraEndpoint, hasuraSecret, hasuraDbName); err != nil {
logger.Errorf("problem applying hasura metadata: %s", err.Error())
os.Exit(1)
}
Expand Down Expand Up @@ -222,6 +224,7 @@ func init() {
"",
"postgres connection, i.e. postgres://user@pass:localhost:5432/mydb",
)
addStringFlag(serveCmd.Flags(), hasuraDbNameFlag, "default", "Hasura database name")
}

{
Expand Down Expand Up @@ -275,6 +278,7 @@ var serveCmd = &cobra.Command{
s3BucketFlag: viper.GetString(s3BucketFlag),
s3RootFolderFlag: viper.GetString(s3RootFolderFlag),
clamavServerFlag: viper.GetString(clamavServerFlag),
hasuraDbNameFlag: viper.GetString(hasuraDbNameFlag),
},
).Debug("parameters")

Expand All @@ -294,6 +298,7 @@ var serveCmd = &cobra.Command{
viper.GetBool(hasuraMetadataFlag),
viper.GetString(hasuraEndpointFlag),
viper.GetString(hasuraAdminSecretFlag),
viper.GetString(hasuraDbNameFlag),
logger,
)

Expand Down
14 changes: 7 additions & 7 deletions migrations/hasura.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ type DropRelationshipArgs struct {
Relationship string `json:"relationship"`
}

func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
func ApplyHasuraMetadata(url, hasuraSecret, hasuraDbName string) error { //nolint: funlen
bucketsTable := TrackTable{
Type: "pg_track_table",
Args: PgTrackTableArgs{
Source: "default",
Source: hasuraDbName,
Table: Table{
Schema: "storage",
Name: "buckets",
Expand Down Expand Up @@ -185,7 +185,7 @@ func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
filesTable := TrackTable{
Type: "pg_track_table",
Args: PgTrackTableArgs{
Source: "default",
Source: hasuraDbName,
Table: Table{
Schema: "storage",
Name: "files",
Expand Down Expand Up @@ -227,7 +227,7 @@ func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
virusTable := TrackTable{
Type: "pg_track_table",
Args: PgTrackTableArgs{
Source: "default",
Source: hasuraDbName,
Table: Table{
Schema: "storage",
Name: "virus",
Expand Down Expand Up @@ -270,7 +270,7 @@ func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
Name: "files",
},
Name: "bucket",
Source: "default",
Source: hasuraDbName,
Using: CreateObjectRelationshipUsing{
ForeignKeyConstraintOn: []string{"bucket_id"},
},
Expand All @@ -289,7 +289,7 @@ func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
Name: "buckets",
},
Name: "files",
Source: "default",
Source: hasuraDbName,
Using: CreateArrayRelationshipUsing{
ForeignKeyConstraintOn: ForeignKeyConstraintOn{
Table: Table{
Expand All @@ -314,7 +314,7 @@ func ApplyHasuraMetadata(url, hasuraSecret string) error { //nolint: funlen
Name: "virus",
},
Name: "file",
Source: "default",
Source: hasuraDbName,
Using: CreateObjectRelationshipUsing{
ForeignKeyConstraintOn: []string{"file_id"},
},
Expand Down
Loading