Skip to content

Commit

Permalink
Hook svc level alteration management to DAL
Browse files Browse the repository at this point in the history
  • Loading branch information
tjerman committed Oct 26, 2023
1 parent b86f67c commit 1eb360f
Show file tree
Hide file tree
Showing 24 changed files with 627 additions and 182 deletions.
6 changes: 0 additions & 6 deletions server/.env.example
Expand Up @@ -26,12 +26,6 @@
# Default: sqlite3://file::memory:?cache=shared&mode=memory
# DB_DSN=sqlite3://file::memory:?cache=shared&mode=memory

###############################################################################
# Allow for irreversible changes to the database schema such as dropping columns and tables.
# Type: bool
# Default: <no value>
# DB_ALLOW_DESTRUCTIVE_SCHEMA_CHANGES=<no value>

###############################################################################
###############################################################################
# HTTP Client
Expand Down
5 changes: 4 additions & 1 deletion server/app/boot_levels.go
Expand Up @@ -23,6 +23,7 @@ import (
apigwTypes "github.com/cortezaproject/corteza/server/pkg/apigw/types"
"github.com/cortezaproject/corteza/server/pkg/auth"
"github.com/cortezaproject/corteza/server/pkg/corredor"
"github.com/cortezaproject/corteza/server/pkg/dal"
"github.com/cortezaproject/corteza/server/pkg/eventbus"
"github.com/cortezaproject/corteza/server/pkg/healthcheck"
"github.com/cortezaproject/corteza/server/pkg/http"
Expand Down Expand Up @@ -380,11 +381,13 @@ func (app *CortezaApp) InitServices(ctx context.Context) (err error) {
Limit: app.Opt.Limit,
Attachment: app.Opt.Attachment,
})

if err != nil {
return
}

// Add alteration management service the global DAL service
dal.Service().Alterations = service.DefaultDalSchemaAlteration

if app.Opt.Messagebus.Enabled {
// initialize all the queue handlers
messagebus.Service().Init(ctx, service.DefaultQueue)
Expand Down
6 changes: 1 addition & 5 deletions server/app/options/db.cue
Expand Up @@ -11,11 +11,7 @@ DB: schema.#optionsGroup & {
defaultValue: "sqlite3://file::memory:?cache=shared&mode=memory"
description: "Database connection string."
}
allow_destructive_schema_changes: {
type: "bool"
defaultGoExpr: "false"
description: "Allow for irreversible changes to the database schema such as dropping columns and tables."
}

}
title: "Connection to data store backend"
}
1 change: 0 additions & 1 deletion server/compose/service/dal_interfaces.go
Expand Up @@ -12,7 +12,6 @@ type (
SearchModels(ctx context.Context) (out dal.ModelSet, err error)
ReplaceModel(ctx context.Context, model *dal.Model) (err error)
RemoveModel(ctx context.Context, connectionID, ID uint64) (err error)
ReplaceModelAttribute(ctx context.Context, model *dal.Model, diff *dal.ModelDiff, hasRecords bool, trans ...dal.TransformationFunction) (err error)

GetConnectionByID(uint64) *dal.ConnectionWrap

Expand Down
42 changes: 3 additions & 39 deletions server/compose/service/module.go
Expand Up @@ -80,8 +80,7 @@ type (

ReplaceModel(context.Context, *dal.Model) error
RemoveModel(ctx context.Context, connectionID, ID uint64) error
ReplaceModelAttribute(ctx context.Context, model *dal.Model, diff *dal.ModelDiff, hasRecords bool, trans ...dal.TransformationFunction) (err error)
SearchModelIssues(ID uint64) []error
SearchModelIssues(ID uint64) []dal.Issue
}
)

Expand Down Expand Up @@ -307,15 +306,9 @@ func (svc module) procDal(m *types.Module) {
return
}

ii := svc.dal.SearchModelIssues(m.ID)
if len(ii) == 0 {
m.Issues = svc.dal.SearchModelIssues(m.ID)
if len(m.Issues) == 0 {
m.Issues = nil
return
}

m.Issues = make([]string, len(ii))
for i, err := range ii {
m.Issues[i] = err.Error()
}
}

Expand All @@ -336,10 +329,6 @@ func (svc module) Create(ctx context.Context, new *types.Module) (*types.Module,
}
}

if err != nil {

}

if ns, err = loadNamespace(ctx, s, new.NamespaceID); err != nil {
return err
}
Expand Down Expand Up @@ -633,9 +622,6 @@ func (svc module) updater(ctx context.Context, namespaceID, moduleID uint64, act
if err = DalModelReplace(ctx, svc.dal, ns, old, m); err != nil {
return err
}
if err = dalAttributeReplace(ctx, svc.dal, ns, old, m, hasRecords); err != nil {
return err
}
} else {
if err = svc.eventbus.WaitFor(ctx, event.ModuleAfterDelete(nil, old, ns)); err != nil {
return
Expand Down Expand Up @@ -1169,28 +1155,6 @@ func DalModelReplace(ctx context.Context, dmm dalModelManager, ns *types.Namespa
return
}

func dalAttributeReplace(ctx context.Context, dmm dalModelManager, ns *types.Namespace, old, new *types.Module, hasRecords bool) (err error) {
oldModel, err := ModulesToModelSet(dmm, ns, old)
if err != nil {
return
}
newModel, err := ModulesToModelSet(dmm, ns, new)
if err != nil {
return
}

diff := oldModel[0].Diff(newModel[0])

// TODO handle the fact that diff is a list of changes so the same field could be present more than once.
for _, d := range diff {
if err = dmm.ReplaceModelAttribute(ctx, oldModel[0], d, hasRecords); err != nil {
return
}
}

return
}

// Removes a connection from DAL service
func DalModelRemove(ctx context.Context, dmm dalModelManager, mm ...*types.Module) (err error) {
for _, m := range mm {
Expand Down
2 changes: 1 addition & 1 deletion server/compose/types/module.go
Expand Up @@ -32,7 +32,7 @@ type (

Labels map[string]string `json:"labels,omitempty"`

Issues []string `json:"issues,omitempty"`
Issues []dal.Issue `json:"issues,omitempty"`

NamespaceID uint64 `json:"namespaceID,string"`

Expand Down
6 changes: 2 additions & 4 deletions server/pkg/options/options.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 33 additions & 13 deletions server/store/adapters/rdbms/aux_types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion server/store/adapters/rdbms/filters.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1eb360f

Please sign in to comment.