Always store slug for Services? #981
Answered
by
JustinBack
michielbdejong
asked this question in
Ideas
Replies: 2 comments
-
Thanks for the code, I'll only update slugs with null values and make sure to use the same system as the ruby code above |
Beta Was this translation helpful? Give feedback.
0 replies
-
const { Client } = require('pg');
const dotenv = require('dotenv');
dotenv.config();
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
});
client.connect();
client.query('SELECT * FROM services WHERE slug is null', (err, res) => {
if (err) throw err;
for (let service of res.rows) {
let slug = (service.slug || service.name.split(' ').join('').split('.').join('-').split('/').join('_').toLowerCase());
console.log("Generated slug for", service.name, "-", slug);
client.query('UPDATE services SET slug = $1 WHERE ID = $2', [slug, service.id], (err, res) => {
if (err) throw err;
console.log("Service slug updated!")
});
}
}); Code above which uses the same system as ruby :-) Worked perfectly. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JustinBack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We use the Service slug in edit.tosdr.org to determine the filename in tosdr.org.
Sometimes, it's stored explicitly in postgres, sometimes it's inferred on the fly, see:
https://github.com/tosdr/edit.tosdr.org/blob/master/db/export_services_to_old_db.rb#L18
@JustinBack do you also need the slug for beta.tosdr.org? You asked if it makes sense to just always store the slug in the database, so the code for export / API becomes simpler.
Sure, go for it! Just make sure that you use that existing code to generate the slug you store, otherwise the export script will create duplicate services (one with the old slug that was generated on-the-fly, and one with the new slug which you stored explicitly).
Beta Was this translation helpful? Give feedback.
All reactions