I want to create migrations to add columns from my rails application (not through rails g migration xxxx), while creating the migration I want to store the version number to the for the migration for later possible down operation.
The scenario is, I have an application with generalized tables and their fields. The application can be deployed for multiple customers. I want to provide a way to define custom fields in the table. Once the user selects/inputs desired data like table_name, field_name, data_type etc. I will be creating a new migration to add the field and store the version number somewhere in the database. This version number will be used to migrate:down in case the user decides to delete the field.
Is there any other better approach than this?
I have implemented this as below:
Depending upon the
field_nameandtable_nameI create a migration using:In this method I have redirected the output of create migration command to a file and retrieving migration number from the file and then storing it to the database.