Skip to content

Commit

Permalink
Allow alterations for default schema but prevent applying
Browse files Browse the repository at this point in the history
  • Loading branch information
tjerman committed Feb 15, 2024
1 parent 0ece3b2 commit b389d50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 7 additions & 0 deletions server/pkg/dal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ func (svc *service) applyAlteration(ctx context.Context, alts ...*Alteration) (e
}

var (
c = svc.GetConnectionByID(0)

connectionID = alts[0].ConnectionID
resource = alts[0].Resource
resourceType = alts[0].ResourceType
Expand Down Expand Up @@ -864,6 +866,11 @@ func (svc *service) applyAlteration(ctx context.Context, alts ...*Alteration) (e
return nil, fmt.Errorf("model not found")
}

if model.ConnectionID == c.ID && model.Ident == "compose_record" {
err = fmt.Errorf("cannot apply alterations for default schema")
return
}

issues = issues.addModel(model.ResourceID)

// @todo consider adding some logging to validators
Expand Down
9 changes: 0 additions & 9 deletions server/system/service/dal_schema_alteration.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,6 @@ func (svc dalSchemaAlteration) SetAlterations(ctx context.Context, s store.Store
u = intAuth.GetIdentityFromContext(ctx).Identity()
)

// @todo this won't work entirely; if someone defines a dal connection to the same DSN as the primary one,
// they can easily bypass this.
// We'll need to do some checking on the DSN; potentially when defining the connection itself.
c := svc.dal.GetConnectionByID(0)
if m.ConnectionID == c.ID && m.Ident == "compose_record" {
err = fmt.Errorf("cannot set alterations for default schema")
return
}

// Delete current ones
// @todo we might be able to do some diffing to preserve the metadata/ids
// but for now this should be just fine.
Expand Down

0 comments on commit b389d50

Please sign in to comment.