'use strict';

exports.up = async function (db) {
    const allApps = await db.runSql('SELECT * FROM apps');

    for (const app of allApps) {
        const manifest = JSON.parse(app.manifestJson);
        // assume apps only have one of them
        if (manifest.addons?.oidc) {
            await db.runSql('UPDATE oidcClients SET id=? WHERE id=?', [ `${app.id}-oidc`, app.id ]);
        } else if (manifest.addons?.proxyAuth) {
            await db.runSql('UPDATE oidcClients SET id=? WHERE id=?', [ `${app.id}-proxyauth`, app.id ]);
        }
    }
};

exports.down = async function (db) {
};
