trilium/db/migrations/0160__attr_def_short.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

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:%'")) {
const obj = JSON.parse(attr.value);
const tokens = [];
if (obj.isPromoted) {
tokens.push('promoted');
}
if (obj.multiplicityType === 'singlevalue') {
tokens.push('single');
} else if (obj.multiplicityType === 'multivalue') {
tokens.push('multi');
}
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:%'")) {
const obj = JSON.parse(attr.value);
const tokens = [];
if (obj.isPromoted) {
tokens.push('promoted');
}
if (obj.multiplicityType === 'singlevalue') {
tokens.push('single');
} else if (obj.multiplicityType === 'multivalue') {
tokens.push('multi');
}
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]);
}
};