diff --git a/app/boot_dal.go b/app/boot_dal.go index 692f225de..be8e089ce 100644 --- a/app/boot_dal.go +++ b/app/boot_dal.go @@ -3,13 +3,14 @@ package app import ( "context" "fmt" + "time" + "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/cortezaproject/corteza-server/pkg/id" "github.com/cortezaproject/corteza-server/store" "github.com/cortezaproject/corteza-server/system/service" "github.com/cortezaproject/corteza-server/system/types" "go.uber.org/zap" - "time" ) func (app *CortezaApp) initDAL(ctx context.Context, log *zap.Logger) (err error) { @@ -74,7 +75,6 @@ func provisionPrimaryDalConnection(ctx context.Context, s store.DalConnections) Config: types.ConnectionConfig{ DAL: &types.ConnectionConfigDAL{ ModelIdent: "compose_record", - Operations: dal.FullOperations(), }, }, diff --git a/compose/dalutils/records.go b/compose/dalutils/records.go index 02b80c186..3662e9013 100644 --- a/compose/dalutils/records.go +++ b/compose/dalutils/records.go @@ -248,15 +248,15 @@ func recToGetters(rr ...*types.Record) (out []dal.ValueGetter) { } func recCreateOperations(m *types.Module) (out dal.OperationSet) { - return dal.CreateOperations(m.Config.DAL.Operations...) + return dal.CreateOperations() } func recUpdateOperations(m *types.Module) (out dal.OperationSet) { - return dal.UpdateOperations(m.Config.DAL.Operations...) + return dal.UpdateOperations() } func recDeleteOperations(m *types.Module) (out dal.OperationSet) { - return dal.DeleteOperations(m.Config.DAL.Operations...) + return dal.DeleteOperations() } func recFilterOperations(f types.RecordFilter) (out dal.OperationSet) { @@ -280,10 +280,10 @@ func recFilterOperations(f types.RecordFilter) (out dal.OperationSet) { } func recSearchOperations(m *types.Module, f types.RecordFilter) (out dal.OperationSet) { - return dal.SearchOperations(m.Config.DAL.Operations...). + return dal.SearchOperations(). Union(recFilterOperations(f)) } func recLookupOperations(m *types.Module) (out dal.OperationSet) { - return dal.LookupOperations(m.Config.DAL.Operations...) + return dal.LookupOperations() } diff --git a/compose/service/module.go b/compose/service/module.go index 5b0deb8b5..b13b3d28e 100644 --- a/compose/service/module.go +++ b/compose/service/module.go @@ -1298,7 +1298,6 @@ func ModuleToModel(ns *types.Namespace, mod *types.Module, inhIdent string) (mod ResourceID: mod.ID, ResourceType: types.ModuleResourceType, SensitivityLevelID: mod.Config.Privacy.SensitivityLevelID, - Operations: mod.Config.DAL.Operations, } if model.Ident = mod.Config.DAL.Ident; model.Ident == "" { diff --git a/compose/types/module.go b/compose/types/module.go index 12ee717d5..f4c2b6343 100644 --- a/compose/types/module.go +++ b/compose/types/module.go @@ -82,8 +82,7 @@ type ( } ModuleConfigDAL struct { - ConnectionID uint64 `json:"connectionID,string"` - Operations dal.OperationSet `json:"operations"` + ConnectionID uint64 `json:"connectionID,string"` Constraints map[string][]any `json:"constraints"` diff --git a/pkg/dal/conn.go b/pkg/dal/conn.go index 953ffc786..90b2bd939 100644 --- a/pkg/dal/conn.go +++ b/pkg/dal/conn.go @@ -9,7 +9,6 @@ type ( connection Connection params ConnectionParams Config ConnectionConfig - operations OperationSet } ConnectionConfig struct { diff --git a/pkg/dal/driver.go b/pkg/dal/driver.go index 875d39833..3322905f7 100644 --- a/pkg/dal/driver.go +++ b/pkg/dal/driver.go @@ -100,7 +100,7 @@ type ( SetValue(string, uint, any) error } - ConnectorFn func(ctx context.Context, dsn string, oo ...Operation) (Connection, error) + ConnectorFn func(ctx context.Context, dsn string) (Connection, error) DriverConnectionParam struct { Key string `json:"key"` @@ -156,7 +156,7 @@ func RegisterDriver(d Driver) { } // connect opens a new StoreConnection for the given CRS -func connect(ctx context.Context, log *zap.Logger, isDevelopment bool, cp ConnectionParams, operations ...Operation) (Connection, error) { +func connect(ctx context.Context, log *zap.Logger, isDevelopment bool, cp ConnectionParams) (Connection, error) { if cp.Type != "corteza::dal:connection:dsn" { return nil, fmt.Errorf("cannot open connection: only DSN connections supported (got: %q)", cp.Type) } @@ -180,7 +180,7 @@ func connect(ctx context.Context, log *zap.Logger, isDevelopment bool, cp Connec } if conn, ok := registeredConnectors[storeType]; ok { - return conn(ctx, dsn, operations...) + return conn(ctx, dsn) } else { return nil, fmt.Errorf("unknown store type used: %q (check your database configuration)", storeType) } diff --git a/pkg/dal/model.go b/pkg/dal/model.go index 300ade8bb..b07870574 100644 --- a/pkg/dal/model.go +++ b/pkg/dal/model.go @@ -39,8 +39,6 @@ type ( Attributes AttributeSet - Operations OperationSet - Constraints map[string][]any Indexes IndexSet } diff --git a/pkg/dal/service.go b/pkg/dal/service.go index beba858ef..35a42583b 100644 --- a/pkg/dal/service.go +++ b/pkg/dal/service.go @@ -233,14 +233,13 @@ func (svc *service) RemoveSensitivityLevel(levelIDs ...uint64) (err error) { // Connection management // MakeConnection makes and returns a new connection (wrap) -func MakeConnection(ID uint64, conn Connection, p ConnectionParams, c ConnectionConfig, oo ...Operation) *ConnectionWrap { +func MakeConnection(ID uint64, conn Connection, p ConnectionParams, c ConnectionConfig) *ConnectionWrap { return &ConnectionWrap{ ID: ID, connection: conn, - params: p, - Config: c, - operations: oo, + params: p, + Config: c, } } @@ -295,12 +294,6 @@ func (svc *service) ReplaceConnection(ctx context.Context, conn *ConnectionWrap, for _, model := range svc.models[ID] { log.Debug("validating model before connection is updated", zap.String("ident", model.Ident)) - // - operations - if !model.Operations.IsSubset(conn.operations...) { - issues.addConnectionIssue(ID, fmt.Errorf("cannot update connection %d: new connection does not support existing models", ID)) - errored = true - } - // - sensitivity levels if !svc.sensitivityLevels.isSubset(model.SensitivityLevelID, conn.Config.SensitivityLevelID) { issues.addConnectionIssue(ID, fmt.Errorf("cannot update connection %d: new connection sensitivity level does not support model %d", ID, model.ResourceID)) @@ -328,7 +321,7 @@ func (svc *service) ReplaceConnection(ctx context.Context, conn *ConnectionWrap, } if conn.connection == nil { - conn.connection, err = connect(ctx, svc.logger, svc.inDev, conn.params, conn.operations...) + conn.connection, err = connect(ctx, svc.logger, svc.inDev, conn.params) if err != nil { log.Warn("could not connect", zap.Error(err)) issues.addConnectionIssue(ID, err) @@ -995,7 +988,7 @@ func (svc *service) GetConnectionByID(connectionID uint64) (cw *ConnectionWrap) return svc.connections[connectionID] } -func (svc *service) getConnection(connectionID uint64, cc ...Operation) (cw *ConnectionWrap, can OperationSet, err error) { +func (svc *service) getConnection(connectionID uint64, oo ...Operation) (cw *ConnectionWrap, can OperationSet, err error) { err = func() error { // get the requested connection cw = svc.GetConnectionByID(connectionID) @@ -1004,8 +997,8 @@ func (svc *service) getConnection(connectionID uint64, cc ...Operation) (cw *Con } // check if connection supports requested operations - if !cw.connection.Can(cc...) { - return fmt.Errorf("connection %d does not support requested operations %v", connectionID, OperationSet(cc).Diff(cw.connection.Operations())) + if !cw.connection.Can(oo...) { + return fmt.Errorf("connection %d does not support requested operations %v", connectionID, OperationSet(oo).Diff(cw.connection.Operations())) } can = cw.connection.Operations() return nil diff --git a/pkg/revisions/model.go b/pkg/revisions/model.go index 4d4a6ccc7..d0c04f242 100644 --- a/pkg/revisions/model.go +++ b/pkg/revisions/model.go @@ -30,10 +30,5 @@ func Model() *dal.Model { &dal.Attribute{Ident: "delta", Store: &dal.CodecPlain{}, Type: &dal.TypeJSON{}}, &dal.Attribute{Ident: "comment", Store: &dal.CodecPlain{}, Type: &dal.TypeText{}}, }, - - Operations: dal.OperationSet{ - dal.Create, - dal.Search, - }, } } diff --git a/store/adapters/rdbms/dal/connection.go b/store/adapters/rdbms/dal/connection.go index 0f8f297e8..b8283bd40 100644 --- a/store/adapters/rdbms/dal/connection.go +++ b/store/adapters/rdbms/dal/connection.go @@ -3,9 +3,10 @@ package dal import ( "context" "fmt" + "sync" + "github.com/cortezaproject/corteza-server/pkg/errors" "github.com/cortezaproject/corteza-server/store/adapters/rdbms/ddl" - "sync" "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/cortezaproject/corteza-server/pkg/filter" @@ -18,9 +19,9 @@ type ( // // In other words: this allows Corteza to read Records from the supported SQL databases connection struct { - mux sync.RWMutex - models map[string]*model - operations dal.OperationSet + mux sync.RWMutex + models map[string]*model + driver dal.Driver db sqlx.ExtContext dialect drivers.Dialect @@ -29,21 +30,26 @@ type ( } ) +var ( + dalDriver dal.Driver +) + func init() { - dal.RegisterDriver(dal.Driver{ + dalDriver = dal.Driver{ Type: "corteza::dal:driver:rdbms", Operations: dal.FullOperations(), Connection: dal.NewDSNDriverConnectionConfig(), - }) + } + dal.RegisterDriver(dalDriver) } -func Connection(db sqlx.ExtContext, dialect drivers.Dialect, dd ddl.DataDefiner, cc ...dal.Operation) *connection { +func Connection(db sqlx.ExtContext, dialect drivers.Dialect, dd ddl.DataDefiner) *connection { return &connection{ db: db, dialect: dialect, dataDefiner: dd, models: make(map[string]*model), - operations: cc, + driver: dalDriver, } } @@ -68,11 +74,11 @@ func (c *connection) withModel(m *dal.Model, fn func(m *model) error) error { } func (c *connection) Operations() dal.OperationSet { - return c.operations + return c.driver.Operations } func (c *connection) Can(operations ...dal.Operation) bool { - return c.operations.IsSuperset(operations...) + return c.Operations().IsSuperset(operations...) } func (c *connection) Create(ctx context.Context, m *dal.Model, rr ...dal.ValueGetter) (err error) { diff --git a/store/adapters/rdbms/drivers/mysql/connect.go b/store/adapters/rdbms/drivers/mysql/connect.go index fe9360bbe..656fbab79 100644 --- a/store/adapters/rdbms/drivers/mysql/connect.go +++ b/store/adapters/rdbms/drivers/mysql/connect.go @@ -4,10 +4,10 @@ import ( "context" "database/sql" "fmt" - "github.com/cortezaproject/corteza-server/store/adapters/rdbms/dal" "strings" - pkgdal "github.com/cortezaproject/corteza-server/pkg/dal" + "github.com/cortezaproject/corteza-server/store/adapters/rdbms/dal" + "github.com/cortezaproject/corteza-server/pkg/errors" "github.com/cortezaproject/corteza-server/pkg/logger" "github.com/cortezaproject/corteza-server/store" @@ -45,7 +45,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) { s := &rdbms.Store{ DB: db, - DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), pkgdal.FullOperations()...), + DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), Dialect: goquDialectWrapper, TxRetryErrHandler: txRetryErrHandler, diff --git a/store/adapters/rdbms/drivers/mysql/dal.go b/store/adapters/rdbms/drivers/mysql/dal.go index 8e341bbed..1a9042d08 100644 --- a/store/adapters/rdbms/drivers/mysql/dal.go +++ b/store/adapters/rdbms/drivers/mysql/dal.go @@ -11,7 +11,7 @@ func init() { dal.RegisterConnector(dalConnector, SCHEMA, debugSchema) } -func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.Connection, err error) { +func dalConnector(ctx context.Context, dsn string) (_ dal.Connection, err error) { cfg, err := NewConfig(dsn) if err != nil { return @@ -27,5 +27,5 @@ func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.C if err != nil { return } - return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), cc...), nil + return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), nil } diff --git a/store/adapters/rdbms/drivers/postgres/connect.go b/store/adapters/rdbms/drivers/postgres/connect.go index fee46cfb0..09b07ad88 100644 --- a/store/adapters/rdbms/drivers/postgres/connect.go +++ b/store/adapters/rdbms/drivers/postgres/connect.go @@ -7,7 +7,6 @@ import ( "net/url" "strings" - pkgdal "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/cortezaproject/corteza-server/store/adapters/rdbms/dal" "github.com/cortezaproject/corteza-server/pkg/logger" @@ -50,7 +49,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) { s := &rdbms.Store{ DB: db, - DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), pkgdal.FullOperations()...), + DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), Dialect: goquDialectWrapper, ErrorHandler: errorHandler, diff --git a/store/adapters/rdbms/drivers/postgres/dal.go b/store/adapters/rdbms/drivers/postgres/dal.go index 28c6b6e16..e5db507a9 100644 --- a/store/adapters/rdbms/drivers/postgres/dal.go +++ b/store/adapters/rdbms/drivers/postgres/dal.go @@ -14,7 +14,7 @@ func init() { dal.RegisterConnector(dalConnector, SCHEMA, debugSchema) } -func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.Connection, err error) { +func dalConnector(ctx context.Context, dsn string) (_ dal.Connection, err error) { var ( db *sqlx.DB cfg *rdbms.ConnConfig @@ -33,5 +33,5 @@ func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.C return } - return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), cc...), nil + return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), nil } diff --git a/store/adapters/rdbms/drivers/sqlite/connect.go b/store/adapters/rdbms/drivers/sqlite/connect.go index f43d9277a..e03c2b50f 100644 --- a/store/adapters/rdbms/drivers/sqlite/connect.go +++ b/store/adapters/rdbms/drivers/sqlite/connect.go @@ -7,7 +7,6 @@ import ( "regexp" "strings" - pkgdal "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/cortezaproject/corteza-server/store/adapters/rdbms/dal" "github.com/cortezaproject/corteza-server/pkg/logger" @@ -70,7 +69,7 @@ func Connect(ctx context.Context, dsn string) (_ store.Storer, err error) { s := &rdbms.Store{ DB: db, - DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), pkgdal.FullOperations()...), + DAL: dal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), Dialect: goquDialectWrapper, ErrorHandler: errorHandler, diff --git a/store/adapters/rdbms/drivers/sqlite/dal.go b/store/adapters/rdbms/drivers/sqlite/dal.go index 9adceeaab..ae6e5dac6 100644 --- a/store/adapters/rdbms/drivers/sqlite/dal.go +++ b/store/adapters/rdbms/drivers/sqlite/dal.go @@ -14,7 +14,7 @@ func init() { dal.RegisterConnector(dalConnector, SCHEMA, altSchema, debugSchema) } -func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.Connection, err error) { +func dalConnector(ctx context.Context, dsn string) (_ dal.Connection, err error) { var ( db *sqlx.DB cfg *rdbms.ConnConfig @@ -33,5 +33,5 @@ func dalConnector(ctx context.Context, dsn string, cc ...dal.Operation) (_ dal.C return } - return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db), cc...), nil + return rdbmsdal.Connection(db, Dialect(), DataDefiner(cfg.DBName, db)), nil } diff --git a/store/adapters/rdbms/drivers/types_test.go b/store/adapters/rdbms/drivers/types_test.go index a53ed98b3..9cb38dab3 100644 --- a/store/adapters/rdbms/drivers/types_test.go +++ b/store/adapters/rdbms/drivers/types_test.go @@ -4,6 +4,7 @@ import ( "database/sql" "testing" + "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/stretchr/testify/require" ) diff --git a/system/service/dal_connection.go b/system/service/dal_connection.go index 68998f4d9..c8b81c6bc 100644 --- a/system/service/dal_connection.go +++ b/system/service/dal_connection.go @@ -365,14 +365,12 @@ func MakeDalConnection(c *types.DalConnection, existing dal.Connection) (cw *dal SensitivityLevelID: c.Config.Privacy.SensitivityLevelID, Label: c.Handle, } - connParams dal.ConnectionParams - connOperations dal.OperationSet + connParams dal.ConnectionParams ) if c.Config.DAL != nil { connConfig.ModelIdent = c.Config.DAL.ModelIdent - connOperations = c.Config.DAL.Operations connParams = dal.ConnectionParams{ Type: c.Config.DAL.Type, Params: c.Config.DAL.Params, @@ -393,7 +391,6 @@ func MakeDalConnection(c *types.DalConnection, existing dal.Connection) (cw *dal existing, connParams, connConfig, - connOperations..., ) return diff --git a/system/types/dal_connection.go b/system/types/dal_connection.go index 7d880d611..97fbdaa42 100644 --- a/system/types/dal_connection.go +++ b/system/types/dal_connection.go @@ -8,7 +8,6 @@ import ( "github.com/cortezaproject/corteza-server/pkg/geolocation" "github.com/cortezaproject/corteza-server/pkg/sql" - "github.com/cortezaproject/corteza-server/pkg/dal" "github.com/cortezaproject/corteza-server/pkg/filter" ) @@ -86,10 +85,6 @@ type ( // parameters for th connection Params map[string]any `json:"params"` - // @note operations, for now, will only be available on connections - // with a fallback on modules - Operations dal.OperationSet `json:"operations"` - // ident to be used when generating models from modules using this connection // it can use {{module}} and {{namespace}} as placeholders ModelIdent string `json:"modelIdent"`