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

  • SEARCH
  • Home
  • 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 3753612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:25:07+00:00 2026-05-19T09:25:07+00:00

I’m writing a SaaS model application. My application database consist of two logic parts:

  • 0

I’m writing a SaaS model application.
My application database consist of two logic parts:

  • application tables – such as user, roles…
  • user-defined tables (he can generate them from UI level) that can be different for each application instance

All tables are created by rails migrations mechanism.

I would like to put user-defined tables in another directory:

  • db/migrations – application tables
  • db/migrations/custom – tables generated by user

so I can do svn:ignore on db/migrations/custom, and when I do updates of my app on clients servers it would only update application tables migrations.

Is there any way to achieve this in rails?

  • 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-19T09:25:07+00:00Added an answer on May 19, 2026 at 9:25 am

    @Vasily thank’s for your response. After reading it and couple more questions from stackoverflow I came up with this solution:

    Since I write my own generator to create user tables I included Rails::Generators::Migration in it so I can override next_migration_number method like this:

    def self.next_migration_number(dirname)
     if ActiveRecord::Base.timestamped_migrations
       Time.now.utc.strftime("custom/%Y%m%d%H%M%S")
     else
       "custom/%.3d" % (current_migration_number(dirname) + 1)
     end
    end
    

    Now all migrations generated by user are created in db/migrations/custom directory.

    Then I wrote normal rails migration that executes all migrations from db/migrations/custom directory:

    class ExecuteCustomMigrations < ActiveRecord::Migration
       MIGRATIONS_PATH='db/migrate/custom'
       def self.up
         Dir["#{MIGRATIONS_PATH}/[0-9]*_*.rb"].
         sort.map{|filename|require filename}.flatten.
         each{|class_name| const_get(class_name).up}
       end
    
       def self.down
         Dir["#{MIGRATIONS_PATH}/[0-9]*_*.rb"].sort.reverse.
         map{|filename|require filename}.flatten.
         each{|class_name| const_get(class_name).down}
       end
    end
    

    After user creates custom table i call this migration with this code:

    Rake::Task["db:migrate:redo"].execute("VERSION=20110108213453")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.