diff --git a/compose/module-field.cue b/compose/module-field.cue index 9e46bdbd3..8cd78bbde 100644 --- a/compose/module-field.cue +++ b/compose/module-field.cue @@ -19,11 +19,8 @@ moduleField: schema.#Resource & { name: {sortable: true} label: {sortable: true} options: { goType: "types.ModuleFieldOptions" } - encoding_strategy: { goType: "types.EncodingStrategy" } - privacy: { goType: "types.ModuleFieldConfigDataPrivacy" } - private: { goType: "bool", storeIdent: "is_private" } + config: { goType: "types.ModuleFieldConfig" } required: { goType: "bool", storeIdent: "is_required" } - visible: { goType: "bool", storeIdent: "is_visible" } multi: { goType: "bool", storeIdent: "is_multi" } default_value: { goType: "types.RecordValueSet" } expressions: { goType: "types.ModuleFieldExpr" } diff --git a/compose/service/module.go b/compose/service/module.go index 4c72dcf83..e3f965f31 100644 --- a/compose/service/module.go +++ b/compose/service/module.go @@ -1270,42 +1270,57 @@ func moduleSystemFieldsToAttributes(ctx context.Context, cm dal.ConnectionMeta, // partitionedModuleSystemFieldsToAttributes converts all system-defined module fields to attributes // keeping user-defined codec in mind func partitionedModuleSystemFieldsToAttributes(cm dal.ConnectionMeta, mod *types.Module) (out dal.AttributeSet) { - sysEnc := mod.Config.DAL.SystemFieldEncoding + var ( + sysEnc = mod.Config.DAL.SystemFieldEncoding + + mf = func(name string, es *types.EncodingStrategy) *types.ModuleField { + return &types.ModuleField{ + Name: name, + Config: types.ModuleFieldConfig{ + DAL: types.ModuleFieldConfigDAL{EncodingStrategy: *es}, + }, + } + } + ) if sysEnc.ID != nil { - out = append(out, dal.PrimaryAttribute(sysID, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysID, EncodingStrategy: *sysEnc.ID}))) + out = append(out, dal.PrimaryAttribute(sysID, modelFieldCodec(cm, mod, mf(sysID, sysEnc.ID)))) } if sysEnc.ModuleID != nil { - out = append(out, dal.FullAttribute(sysModuleID, &dal.TypeID{}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysModuleID, EncodingStrategy: *sysEnc.ModuleID}))) + out = append(out, dal.FullAttribute(sysModuleID, &dal.TypeID{}, modelFieldCodec(cm, mod, mf(sysModuleID, sysEnc.ModuleID)))) } + if sysEnc.NamespaceID != nil { - out = append(out, dal.FullAttribute(sysNamespaceID, &dal.TypeID{}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysNamespaceID, EncodingStrategy: *sysEnc.NamespaceID}))) + out = append(out, dal.FullAttribute(sysNamespaceID, &dal.TypeID{}, modelFieldCodec(cm, mod, mf(sysNamespaceID, sysEnc.NamespaceID)))) } if sysEnc.OwnedBy != nil { - out = append(out, dal.FullAttribute(sysOwnedBy, &dal.TypeID{}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysOwnedBy, EncodingStrategy: *sysEnc.OwnedBy}))) + out = append(out, dal.FullAttribute(sysOwnedBy, &dal.TypeID{}, modelFieldCodec(cm, mod, mf(sysOwnedBy, sysEnc.OwnedBy)))) } if sysEnc.CreatedAt != nil { - out = append(out, dal.FullAttribute(sysCreatedAt, &dal.TypeTimestamp{}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysCreatedAt, EncodingStrategy: *sysEnc.CreatedAt}))) + out = append(out, dal.FullAttribute(sysCreatedAt, &dal.TypeTimestamp{}, modelFieldCodec(cm, mod, mf(sysCreatedAt, sysEnc.CreatedAt)))) } + if sysEnc.CreatedBy != nil { - out = append(out, dal.FullAttribute(sysCreatedBy, &dal.TypeID{}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysCreatedBy, EncodingStrategy: *sysEnc.CreatedBy}))) + out = append(out, dal.FullAttribute(sysCreatedBy, &dal.TypeID{}, modelFieldCodec(cm, mod, mf(sysCreatedBy, sysEnc.CreatedBy)))) } if sysEnc.UpdatedAt != nil { - out = append(out, dal.FullAttribute(sysUpdatedAt, &dal.TypeTimestamp{Nullable: true}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysUpdatedAt, EncodingStrategy: *sysEnc.UpdatedAt}))) + out = append(out, dal.FullAttribute(sysUpdatedAt, &dal.TypeTimestamp{Nullable: true}, modelFieldCodec(cm, mod, mf(sysUpdatedAt, sysEnc.UpdatedAt)))) } + if sysEnc.UpdatedBy != nil { - out = append(out, dal.FullAttribute(sysUpdatedBy, &dal.TypeID{Nullable: true}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysUpdatedBy, EncodingStrategy: *sysEnc.UpdatedBy}))) + out = append(out, dal.FullAttribute(sysUpdatedBy, &dal.TypeID{Nullable: true}, modelFieldCodec(cm, mod, mf(sysUpdatedBy, sysEnc.UpdatedBy)))) } if sysEnc.DeletedAt != nil { - out = append(out, dal.FullAttribute(sysDeletedAt, &dal.TypeTimestamp{Nullable: true}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysDeletedAt, EncodingStrategy: *sysEnc.DeletedAt}))) + out = append(out, dal.FullAttribute(sysDeletedAt, &dal.TypeTimestamp{Nullable: true}, modelFieldCodec(cm, mod, mf(sysDeletedAt, sysEnc.DeletedAt)))) } + if sysEnc.DeletedBy != nil { - out = append(out, dal.FullAttribute(sysDeletedBy, &dal.TypeID{Nullable: true}, modelFieldCodec(cm, mod, &types.ModuleField{Name: sysDeletedBy, EncodingStrategy: *sysEnc.DeletedBy}))) + out = append(out, dal.FullAttribute(sysDeletedBy, &dal.TypeID{Nullable: true}, modelFieldCodec(cm, mod, mf(sysDeletedBy, sysEnc.DeletedBy)))) } return @@ -1411,7 +1426,7 @@ func moduleFieldToAttribute(ctx context.Context, cm dal.ConnectionMeta, mod *typ return nil, fmt.Errorf("invalid field %s: kind %s not supported", f.Name, f.Kind) } - out.SensitivityLevel = f.Privacy.SensitivityLevel + out.SensitivityLevel = f.Config.Privacy.SensitivityLevel out.Label = f.Name out.MultiValue = f.Multi @@ -1449,13 +1464,13 @@ func modelFieldCodec(cm dal.ConnectionMeta, mod *types.Module, f *types.ModuleFi c = baseModelFieldCodec(cm, mod, f) switch { - case f.EncodingStrategy.EncodingStrategyAlias != nil: + case f.Config.DAL.EncodingStrategy.EncodingStrategyAlias != nil: c = &dal.CodecAlias{ - Ident: f.EncodingStrategy.EncodingStrategyAlias.Ident, + Ident: f.Config.DAL.EncodingStrategy.EncodingStrategyAlias.Ident, } - case f.EncodingStrategy.EncodingStrategyJSON != nil: + case f.Config.DAL.EncodingStrategy.EncodingStrategyJSON != nil: c = &dal.CodecRecordValueSetJSON{ - Ident: f.EncodingStrategy.EncodingStrategyJSON.Ident, + Ident: f.Config.DAL.EncodingStrategy.EncodingStrategyJSON.Ident, } } diff --git a/compose/types/module.go b/compose/types/module.go index 73e9a8d74..8042d46c4 100644 --- a/compose/types/module.go +++ b/compose/types/module.go @@ -96,8 +96,6 @@ type ( UsageDisclosure string `json:"usageDisclosure"` } - ModelMeta map[string]any - ModuleFilter struct { ModuleID []uint64 `json:"moduleID"` NamespaceID uint64 `json:"namespaceID,string"` @@ -168,9 +166,6 @@ func (set ModuleSet) FindByHandle(handle string) *Module { func (c *ModuleConfig) Scan(src any) error { return sql.ParseJSON(src, c) } func (c ModuleConfig) Value() (driver.Value, error) { return json.Marshal(c) } -func (m *ModelMeta) Scan(src any) error { return sql.ParseJSON(src, m) } -func (m ModelMeta) Value() (driver.Value, error) { return json.Marshal(m) } - func ParseModuleConfig(ss []string) (m ModuleConfig, err error) { if len(ss) == 0 { return diff --git a/compose/types/module_field.go b/compose/types/module_field.go index 70a695367..fde7ed636 100644 --- a/compose/types/module_field.go +++ b/compose/types/module_field.go @@ -25,15 +25,14 @@ type ( Kind string `json:"kind"` Name string `json:"name"` + // Options relevant to field type Options ModuleFieldOptions `json:"options"` - EncodingStrategy EncodingStrategy `json:"encodingStrategy"` + // Configuration - how sub-services and sub-systems like DAL and record revisions + // are configured to work with this field + Config ModuleFieldConfig `json:"config"` - Privacy ModuleFieldConfigDataPrivacy `json:"privacy"` - - Private bool `json:"isPrivate"` Required bool `json:"isRequired"` - Visible bool `json:"isVisible"` Multi bool `json:"isMulti"` DefaultValue RecordValueSet `json:"defaultValue"` @@ -51,6 +50,15 @@ type ( Label string `json:"label"` } + ModuleFieldConfig struct { + DAL ModuleFieldConfigDAL `json:"dal"` + Privacy ModuleFieldConfigDataPrivacy `json:"privacy"` + } + + ModuleFieldConfigDAL struct { + EncodingStrategy EncodingStrategy `json:"encodingStrategy"` + } + ModuleFieldConfigDataPrivacy struct { // Define the highest sensitivity level which // can be configured on the module fields @@ -429,9 +437,6 @@ func (set ModuleFieldSet) Clone() (out ModuleFieldSet) { func (set *ModuleFieldSet) Scan(src any) error { return sql.ParseJSON(src, set) } func (set ModuleFieldSet) Value() (driver.Value, error) { return json.Marshal(set) } -func (set *EncodingStrategy) Scan(src any) error { return sql.ParseJSON(src, set) } -func (set EncodingStrategy) Value() (driver.Value, error) { return json.Marshal(set) } - func (set ModuleFieldSet) Names() (names []string) { names = make([]string, len(set)) @@ -511,8 +516,8 @@ func (f ModuleField) IsRef() bool { } func (f ModuleField) IsSensitive() bool { - return f.Privacy.SensitivityLevel > 0 + return f.Config.Privacy.SensitivityLevel > 0 } -func (p *ModuleFieldConfigDataPrivacy) Scan(src any) error { return sql.ParseJSON(src, p) } -func (p ModuleFieldConfigDataPrivacy) Value() (driver.Value, error) { return json.Marshal(p) } +func (p *ModuleFieldConfig) Scan(src any) error { return sql.ParseJSON(src, p) } +func (p ModuleFieldConfig) Value() (driver.Value, error) { return json.Marshal(p) } diff --git a/docs/compose.yaml b/docs/compose.yaml index fe028adfb..52e199380 100644 --- a/docs/compose.yaml +++ b/docs/compose.yaml @@ -594,8 +594,6 @@ paths: type: integer isRequired: type: boolean - isPrivate: - type: boolean isMulti: type: boolean isSystem: diff --git a/docs/federation.yaml b/docs/federation.yaml index 6fb9ef127..18d087286 100644 --- a/docs/federation.yaml +++ b/docs/federation.yaml @@ -319,8 +319,6 @@ paths: type: integer isRequired: type: boolean - isPrivate: - type: boolean isMulti: type: boolean isSystem: diff --git a/pkg/envoy/yaml/compose_module_marshal.go b/pkg/envoy/yaml/compose_module_marshal.go index 74389619f..a160dbd48 100644 --- a/pkg/envoy/yaml/compose_module_marshal.go +++ b/pkg/envoy/yaml/compose_module_marshal.go @@ -194,10 +194,9 @@ func (c *composeModuleField) MarshalYAML() (interface{}, error) { "label", c.res.Label, "options", nopt, + "config", c.res.Config, - "private", c.res.Private, "required", c.res.Required, - "visible", c.res.Visible, "multi", c.res.Multi, "defaultValue", c.res.DefaultValue, diff --git a/pkg/envoy/yaml/compose_module_unmarshal.go b/pkg/envoy/yaml/compose_module_unmarshal.go index 37b156035..2124fec0c 100644 --- a/pkg/envoy/yaml/compose_module_unmarshal.go +++ b/pkg/envoy/yaml/compose_module_unmarshal.go @@ -314,15 +314,9 @@ func (wrap *composeModuleField) UnmarshalYAML(n *yaml.Node) (err error) { case "label": return y7s.DecodeScalar(v, "module label", &wrap.res.Label) - case "private": - return y7s.DecodeScalar(v, "module private", &wrap.res.Private) - case "required": return y7s.DecodeScalar(v, "module required", &wrap.res.Required) - case "visible": - return y7s.DecodeScalar(v, "module visible", &wrap.res.Visible) - case "multi": return y7s.DecodeScalar(v, "module multi", &wrap.res.Multi) @@ -331,6 +325,11 @@ func (wrap *composeModuleField) UnmarshalYAML(n *yaml.Node) (err error) { return err } + case "config": + if err = v.Decode(&wrap.res.Config); err != nil { + return err + } + case "expressions": ea := composeModuleFieldExpr{} if err = v.Decode(&ea); err != nil { diff --git a/store/adapters/rdbms/aux_types.gen.go b/store/adapters/rdbms/aux_types.gen.go index 0a3e1de91..9fc1aafa4 100644 --- a/store/adapters/rdbms/aux_types.gen.go +++ b/store/adapters/rdbms/aux_types.gen.go @@ -257,24 +257,21 @@ type ( // auxComposeModuleField is an auxiliary structure used for transporting to/from RDBMS store auxComposeModuleField struct { - ID uint64 `db:"id"` - ModuleID uint64 `db:"module_id"` - Place int `db:"place"` - Kind string `db:"kind"` - Name string `db:"name"` - Label string `db:"label"` - Options composeType.ModuleFieldOptions `db:"options"` - EncodingStrategy composeType.EncodingStrategy `db:"encoding_strategy"` - Privacy composeType.ModuleFieldConfigDataPrivacy `db:"privacy"` - Private bool `db:"private"` - Required bool `db:"required"` - Visible bool `db:"visible"` - Multi bool `db:"multi"` - DefaultValue composeType.RecordValueSet `db:"default_value"` - Expressions composeType.ModuleFieldExpr `db:"expressions"` - CreatedAt time.Time `db:"created_at"` - UpdatedAt *time.Time `db:"updated_at"` - DeletedAt *time.Time `db:"deleted_at"` + ID uint64 `db:"id"` + ModuleID uint64 `db:"module_id"` + Place int `db:"place"` + Kind string `db:"kind"` + Name string `db:"name"` + Label string `db:"label"` + Options composeType.ModuleFieldOptions `db:"options"` + Config composeType.ModuleFieldConfig `db:"config"` + Required bool `db:"required"` + Multi bool `db:"multi"` + DefaultValue composeType.RecordValueSet `db:"default_value"` + Expressions composeType.ModuleFieldExpr `db:"expressions"` + CreatedAt time.Time `db:"created_at"` + UpdatedAt *time.Time `db:"updated_at"` + DeletedAt *time.Time `db:"deleted_at"` } // auxComposeNamespace is an auxiliary structure used for transporting to/from RDBMS store @@ -1495,11 +1492,8 @@ func (aux *auxComposeModuleField) encode(res *composeType.ModuleField) (_ error) aux.Name = res.Name aux.Label = res.Label aux.Options = res.Options - aux.EncodingStrategy = res.EncodingStrategy - aux.Privacy = res.Privacy - aux.Private = res.Private + aux.Config = res.Config aux.Required = res.Required - aux.Visible = res.Visible aux.Multi = res.Multi aux.DefaultValue = res.DefaultValue aux.Expressions = res.Expressions @@ -1521,11 +1515,8 @@ func (aux auxComposeModuleField) decode() (res *composeType.ModuleField, _ error res.Name = aux.Name res.Label = aux.Label res.Options = aux.Options - res.EncodingStrategy = aux.EncodingStrategy - res.Privacy = aux.Privacy - res.Private = aux.Private + res.Config = aux.Config res.Required = aux.Required - res.Visible = aux.Visible res.Multi = aux.Multi res.DefaultValue = aux.DefaultValue res.Expressions = aux.Expressions @@ -1547,11 +1538,8 @@ func (aux *auxComposeModuleField) scan(row scanner) error { &aux.Name, &aux.Label, &aux.Options, - &aux.EncodingStrategy, - &aux.Privacy, - &aux.Private, + &aux.Config, &aux.Required, - &aux.Visible, &aux.Multi, &aux.DefaultValue, &aux.Expressions, diff --git a/store/adapters/rdbms/ddl/commands.go b/store/adapters/rdbms/ddl/commands.go index 1263036cf..3dddc849a 100644 --- a/store/adapters/rdbms/ddl/commands.go +++ b/store/adapters/rdbms/ddl/commands.go @@ -40,6 +40,12 @@ type ( Table *Table Column *Column } + + DropColumn struct { + Dialect dialect + Table *Table + Column string + } ) func CreateIndexTemplates(base *CreateIndex, ii ...*Index) []any { @@ -283,6 +289,10 @@ func (c *AddColumn) String() string { return sql } +func (c *DropColumn) String() string { + return "ALTER TABLE" + " " + c.Table.Name + " DROP COLUMN " + c.Column +} + func GetBool(ctx context.Context, db sqlx.QueryerContext, query exp.SQLExpression) (bool, error) { var ( exists bool diff --git a/store/adapters/rdbms/drivers/mysql/schema.go b/store/adapters/rdbms/drivers/mysql/schema.go index 8586f0b0a..22d4d3e58 100644 --- a/store/adapters/rdbms/drivers/mysql/schema.go +++ b/store/adapters/rdbms/drivers/mysql/schema.go @@ -98,6 +98,31 @@ func (s *schema) AddColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table return ddl.Exec(ctx, db, aux...) } +func (s *schema) DropColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table, cc ...string) (err error) { + var ( + aux []any + exists bool + ) + + for _, c := range cc { + // check column existence + if exists, err = s.ColumnExists(ctx, db, c, t.Name); err != nil { + return + } else if !exists { + // column exists + continue + } + + aux = append(aux, &ddl.DropColumn{ + Dialect: dialect, + Table: t, + Column: c, + }) + } + + return ddl.Exec(ctx, db, aux...) +} + func columnTypeTranslator(ct ddl.ColumnType) string { switch ct.Type { case ddl.ColumnTypeIdentifier: diff --git a/store/adapters/rdbms/drivers/postgres/schema.go b/store/adapters/rdbms/drivers/postgres/schema.go index 57dad0d74..409d40c4f 100644 --- a/store/adapters/rdbms/drivers/postgres/schema.go +++ b/store/adapters/rdbms/drivers/postgres/schema.go @@ -66,3 +66,28 @@ func (s *schema) AddColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table return ddl.Exec(ctx, db, aux...) } + +func (s *schema) DropColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table, cc ...string) (err error) { + var ( + aux []any + exists bool + ) + + for _, c := range cc { + // check column existence + if exists, err = s.ColumnExists(ctx, db, c, t.Name); err != nil { + return + } else if !exists { + // column exists + continue + } + + aux = append(aux, &ddl.DropColumn{ + Dialect: dialect, + Table: t, + Column: c, + }) + } + + return ddl.Exec(ctx, db, aux...) +} diff --git a/store/adapters/rdbms/drivers/sqlite/schema.go b/store/adapters/rdbms/drivers/sqlite/schema.go index b84172dbe..0eab23169 100644 --- a/store/adapters/rdbms/drivers/sqlite/schema.go +++ b/store/adapters/rdbms/drivers/sqlite/schema.go @@ -75,6 +75,31 @@ func (s *schema) AddColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table return ddl.Exec(ctx, db, aux...) } +func (s *schema) DropColumn(ctx context.Context, db sqlx.ExtContext, t *ddl.Table, cc ...string) (err error) { + var ( + aux []any + exists bool + ) + + for _, c := range cc { + // check column existence + if exists, err = s.ColumnExists(ctx, db, c, t.Name); err != nil { + return + } else if !exists { + // column exists + continue + } + + aux = append(aux, &ddl.DropColumn{ + Dialect: dialect, + Table: t, + Column: c, + }) + } + + return ddl.Exec(ctx, db, aux...) +} + func columnTypeTranslator(ct ddl.ColumnType) string { switch ct.Type { case ddl.ColumnTypeTimestamp: diff --git a/store/adapters/rdbms/queries.gen.go b/store/adapters/rdbms/queries.gen.go index 9a30c100a..29b0f8383 100644 --- a/store/adapters/rdbms/queries.gen.go +++ b/store/adapters/rdbms/queries.gen.go @@ -1744,11 +1744,8 @@ var ( "name", "label", "options", - "encoding_strategy", - "privacy", - "is_private", + "config", "is_required", - "is_visible", "is_multi", "default_value", "expressions", @@ -1764,24 +1761,21 @@ var ( composeModuleFieldInsertQuery = func(d goqu.DialectWrapper, res *composeType.ModuleField) *goqu.InsertDataset { return d.Insert(composeModuleFieldTable). Rows(goqu.Record{ - "id": res.ID, - "rel_module": res.ModuleID, - "place": res.Place, - "kind": res.Kind, - "name": res.Name, - "label": res.Label, - "options": res.Options, - "encoding_strategy": res.EncodingStrategy, - "privacy": res.Privacy, - "is_private": res.Private, - "is_required": res.Required, - "is_visible": res.Visible, - "is_multi": res.Multi, - "default_value": res.DefaultValue, - "expressions": res.Expressions, - "created_at": res.CreatedAt, - "updated_at": res.UpdatedAt, - "deleted_at": res.DeletedAt, + "id": res.ID, + "rel_module": res.ModuleID, + "place": res.Place, + "kind": res.Kind, + "name": res.Name, + "label": res.Label, + "options": res.Options, + "config": res.Config, + "is_required": res.Required, + "is_multi": res.Multi, + "default_value": res.DefaultValue, + "expressions": res.Expressions, + "created_at": res.CreatedAt, + "updated_at": res.UpdatedAt, + "deleted_at": res.DeletedAt, }) } @@ -1795,23 +1789,20 @@ var ( OnConflict( goqu.DoUpdate(target[1:], goqu.Record{ - "rel_module": res.ModuleID, - "place": res.Place, - "kind": res.Kind, - "name": res.Name, - "label": res.Label, - "options": res.Options, - "encoding_strategy": res.EncodingStrategy, - "privacy": res.Privacy, - "is_private": res.Private, - "is_required": res.Required, - "is_visible": res.Visible, - "is_multi": res.Multi, - "default_value": res.DefaultValue, - "expressions": res.Expressions, - "created_at": res.CreatedAt, - "updated_at": res.UpdatedAt, - "deleted_at": res.DeletedAt, + "rel_module": res.ModuleID, + "place": res.Place, + "kind": res.Kind, + "name": res.Name, + "label": res.Label, + "options": res.Options, + "config": res.Config, + "is_required": res.Required, + "is_multi": res.Multi, + "default_value": res.DefaultValue, + "expressions": res.Expressions, + "created_at": res.CreatedAt, + "updated_at": res.UpdatedAt, + "deleted_at": res.DeletedAt, }, ), ) @@ -1823,23 +1814,20 @@ var ( composeModuleFieldUpdateQuery = func(d goqu.DialectWrapper, res *composeType.ModuleField) *goqu.UpdateDataset { return d.Update(composeModuleFieldTable). Set(goqu.Record{ - "rel_module": res.ModuleID, - "place": res.Place, - "kind": res.Kind, - "name": res.Name, - "label": res.Label, - "options": res.Options, - "encoding_strategy": res.EncodingStrategy, - "privacy": res.Privacy, - "is_private": res.Private, - "is_required": res.Required, - "is_visible": res.Visible, - "is_multi": res.Multi, - "default_value": res.DefaultValue, - "expressions": res.Expressions, - "created_at": res.CreatedAt, - "updated_at": res.UpdatedAt, - "deleted_at": res.DeletedAt, + "rel_module": res.ModuleID, + "place": res.Place, + "kind": res.Kind, + "name": res.Name, + "label": res.Label, + "options": res.Options, + "config": res.Config, + "is_required": res.Required, + "is_multi": res.Multi, + "default_value": res.DefaultValue, + "expressions": res.Expressions, + "created_at": res.CreatedAt, + "updated_at": res.UpdatedAt, + "deleted_at": res.DeletedAt, }). Where(composeModuleFieldPrimaryKeys(res)) } diff --git a/store/adapters/rdbms/rdbms_store.go b/store/adapters/rdbms/rdbms_store.go index 27997e3b3..f6aa8d669 100644 --- a/store/adapters/rdbms/rdbms_store.go +++ b/store/adapters/rdbms/rdbms_store.go @@ -37,6 +37,7 @@ type ( TableExists(context.Context, sqlx.QueryerContext, string) (bool, error) CreateTable(context.Context, sqlx.ExtContext, *ddl.Table) error AddColumn(context.Context, sqlx.ExtContext, *ddl.Table, ...*ddl.Column) error + DropColumn(context.Context, sqlx.ExtContext, *ddl.Table, ...string) error } Store struct { diff --git a/store/adapters/rdbms/upgrade.go b/store/adapters/rdbms/upgrade.go index d21b29240..db509a23c 100644 --- a/store/adapters/rdbms/upgrade.go +++ b/store/adapters/rdbms/upgrade.go @@ -29,6 +29,7 @@ func (s *Store) Upgrade(ctx context.Context) (err error) { fixes := []func(context.Context, *Store) error{ fix202209_extendComposeModuleForPrivacyAndDAL, fix202209_extendComposeModuleFieldsForPrivacyAndDAL, + fix202209_dropObsoleteComposeModuleFields, } for _, fix := range fixes { diff --git a/store/adapters/rdbms/upgrade_fixes.go b/store/adapters/rdbms/upgrade_fixes.go index c8f0b4c96..44eddde7b 100644 --- a/store/adapters/rdbms/upgrade_fixes.go +++ b/store/adapters/rdbms/upgrade_fixes.go @@ -15,11 +15,20 @@ func fix202209_extendComposeModuleForPrivacyAndDAL(ctx context.Context, s *Store } func fix202209_extendComposeModuleFieldsForPrivacyAndDAL(ctx context.Context, s *Store) (err error) { - s.log(ctx).Info("extending compose_module_field table with privacy and encoding_strategy columns") + s.log(ctx).Info("extending compose_module_field table with config column") return s.SchemaAPI.AddColumn( ctx, s.DB, &Table{Name: "compose_module_field"}, - &Column{Type: ColumnType{Type: ColumnTypeJson}, DefaultValue: "'{}'", Name: "privacy"}, - &Column{Type: ColumnType{Type: ColumnTypeJson}, DefaultValue: "'{}'", Name: "encoding_strategy"}, + &Column{Type: ColumnType{Type: ColumnTypeJson}, DefaultValue: "'{}'", Name: "config"}, + ) +} + +func fix202209_dropObsoleteComposeModuleFields(ctx context.Context, s *Store) (err error) { + s.log(ctx).Info("extending compose_module_field table with config column") + return s.SchemaAPI.DropColumn( + ctx, s.DB, + &Table{Name: "compose_module_field"}, + "is_private", + "is_visible", ) } diff --git a/store/adapters/rdbms/upgrade_tables.go b/store/adapters/rdbms/upgrade_tables.go index a8f8987fc..840aac1f0 100644 --- a/store/adapters/rdbms/upgrade_tables.go +++ b/store/adapters/rdbms/upgrade_tables.go @@ -464,15 +464,12 @@ func tableComposeModuleField() *Table { ColumnDef("place", ColumnTypeInteger), ColumnDef("kind", ColumnTypeText), ColumnDef("options", ColumnTypeJson), - ColumnDef("privacy", ColumnTypeJson), - ColumnDef("encoding_strategy", ColumnTypeJson), + ColumnDef("config", ColumnTypeJson), ColumnDef("default_value", ColumnTypeJson), ColumnDef("expressions", ColumnTypeJson), ColumnDef("name", ColumnTypeVarchar, ColumnTypeLength(handleLength)), ColumnDef("label", ColumnTypeText), - ColumnDef("is_private", ColumnTypeBoolean), ColumnDef("is_required", ColumnTypeBoolean), - ColumnDef("is_visible", ColumnTypeBoolean), ColumnDef("is_multi", ColumnTypeBoolean), CUDTimestamps,