Tarantool existing space migration - migration

I need to add a parameter to existing space and keep the existing data.
space is created like this:
function create_user()
local space = box.schema.create_space('user', { engine = 'memtx' })
space:format({
{ name = 'user_id', type = 'unsigned' },
{ name = 'name', type = 'string' },
{ name = 'is_active', type = 'boolean' },
})
space:create_index('users_id', { type = 'TREE', parts = { 'user_id', 'name' } })
end
i need to add the following parameters
{ name = 'is_online', type = 'boolean' }
{ name = 'session_id', type = 'unsigned', is_nullable = true }
how to write the required migration script?

it's my solution
function migrate_users()
local counter = 0
local space = box.space.users
space:format({})
for _, tuple in space:pairs(
nil, {iterator=box.index.ALL}
) do
local user_tuple = tuple:totable()
user_tuple[4] = nil
user_tuple[5] = false
space:replace(user_tuple)
counter = counter + 1
if counter % 10000 == 0 then
fiber.sleep(0)
end
end
space:format({
{ name = 'user_id', type = 'unsigned' },
{ name = 'name', type = 'string' },
{ name = 'is_active', type = 'boolean' },
{ name = 'session_id', type = 'unsigned', is_nullable = true },
{ name = 'is_online', type = 'boolean' }
})
space:create_index('session_id', { type = 'TREE', unique = false, parts = { 'session_id' } })
end

it is better to use spacer immediately
https://github.com/igorcoding/tarantool-spacer

Related

Looping over map variable using for_each expression in terraform

