Skip to content

Commit

Permalink
feat(seed): set a default tenant ID
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Dec 21, 2023
1 parent 806dae5 commit e0853d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
)

var DefaultTenantID = "f790792c-cd0f-4304-91f3-3cb91feb019c"

func main() {
// init the repository
cf := &loader.ConfigLoader{}
Expand Down Expand Up @@ -54,6 +56,7 @@ func main() {
// seed an example tenant
// initialize a tenant
tenant, err = dc.Repository.Tenant().CreateTenant(&repository.CreateTenantOpts{
ID: &DefaultTenantID,
Name: "Default",
Slug: "default",
})
Expand Down
1 change: 1 addition & 0 deletions internal/config/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ClientConfig struct {
}

func BindAllEnv(v *viper.Viper) {
v.SetDefault("tenantId", "f790792c-cd0f-4304-91f3-3cb91feb019c")
v.BindEnv("tenantId", "HATCHET_CLIENT_TENANT_ID")

// tls options
Expand Down
1 change: 1 addition & 0 deletions internal/repository/prisma/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (r *tenantRepository) CreateTenant(opts *repository.CreateTenantOpts) (*db.
return r.client.Tenant.CreateOne(
db.Tenant.Name.Set(opts.Name),
db.Tenant.Slug.Set(opts.Slug),
db.Tenant.ID.SetIfPresent(opts.ID),
).Exec(context.Background())
}

Expand Down
3 changes: 3 additions & 0 deletions internal/repository/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ type CreateTenantOpts struct {

// (required) the tenant slug
Slug string `validate:"required,hatchetName"`

// (optional) the tenant name
ID *string
}

type CreateTenantMemberOpts struct {
Expand Down

0 comments on commit e0853d4

Please sign in to comment.