Fix RDBMS upgrade procedures
This commit is contained in:
@@ -82,9 +82,17 @@ func createTablesFromModels(ctx context.Context, log *zap.Logger, dd ddl.DataDef
|
||||
return nil
|
||||
}
|
||||
|
||||
// addColumn adds column on a table but only if table exists!
|
||||
//
|
||||
// If table does not exist adding column can be skipped
|
||||
// We can assume that 2nd step of the upgrade process will include the column
|
||||
func addColumn(ctx context.Context, s *Store, table string, attr *dal.Attribute) error {
|
||||
tbl, err := s.DataDefiner.TableLookup(ctx, table)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -102,9 +110,17 @@ func addColumn(ctx context.Context, s *Store, table string, attr *dal.Attribute)
|
||||
return s.DataDefiner.ColumnAdd(ctx, table, col)
|
||||
}
|
||||
|
||||
// dropColumns removes columns from a table but only if table exists!
|
||||
//
|
||||
// If table does not exist column removing can be skipped
|
||||
// We can assume that 2nd step of the upgrade process will omit the column
|
||||
func dropColumns(ctx context.Context, s *Store, table string, cc ...string) error {
|
||||
tbl, err := s.DataDefiner.TableLookup(ctx, table)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -122,9 +138,17 @@ func dropColumns(ctx context.Context, s *Store, table string, cc ...string) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// renameColumn renames columns from a table but only if table exists!
|
||||
//
|
||||
// If table does not exist column renaming can be skipped
|
||||
// We can assume that 2nd step of the upgrade process will have columns properly nameed
|
||||
func renameColumn(ctx context.Context, s *Store, table string, from, to string) error {
|
||||
tbl, err := s.DataDefiner.TableLookup(ctx, table)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/cortezaproject/corteza-server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza-server/pkg/errors"
|
||||
labelsType "github.com/cortezaproject/corteza-server/pkg/label/types"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"go.uber.org/zap"
|
||||
@@ -26,6 +27,7 @@ var (
|
||||
fix_2022_09_00_extendDalConnectionsForMeta,
|
||||
fix_2022_09_00_renameModuleColOnComposeRecords,
|
||||
fix_2022_09_00_addMetaOnComposeRecords,
|
||||
fix_2022_09_00_addMissingNodeIdOnFederationMapping,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -38,7 +40,7 @@ func fix_2022_09_00_extendComposeModuleForPrivacyAndDAL(ctx context.Context, s *
|
||||
|
||||
func fix_2022_09_00_extendComposeModuleFieldsForPrivacyAndDAL(ctx context.Context, s *Store) (err error) {
|
||||
return addColumn(ctx, s,
|
||||
"compose_module",
|
||||
"compose_module_field",
|
||||
&dal.Attribute{Ident: "config", Type: &dal.TypeJSON{DefaultValue: "{}"}},
|
||||
)
|
||||
}
|
||||
@@ -70,6 +72,14 @@ func fix_2022_09_00_addMetaOnComposeRecords(ctx context.Context, s *Store) (err
|
||||
packed []byte
|
||||
)
|
||||
|
||||
_, err = s.DataDefiner.TableLookup(ctx, "labels")
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
err = addColumn(ctx, s,
|
||||
"compose_record",
|
||||
&dal.Attribute{Ident: "meta", Type: &dal.TypeJSON{DefaultValue: "{}"}},
|
||||
@@ -110,5 +120,11 @@ func fix_2022_09_00_addMetaOnComposeRecords(ctx context.Context, s *Store) (err
|
||||
return
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func fix_2022_09_00_addMissingNodeIdOnFederationMapping(ctx context.Context, s *Store) (err error) {
|
||||
return addColumn(ctx, s,
|
||||
"federation_module_mapping",
|
||||
&dal.Attribute{Ident: "node_id", Type: &dal.TypeID{}},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user