Skip to content

Commit

Permalink
spice.go: handle empty schema case
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed Aug 26, 2024
1 parent a513fe7 commit 770d447
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions spice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package main
import (
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

"github.com/alecthomas/kong"
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/authzed/authzed-go/v1"
"github.com/authzed/grpcutil"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"
"io"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
)

const MigrationResourceType = "spice_schema_migrations/migration"
Expand Down Expand Up @@ -135,7 +138,7 @@ func getCurrentVersion(ctx context.Context, client *authzed.Client) int {
OptionalLimit: 0,
})
if err != nil {
fmt.Println("could not read relationships")
fmt.Println("could not open relationship stream")
panic(err)
}

Expand All @@ -145,6 +148,11 @@ func getCurrentVersion(ctx context.Context, client *authzed.Client) int {
if err == io.EOF {
return 0
}
if statusErr, ok := status.FromError(err); ok {
if statusErr.Code() == codes.FailedPrecondition && statusErr.Message() == "object definition `spice_schema_migrations/migration` not found" {
return 0
}
}
fmt.Println("could not read relationships")
panic(err)
}
Expand Down

0 comments on commit 770d447

Please sign in to comment.