mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated migration for attributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
8a8fa56797
commit
a3eac846d4
@@ -137,9 +137,6 @@ func (m *Migrator) migrateV2Attributes() (err error) {
|
||||
if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.remV2AttributeProfile(v2Attr.Tenant, v2Attr.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Attributes] += 1
|
||||
}
|
||||
if m.dryRun {
|
||||
@@ -248,7 +245,7 @@ func (v2AttrPrf v2AttributeProfile) AsAttributeProfile() (attrPrf *engine.Attrib
|
||||
for _, attr := range v2AttrPrf.Attributes {
|
||||
filterIDs := make([]string, 0)
|
||||
//append false translate to if FieldName exist do stuff
|
||||
if attr.Append == false {
|
||||
if !attr.Append {
|
||||
filterIDs = append(filterIDs, utils.MetaExists+":"+attr.FieldName+":")
|
||||
}
|
||||
//Initial not *any translate to if value of fieldName = initial do stuff
|
||||
|
||||
@@ -45,6 +45,8 @@ var sTestsAttrIT = []func(t *testing.T){
|
||||
testAttrITConnect,
|
||||
testAttrITFlush,
|
||||
testAttrITMigrateAndMove,
|
||||
testAttrITFlush,
|
||||
testAttrITMigrateV2,
|
||||
}
|
||||
|
||||
func TestAttributeITRedis(t *testing.T) {
|
||||
@@ -291,7 +293,7 @@ func testAttrITMigrateAndMove(t *testing.T) {
|
||||
result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Error("Error when getting Attribute ", err.Error())
|
||||
t.Fatal("Error when getting Attribute ", err.Error())
|
||||
}
|
||||
result.Compile()
|
||||
attrPrf.Compile()
|
||||
@@ -335,3 +337,85 @@ func testAttrITMigrateAndMove(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAttrITMigrateV2(t *testing.T) {
|
||||
if attrAction != utils.Migrate {
|
||||
return
|
||||
}
|
||||
|
||||
v2attr := &v2AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*v2Attribute{
|
||||
&v2Attribute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Substitute: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
|
||||
attrPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:FL1:In1"},
|
||||
FieldName: "FL1",
|
||||
Substitute: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
|
||||
err := attrMigrator.dmIN.setV2AttributeProfile(v2attr)
|
||||
if err != nil {
|
||||
t.Error("Error when setting v1 AttributeProfile ", err.Error())
|
||||
}
|
||||
currentVersion := engine.Versions{utils.Attributes: 2}
|
||||
err = attrMigrator.dmIN.DataManager().DataDB().SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for Attributes ", err.Error())
|
||||
}
|
||||
|
||||
if vrs, err := attrMigrator.dmIN.DataManager().DataDB().GetVersions(""); err != nil {
|
||||
t.Error(err)
|
||||
} else if vrs[utils.Attributes] != 2 {
|
||||
t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes])
|
||||
}
|
||||
|
||||
err, _ = attrMigrator.Migrate([]string{utils.MetaAttributes})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Attributes ", err.Error())
|
||||
}
|
||||
|
||||
if vrs, err := attrMigrator.dmOut.DataManager().DataDB().GetVersions(""); err != nil {
|
||||
t.Error(err)
|
||||
} else if vrs[utils.Attributes] != 3 {
|
||||
t.Errorf("Unexpected version returned: %d", vrs[utils.Attributes])
|
||||
}
|
||||
result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
t.Fatal("Error when getting Attribute ", err.Error())
|
||||
}
|
||||
result.Compile()
|
||||
attrPrf.Compile()
|
||||
if !reflect.DeepEqual(result, attrPrf) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(attrPrf), utils.ToJSON(result))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user