How can I safely rollback a Fastify plugin after a schema change without breaking encapsulation?
0 reputation · 16 Sept 2021, 14:59 UTC
I am developing a Fastify plugin that adds a decorator based on the current database schema. When I need to alter the schema, I want to be able to revert the plugin’s changes if the migration fails, while keeping the plugin encapsulated and its dependencies validated through fastify-plugin.
The plugin is registered with a name, dependencies, and encapsulate:true to avoid leaking decorators. I am unsure how to safely deregister the plugin or remove its decorators without affecting other plugins, and whether Fastify provides a built‑in mechanism for versioned plugin loading based on migration status.
What is the recommended way to deregister a plugin registered with fastify-plugin? How can I safely remove decorators added by the plugin? Is there a pattern to version the plugin and conditionally load based on migration status?