I have variable that I want to iterate over using for_each in terraform to create multiple instances of submodule - node_groups, which is part of eks module. This is my variable:
variable "frame_platform_eks_node_groups" {
type = map
default = {
eks_kube_system = {
desired_capacity = 1,
max_capacity = 5,
min_capacity = 1,
instance_type = ["m5.large"],
k8s_label = "eks_kube_system",
additional_tags = "eks_kube_system_node"
},
eks_jenkins_build = {
desired_capacity = 1,
max_capacity = 10,
min_capacity = 1,
instance_type = ["m5.large"],
k8s_label = "eks_jenkins_build",
additional_tags = "eks_jenkins_build_node"
}
}
}
And this is my node_groups submodule, which is part of module eks.
module "eks" {
...
node_groups = {
for_each = var.frame_platform_eks_node_groups
each.key = {
desired_capacity = each.value.desired_capacity
max_capacity = each.value.max_capacity
min_capacity = each.value.min_capacity
instance_types = each.value.instance_type
k8s_labels = {
Name = each.value.k8s_label
}
additional_tags = {
ExtraTag = each.value.additional_tags
}
}
When I run terraform plan I am getting following error:
15: each.key = {
If this expression is intended to be a reference, wrap it in parentheses. If
it’s instead intended as a literal name containing periods, wrap it in quotes
to create a string literal.
My intention obviously is to get eks_kube_system and eks_jenkins_build values from the map variable with each.key reference. But something is wrong. Do you have advice what I am doing wrong?
Thank you!
Its not exactly clear what node_groups is as it is not defined in your question, but assuming that it is a list of maps, then the code should be:
module "eks" {
...
node_groups = [
for k,v in var.frame_platform_eks_node_groups:
{
desired_capacity = v.desired_capacity
max_capacity = v.max_capacity
min_capacity = v.min_capacity
instance_types = v.instance_type
k8s_labels = {
Name = v.k8s_label
}
additional_tags = {
ExtraTag = v.additional_tags
}
}
]

Assert ONLY json .Net Object attributes name without values

Is that possible to assert just the json attribute names rather than values.
Actual:
{
CartId = 0
ConvertedAt = null
Currency = BankCurrency
{
BaseCurrencyCode = null
BaseToGlobalRate = 0
BaseToQuoteRate = 0
GlobalCurrencyCode = null
}
CustomerIsGuest = False
}
Expected :
{
CartId = 418
ConvertedAt = 2019-07-22 04:01:49
Currency = BankCurrency
{
BaseCurrencyCode = null
BaseToGlobalRate = 1
BaseToQuoteRate = 1
GlobalCurrencyCode = "AUD"
}
CustomerIsGuest = False
}
So when compare above both actual and expected should tally.
Basically I wanted to compare above json .Net objects and check attribute names (structure) is correct rather than attribute values in there. If you see above actual and expected structure is tallying but not the values inside. I have used below but it still complaining.
TheReturnedContentModelIs(new UserResponse())
Validation:
public async Task TheReturnedContentModelIs<T>(T expected)
{
var responseString = await ResponseMessage.Content.ReadAsStringAsync();
var actual = JsonConvert.DeserializeObject<T>(responseString);
actual.Should()
.BeEquivalentTo(expected,
opt => opt.Using<object>(_ => { })
.When(e => e.RuntimeType.IsValueType)
.Using<string>(_ => { })
.WhenTypeIs<string>());

Importing a contact column into Podio

Which app_id should be used for importing into a contact column? Also, what should the mappings parameter look like?
podio.ImporterService.ImportAppItems(fileId, appId, new List<ImportMappingField> {
new ImportMappingField { FieldId = primaryFieldId, Unique = false, Value = new { column_id = "0" }},
new ImportMappingField { FieldId = contactfieldId, Unique = false, Value = new { column_id = "1", app_id = ???, mappings = new []{ ??? }}}
})
Edit:
I figured it out. Below is an example that works for me.
podio.ImporterService.ImportAppItems(373063497, 18803129, new List<ImportMappingField> {
new ImportMappingField {
FieldId = 148580608,
Unique = false,
Value = new { column_id = "0" }
},
new ImportMappingField {
FieldId = 148580614,
Unique = false,
Value = new {
mappings = new []{
new {
field_key = "mail",
unique = "true",
column_id = "4"
}
}
}
}
});
See the API documentation [1]
[1] https://developers.podio.com/doc/contacts

lodash : add a new field during a ._map

I have an array of objects of that type:
response.data = [{Name = "name1", Type = "text"}, {Name = "name2", Type = "text"}...]
I am trying to do add and initiate a property to all objects.
I tried:
var newObj = _.map([response.data], function (value) {
return {
value: "property : " + value.Name ,
type: "my type is : " + value.Type,
active : false
};
});
But it does not add the property
Do you know how to do this with lodash?
Because lodash map takes in input as first argument a collection. Your response.data is already a collection and you are wrapping it inside another array ([response.data]).
To fix it, avoid to wrap it:
var newObj = _.map(response.data, function (value) {
return {
value: "property : " + value.Name,
type: "my type is : " + value.Type,
active: false
};
});
Please, consider that JavaScript Array natively has map method, so you do not need lodash. You can write your piece of code in the following way:
var newObj = response.data.map(function (value) {
return {
value: "property : " + value.Name,
type: "my type is : " + value.Type,
active: false
};
});
var newObj = _.map(response.data, function (value) {
return {
value: "property : " + value.Name ,
type: "my type is : " + value.Type,
active : false
};
});

Filter dictionary array with multiple value

(
{
iReplyId = 3870;
name = rahul;
},
{
iReplyId = 3914;
name = Tom;
},
{
iReplyId = 3873;
name = Smith;
},
{
iReplyId = 3871;
name = yator;
},
{
iReplyId = 3872;
name = jack;
},
{
iReplyId = 3875;
name = smith;
},
{
iReplyId = 3876;
name = rancho;
},
{
iReplyId = 3878;
name = vid;
},
)
My requirement is to filter this array with multiple condtion like iReplyId = 3871,3870,3914 by using nspredicate. i tried so much but but i didn't get the solution with predicate, i can solve this by using for loop but that is not a good way.
Any help is highly appreciated.
[array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"iReplyId IN (%#)",[idsArray componentsJoinedByString:#","]]]