go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
37.02k stars 3.94k forks source link

Enhancing GORM: Proposal for Migration Hooks #7227

Open MuhmdHsn313 opened 1 month ago

MuhmdHsn313 commented 1 month ago

Describe the feature

I propose the introduction of migration hooks within GORM, enabling developers to execute custom logic or SQL commands before and after migrations. Hooks such as BeforeMigrate, AfterMigrate ..etc would facilitate handling complex migration scenarios, including the creation of enums, data modifications, and conditional execution of SQL commands based on the existing database state.

Motivation

The current GORM framework offers lifecycle hooks for model events but lacks specific hooks for migrations. This absence can complicate the management of intricate migrations that require additional logic or setup procedures. Implementing migration hooks would provide developers with enhanced flexibility and control over database schema changes, leading to cleaner, more maintainable migration code. Such a feature would significantly improve the usability of GORM in larger projects with complex database architectures.

Related Issues