-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2b7ad3
commit c2fca12
Showing
12 changed files
with
458 additions
and
18 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
45 changes: 45 additions & 0 deletions
45
pkg/repository/backend_postgres_migrations/020_add_shell_stub_type.go
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,45 @@ | ||
package backend_postgres_migrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(upAddShellStubType, downRemoveShellStubType) | ||
} | ||
|
||
func upAddShellStubType(ctx context.Context, tx *sql.Tx) error { | ||
newStubTypes := []string{"schedule/shell", "asgi/shell", "endpoint/shell", "taskqueue/shell", "function/shell"} | ||
|
||
for _, stubType := range newStubTypes { | ||
addEnumSQL := fmt.Sprintf(` | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_type t | ||
JOIN pg_enum e ON t.oid = e.enumtypid | ||
JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace | ||
WHERE n.nspname = 'public' AND t.typname = 'stub_type' AND e.enumlabel = '%s' | ||
) THEN | ||
EXECUTE 'ALTER TYPE stub_type ADD VALUE ' || quote_literal('%s'); | ||
END IF; | ||
END | ||
$$;`, stubType, stubType) | ||
|
||
if _, err := tx.Exec(addEnumSQL); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func downRemoveShellStubType(ctx context.Context, tx *sql.Tx) error { | ||
// PostgreSQL doesn't support removing values from an ENUM directly | ||
// hi | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.