0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-23 20:33:16 -05:00
logto/packages/schemas/alterations/1.2.0-1681267285-fix-get-started-passwordless-status.ts
2023-04-18 21:13:31 +08:00

32 lines
1 KiB
TypeScript

import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
const adminConsoleConfigKey = 'adminConsole';
const alteration: AlterationScript = {
up: async (pool) => {
const tenantIds = await pool.many<{ id: string }>(sql`select id from tenants`);
await Promise.all(
tenantIds.map(async ({ id }) => {
const { count } = await pool.one<{ count: number }>(sql`
select count(*) from connectors
where tenant_id = ${id} and connector_id <> 'logto-sms' and connector_id <> 'logto-email' and connector_id <> 'logto-social-demo';
`);
if (count > 0) {
await pool.query(sql`
update logto_configs set value = jsonb_set(value, '{passwordlessConfigured}', 'true')
where tenant_id = ${id} and key = ${adminConsoleConfigKey};
`);
}
})
);
},
down: async () => {
// Do nothing as there is no alteration made to the DB schemas, only fixing data.
},
};
export default alteration;