Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4077372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:32:31+00:00 2026-05-20T17:32:31+00:00

I want to create migrations to add columns from my rails application (not through

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:32:32+00:00Added an answer on May 20, 2026 at 5:32 pm

    I have implemented this as below:
    Depending upon the field_name and table_name I create a migration using:

    def create_migration
        field_name_for_db = field_name.gsub(' ', '_').downcase
        migration_name = "add_column_#{self.field_name}_to_#{self.table_name}"
        logger.info "cd #{Rails.root} && rails g migration #{migration_name} #{self.field_name}:string > #{Rails.root}/tmp/migration_details.txt && rake db:migrate"
        system "cd #{Rails.root} && rails g migration #{migration_name} #{self.field_name}:string > #{Rails.root}/tmp/migration_details.txt && rake db:migrate"
        migration_version = File.read("#{Rails.root}/tmp/migration_details.txt").split('/').last.split("_#{migration_name}").first
        self.migration_name = migration_name
        self.migration_version = migration_version
        self.save
      end
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create module which update list of usb devices automatically (not only mass
I want to create a Java application bundle for Mac without using Mac. According
I'm working on a Rails web application with a MySQL database. I'm using migrations
I'm creating a user authentication system for my site. I want to add a
I want to add the current_user.id from devise to another model... question model: class
I have an app running. I want to create a UserNotifications migration that belongs_to
Let's say I create a table in a Rails migration, specifying to omit the
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert
i want create image animation , i have 50 images with png format now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.