Skip to main content

Function: useSchemaMigration()

useSchemaMigration(): UseMutationResult<MigrationSuccess, SchemaMigrationError, MigrateRecordParams, unknown>

Defined in: web/lib/hooks/use-schema-migration.ts:161

Hook for migrating eprint records to the current schema.

Returns

UseMutationResult<MigrationSuccess, SchemaMigrationError, MigrateRecordParams, unknown>

Mutation object with migrateRecord, loading state, and error

Remarks

This hook handles the complete migration flow:

  1. Validates the user is authenticated
  2. Fetches the current record from the PDS
  3. Transforms deprecated fields using schema migration utilities
  4. Updates the record in the PDS via putRecord
  5. Invalidates relevant queries to refresh the UI

The mutation requires the user to be the record owner (same DID).

Example

const { mutate: migrateRecord, isPending, error, isSuccess } = useSchemaMigration();

const handleMigrate = async () => {
try {
await migrateRecord({ uri: eprint.uri });
toast.success('Record updated to latest format');
} catch (error) {
toast.error('Failed to update record');
}
};

return (
<Button onClick={handleMigrate} disabled={isPending}>
{isPending ? 'Updating...' : 'Update to Latest Format'}
</Button>
);