n8n/packages/cli/src/databases/migrations/postgresdb/1717498465931-AddActivatedAtUserSetting.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
708 B
TypeScript
Raw Normal View History

import type { MigrationContext, ReversibleMigration } from '@db/types';
export class AddActivatedAtUserSetting1717498465931 implements ReversibleMigration {
async up({ queryRunner, escape }: MigrationContext) {
const now = Date.now();
await queryRunner.query(
`UPDATE ${escape.tableName('user')}
SET settings = jsonb_set(COALESCE(settings::jsonb, '{}'), '{userActivatedAt}', to_jsonb(${now}))
WHERE settings IS NOT NULL AND (settings->>'userActivated')::boolean = true`,
);
}
async down({ queryRunner, escape }: MigrationContext) {
await queryRunner.query(
`UPDATE ${escape.tableName('user')} SET settings = settings::jsonb - 'userActivatedAt' WHERE settings IS NOT NULL`,
);
}
}