2020-07-01 05:37:06 +08:00
|
|
|
const sql = require('../../src/services/sql');
|
|
|
|
|
|
|
|
module.exports = () => {
|
|
|
|
for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'label:%'")) {
|
2020-08-27 18:44:49 +08:00
|
|
|
let obj;
|
|
|
|
|
|
|
|
try {
|
|
|
|
obj = JSON.parse(attr.value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`);
|
|
|
|
|
|
|
|
sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?',
|
|
|
|
["multi,text", attr.attributeId]);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-01 05:37:06 +08:00
|
|
|
|
|
|
|
const tokens = [];
|
|
|
|
|
|
|
|
if (obj.isPromoted) {
|
|
|
|
tokens.push('promoted');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.multiplicityType === 'singlevalue') {
|
|
|
|
tokens.push('single');
|
|
|
|
} else if (obj.multiplicityType === 'multivalue') {
|
|
|
|
tokens.push('multi');
|
|
|
|
}
|
|
|
|
|
2020-07-19 05:45:28 +08:00
|
|
|
if (obj.labelType) {
|
|
|
|
tokens.push(obj.labelType);
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:37:06 +08:00
|
|
|
if (obj.numberPrecision) {
|
|
|
|
tokens.push('precision='+obj.numberPrecision);
|
|
|
|
}
|
|
|
|
|
|
|
|
const newValue = tokens.join(',');
|
|
|
|
|
|
|
|
sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', [newValue, attr.attributeId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'relation:%'")) {
|
2020-08-27 18:44:49 +08:00
|
|
|
let obj;
|
|
|
|
|
|
|
|
try {
|
|
|
|
obj = JSON.parse(attr.value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`);
|
|
|
|
|
|
|
|
sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?',
|
|
|
|
["multi", attr.attributeId]);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-01 05:37:06 +08:00
|
|
|
|
|
|
|
const tokens = [];
|
|
|
|
|
|
|
|
if (obj.isPromoted) {
|
|
|
|
tokens.push('promoted');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj.multiplicityType === 'singlevalue') {
|
|
|
|
tokens.push('single');
|
|
|
|
} else if (obj.multiplicityType === 'multivalue') {
|
|
|
|
tokens.push('multi');
|
|
|
|
}
|
|
|
|
|
2020-07-19 05:45:28 +08:00
|
|
|
if (obj.inverseRelation) {
|
|
|
|
tokens.push('inverse=' + obj.inverseRelation);
|
|
|
|
}
|
|
|
|
|
2020-07-01 05:37:06 +08:00
|
|
|
const newValue = tokens.join(',');
|
|
|
|
|
|
|
|
sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?', [newValue, attr.attributeId]);
|
|
|
|
}
|
|
|
|
};
|