Add (and refactor) RDBMS fix for values, revision and meta column
This commit is contained in:
5
compose/model/models.gen.go
generated
5
compose/model/models.gen.go
generated
@@ -769,7 +769,10 @@ var Record = &dal.Model{
|
||||
|
||||
&dal.Attribute{
|
||||
Ident: "Revision",
|
||||
Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}},
|
||||
Type: &dal.TypeNumber{HasDefault: true,
|
||||
DefaultValue: 0,
|
||||
Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"},
|
||||
},
|
||||
Store: &dal.CodecAlias{Ident: "revision"},
|
||||
},
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ record: {
|
||||
id: schema.IdField
|
||||
revision: {
|
||||
goType: "uint"
|
||||
dal: { type: "Number", meta: { "rdbms:type": "integer" } }
|
||||
dal: { type: "Number", meta: { "rdbms:type": "integer" }, default: 0 }
|
||||
}
|
||||
module_id: {
|
||||
ident: "moduleID",
|
||||
|
||||
@@ -34,7 +34,9 @@ func DeleteModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error)
|
||||
// UpdateModel alters existing table's columns and indexes to match Model definition
|
||||
func UpdateModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error) {
|
||||
var (
|
||||
t *Table
|
||||
t *Table
|
||||
col *Column
|
||||
colIdent string
|
||||
)
|
||||
|
||||
if t, err = dd.TableLookup(ctx, m.Ident); err != nil {
|
||||
@@ -44,7 +46,8 @@ func UpdateModel(ctx context.Context, dd DataDefiner, m *dal.Model) (err error)
|
||||
// @todo check model against table structure
|
||||
for _, attr := range m.Attributes {
|
||||
// iterate over attributes and check if they exist in the table
|
||||
col := t.ColumnByIdent(attr.StoreIdent())
|
||||
colIdent = attr.StoreIdent()
|
||||
col = t.ColumnByIdent(colIdent)
|
||||
if col != nil {
|
||||
// @todo check if column type matches
|
||||
// @todo check if column is nullable
|
||||
|
||||
@@ -3,6 +3,7 @@ package rdbms
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/cortezaproject/corteza-server/compose/model"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza-server/pkg/errors"
|
||||
labelsType "github.com/cortezaproject/corteza-server/pkg/label/types"
|
||||
@@ -26,6 +27,8 @@ var (
|
||||
fix_2022_09_00_dropObsoleteComposeModuleFields,
|
||||
fix_2022_09_00_extendDalConnectionsForMeta,
|
||||
fix_2022_09_00_renameModuleColOnComposeRecords,
|
||||
fix_2022_09_00_addValuesOnComposeRecords,
|
||||
fix_2022_09_00_addRevisionOnComposeRecords,
|
||||
fix_2022_09_00_addMetaOnComposeRecords,
|
||||
fix_2022_09_00_addMissingNodeIdOnFederationMapping,
|
||||
}
|
||||
@@ -64,6 +67,20 @@ func fix_2022_09_00_renameModuleColOnComposeRecords(ctx context.Context, s *Stor
|
||||
return renameColumn(ctx, s, "compose_record", "module_id", "rel_module")
|
||||
}
|
||||
|
||||
func fix_2022_09_00_addValuesOnComposeRecords(ctx context.Context, s *Store) (err error) {
|
||||
return addColumn(ctx, s,
|
||||
"compose_record",
|
||||
model.Record.Attributes.FindByIdent("Values"),
|
||||
)
|
||||
}
|
||||
|
||||
func fix_2022_09_00_addRevisionOnComposeRecords(ctx context.Context, s *Store) (err error) {
|
||||
return addColumn(ctx, s,
|
||||
"compose_record",
|
||||
model.Record.Attributes.FindByIdent("Revision"),
|
||||
)
|
||||
}
|
||||
|
||||
func fix_2022_09_00_addMetaOnComposeRecords(ctx context.Context, s *Store) (err error) {
|
||||
var (
|
||||
log = s.log(ctx)
|
||||
@@ -82,7 +99,7 @@ func fix_2022_09_00_addMetaOnComposeRecords(ctx context.Context, s *Store) (err
|
||||
|
||||
err = addColumn(ctx, s,
|
||||
"compose_record",
|
||||
&dal.Attribute{Ident: "meta", Type: &dal.TypeJSON{DefaultValue: "{}"}},
|
||||
model.Record.Attributes.FindByIdent("Meta"),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user