Skip to content
Draft
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
2 changes: 2 additions & 0 deletions admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ type Deployment struct {
Environment string `db:"environment"`
Branch string `db:"branch"`
Editable bool `db:"editable"`
ReadOnlyModels bool `db:"read_only_models"`
RuntimeHost string `db:"runtime_host"`
RuntimeInstanceID string `db:"runtime_instance_id"`
RuntimeAudience string `db:"runtime_audience"`
Expand All @@ -639,6 +640,7 @@ type InsertDeploymentOptions struct {
Environment string
Branch string
Editable bool
ReadOnlyModels bool
RuntimeHost string
RuntimeInstanceID string
RuntimeAudience string
Expand Down
1 change: 1 addition & 0 deletions admin/database/postgres/migrations/0096.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE deployments ADD COLUMN read_only_models BOOLEAN DEFAULT FALSE;
6 changes: 3 additions & 3 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,9 @@ func (c *connection) InsertDeployment(ctx context.Context, opts *database.Insert

res := &database.Deployment{}
err := c.getDB(ctx).QueryRowxContext(ctx, `
INSERT INTO deployments (project_id, owner_user_id, environment, branch, editable, runtime_host, runtime_instance_id, runtime_audience, status, status_message, desired_status, desired_status_updated_on)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, now()) RETURNING *`,
opts.ProjectID, opts.OwnerUserID, opts.Environment, opts.Branch, opts.Editable, opts.RuntimeHost, opts.RuntimeInstanceID, opts.RuntimeAudience, opts.Status, opts.StatusMessage, opts.DesiredStatus,
INSERT INTO deployments (project_id, owner_user_id, environment, branch, editable, read_only_models, runtime_host, runtime_instance_id, runtime_audience, status, status_message, desired_status, desired_status_updated_on)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, now()) RETURNING *`,
opts.ProjectID, opts.OwnerUserID, opts.Environment, opts.Branch, opts.Editable, opts.ReadOnlyModels, opts.RuntimeHost, opts.RuntimeInstanceID, opts.RuntimeAudience, opts.Status, opts.StatusMessage, opts.DesiredStatus,
).StructScan(res)
if err != nil {
return nil, parseErr("deployment", err)
Expand Down
12 changes: 7 additions & 5 deletions admin/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (
var ErrDeploymentNotReady = errors.New("deployment not ready")

type CreateDeploymentOptions struct {
ProjectID string
OwnerUserID *string
Environment string
Branch string
Editable bool
ProjectID string
OwnerUserID *string
Environment string
Branch string
Editable bool
ReadOnlyModels bool
}

func (s *Service) CreateDeployment(ctx context.Context, opts *CreateDeploymentOptions) (*database.Deployment, error) {
Expand All @@ -42,6 +43,7 @@ func (s *Service) CreateDeployment(ctx context.Context, opts *CreateDeploymentOp
Environment: opts.Environment,
Branch: opts.Branch,
Editable: opts.Editable,
ReadOnlyModels: opts.ReadOnlyModels,
RuntimeHost: "", // Will be populated after provisioning in startDeploymentInner
RuntimeInstanceID: "", // Will be populated after provisioning in startDeploymentInner
RuntimeAudience: "", // Will be populated after provisioning in startDeploymentInner
Expand Down
28 changes: 16 additions & 12 deletions admin/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func (s *Service) CreateProject(ctx context.Context, org *database.Organization,
// Provision prod deployment.
// Start using original context again since transaction in txCtx is done.
depl, err := s.CreateDeployment(ctx, &CreateDeploymentOptions{
ProjectID: proj.ID,
OwnerUserID: nil,
Environment: "prod",
Branch: proj.PrimaryBranch,
Editable: false,
ProjectID: proj.ID,
OwnerUserID: nil,
Environment: "prod",
Branch: proj.PrimaryBranch,
Editable: false,
ReadOnlyModels: false,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -336,21 +337,23 @@ func (s *Service) UpdateOrgDeploymentAnnotations(ctx context.Context, org *datab
func (s *Service) RedeployProject(ctx context.Context, proj *database.Project, prevDepl *database.Deployment) (*database.Project, error) {
// Provision new deployment
var branch, environment string
var editable bool
var editable, readOnlyModels bool
if prevDepl != nil {
branch = prevDepl.Branch
environment = prevDepl.Environment
editable = prevDepl.Editable
readOnlyModels = prevDepl.ReadOnlyModels
} else {
branch = proj.PrimaryBranch
environment = "prod"
}
newDepl, err := s.CreateDeployment(ctx, &CreateDeploymentOptions{
ProjectID: proj.ID,
OwnerUserID: nil,
Environment: environment,
Branch: branch,
Editable: editable,
ProjectID: proj.ID,
OwnerUserID: nil,
Environment: environment,
Branch: branch,
Editable: editable,
ReadOnlyModels: readOnlyModels,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -552,7 +555,8 @@ func (s *Service) ResolveVariables(ctx context.Context, depl *database.Deploymen
})
// Enable the file watcher for editable deployments.
systemVars := map[string]string{
"rill.watch_repo": strconv.FormatBool(depl.Editable),
"rill.watch_repo": strconv.FormatBool(depl.Editable),
"rill.models.assume_materialized": strconv.FormatBool(depl.ReadOnlyModels),
}
return vars, systemVars, nil
}
14 changes: 8 additions & 6 deletions admin/server/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (s *Server) CreateDeployment(ctx context.Context, req *adminv1.CreateDeploy
attribute.String("args.environment", req.Environment),
attribute.String("args.branch", req.Branch),
attribute.Bool("args.editable", req.Editable),
attribute.Bool("args.read_only_models", req.ReadOnlyModels),
)

proj, err := s.admin.DB.FindProjectByName(ctx, req.Org, req.Project)
Expand Down Expand Up @@ -284,7 +285,7 @@ func (s *Server) CreateDeployment(ctx context.Context, req *adminv1.CreateDeploy
} else {
branch = proj.PrimaryBranch
}
if req.Editable {
if req.Editable && !req.ReadOnlyModels {
return nil, status.Error(codes.InvalidArgument, "editable cannot be set for prod deployments")
}
slots = proj.ProdSlots
Expand Down Expand Up @@ -345,11 +346,12 @@ func (s *Server) CreateDeployment(ctx context.Context, req *adminv1.CreateDeploy
}

depl, err := s.admin.CreateDeployment(ctx, &admin.CreateDeploymentOptions{
ProjectID: proj.ID,
OwnerUserID: ownerUserID,
Environment: req.Environment,
Branch: branch,
Editable: req.Editable,
ProjectID: proj.ID,
OwnerUserID: ownerUserID,
Environment: req.Environment,
Branch: branch,
Editable: req.Editable,
ReadOnlyModels: req.ReadOnlyModels,
})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions admin/server/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,7 @@ func deploymentToDTO(d *database.Deployment) *adminv1.Deployment {
Environment: d.Environment,
Branch: d.Branch,
Editable: d.Editable,
ReadOnlyModels: d.ReadOnlyModels,
RuntimeHost: d.RuntimeHost,
RuntimeInstanceId: d.RuntimeInstanceID,
Status: s,
Expand Down
21 changes: 14 additions & 7 deletions cli/cmd/project/deployment/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
var project, path, environment string
var editable bool
var editable, readOnlyModels bool

createCmd := &cobra.Command{
Use: "create [<project>] <branch>",
Expand All @@ -39,7 +39,12 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
}
}

if environment == "prod" {
if readOnlyModels && !cmd.Flags().Changed("environment") {
// If read-only-models is set and environment is not explicitly set, default to prod
environment = "prod"
}

if environment == "prod" && !readOnlyModels {
// editable defaults to true, so only error if it was explicitly requested
if cmd.Flags().Changed("editable") && editable {
return fmt.Errorf("prod deployments cannot be editable")
Expand All @@ -54,11 +59,12 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
ch.PrintfBold("Creating %q deployment for branch %q...\n", environment, branch)

resp, err := client.CreateDeployment(cmd.Context(), &adminv1.CreateDeploymentRequest{
Org: ch.Org,
Project: project,
Environment: environment,
Branch: branch,
Editable: editable,
Org: ch.Org,
Project: project,
Environment: environment,
Branch: branch,
Editable: editable,
ReadOnlyModels: readOnlyModels,
})
if err != nil {
return err
Expand All @@ -76,6 +82,7 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
createCmd.Flags().StringVar(&path, "path", ".", "Project directory")
createCmd.Flags().StringVar(&environment, "environment", "dev", "Optional environment to create for (options: dev, prod)")
createCmd.Flags().BoolVar(&editable, "editable", true, "Make the deployment editable (changes are persisted back to git repo)")
createCmd.Flags().BoolVar(&readOnlyModels, "read-only-models", false, "Project editing is allowed but models are read-only. Assumes models have already been materialized in the output connector. Allows quick setup of editable deployments.")
_ = createCmd.Flags().MarkHidden("environment") // Hide the environment flag since editable deployments are only supported for dev environment and non editable deployments are not supported in UI yet
_ = createCmd.Flags().MarkHidden("editable") // Hide the editable flag since non editable deployments are not supported in UI yet

Expand Down
5 changes: 5 additions & 0 deletions proto/gen/rill/admin/v1/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,9 @@ paths:
description: |-
Whether the deployment is editable and the edited changes are persisted back to the git repo.
Can't be set for `prod` deployments.
readOnlyModels:
type: boolean
description: Set for editable projects when edits to models is not allowed.
/v1/orgs/{org}/projects/{project}/github/pr:
post:
summary: CreateGithubPullRequest creates a Github PR from the specified branch in the project's connected Github repository to the primary branch.
Expand Down Expand Up @@ -5381,6 +5384,8 @@ definitions:
type: string
editable:
type: boolean
readOnlyModels:
type: boolean
runtimeHost:
type: string
runtimeInstanceId:
Expand Down
Loading
Loading