We have a SAAS platform written in Rails using the postgres' schema based multitenancy and Apartment gem. The different schemas are identical, with same number of tables and same columns in each table. We want to migrate to foreign key based multitenant system where we want to merge all the records from different schemas into a single schema, identifying each record with a tenant_id. What is the proper way of merging all the records from the different schemas, and preserving the foreign key relationships.
What is the proper way of merging multiple postgres schemas into a single schema preserving the foreign key relationships?
322 Views Asked by Abhishek Bhatta At
1
There are 1 best solutions below
Related Questions in RUBY-ON-RAILS
- Rails HABTM: Select everything a that a record 'has'
- Best way to make an HABTM association via console
- dynamically create an ical / ics file from a rails model
- Ruby destroy is not working? Or objects still present?
- NoMethodError: undefined method `update_average_rating' for nil:NilClass
- Select results where joined table contains records with an attribute, but without another
- Showing posts only created when boolean was true
- Ruby on rails and HAML - Print a hash with background color
- How can I monitor an endpoint's status with Ruby?
- How to create dynamic pages without form_for helper in Rails?
- Rails 4.2 jQuery loads only after refresh
- "Access Denied" - User's Permissions to S3 Bucket
- ActiveRecord, Rails 4: has_many :through with scoped conditions failure
- Rails - formatting a list of options
- Rails - Ajax do not work properly on production server
Related Questions in POSTGRESQL
- Why does adding a JOIN completely modify the query planner behaviour?
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Aggregate and count in PostgreSQL
- Rails HABTM: Select everything a that a record 'has'
- Trigger using data from inserted row
- Select results where joined table contains records with an attribute, but without another
- DB candidate as CouchDB/Schema replacement
- How do I properly add data in SQLAlchemy?
- Postgres in Conda Environment (Ubuntu 14.04)
- How to customize the output of the Postgres Pseudo Encrypt function?
- Split a large query (2 days) into pieces to increase the speed in Postgres
- Why does pg_search prefix not work like I expect?
- extracting meta info from a table psql using information_schema
- How to query a table in the database and copy it's data into one one?
- Update a table using info from a second table and a condition from a third table in Postgresql
Related Questions in MULTI-TENANT
- MultiTenant Application Prevent Tenant Access Data from Other Tenant in Shared Database
- EclipseLink @Multitenant EntityManager/Transaction handling
- django-tenant-schema and domain redirection
- ASP.NET Identity - Filter roles based on company
- Best way to customize CSS for tenants on a multi-tenant app?
- Microsoft Graph API Accessing basic info of a user that is outside tenancy
- How to implement customer subdomain in Spring framework
- Multi-tenant using Aspnet Identity
- Rails apartment with merit gem
- Rails - Redirect to a user's subdomain if it is removed and they are signed in?
- Multitenant scoping using Pundit
- Entity Framework Multi-Tenancy with ASP.NET Identity
- Mongoose and Node.js multi tenant architecture
- Solutions for a Multi-Tenant Platform using Django with Postgresql
- One database per client or all clients in one database?
Related Questions in APARTMENT-GEM
- How can I setup Minitest fixtures to test Apartment using postgres schemas
- Best way to customize CSS for tenants on a multi-tenant app?
- Rails apartment with merit gem
- Why is apartment-sidekiq not finding the tenant?
- two sessions creating in rails devise with apartment gem
- Devise: Login user and redirect to subdomain
- Apartment ruby gem : Want to Catch an exception
- Change response URL on Rails server
- How to redirect user after registration in apartment gem
- How to define seed file for Rails Apartment
- Postgresql Schema not found after moving to Amazon AWS
- Rake task to migrate tenants on their schema's on multiple darabases
- ActiveStorage with Apartment gem only checks public schema to load files instead of tenant schema
- Action cable in rails application with subdomain - apartment gem isn't working
- Making a request to an ActiveStorage resource fails occasionally when used alongside Apartment gem
Related Questions in ACTS-AS-TENANT
- How to configure acts_as_tenant gem with ActionCable in rails7
- Set Multi Tenant in Active Admin Controllers (required for Searchkick index)
- Citus "create_distributed_table" giving "PG::UndefinedColumn"
- Multitenancy (Acts as Tenant gem): How to delete a tenant?
- Rails Devise how to set confirmation_url if using Tenants
- Devise and ActsAsTenant not playing nicely together
- activerecord-multi-tenant / acts_as_tenant and Active Admin
- Scoping Account model with acts_as_tenant?
- multi-tenant rails app user-account relationship issue
- Tweaking scoping rules as part of acts_as_tenant?
- Rails Acts As Tenant error using current_tenant in controller
- Extending gem/engine models to include acts_as_tenant from main app
- acts as tenant gem scopes all users data, ignoring scoping data based on the subdomain
- Rails acts as tenant getting nil in model on Heroku
- What is the proper way of merging multiple postgres schemas into a single schema preserving the foreign key relationships?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
This is a situation that will need care. I think (I could be wrong) that the best approach is to add to all tables
tenant_idandoriginal_id... before attempting migration populateoriginal_idin all tables withidof that record. Essentially this is to have a record of what the value ofidwas before the merging.After merge you can then run a rake task that rebuilds the associations. So if you had...
Your migration script would do (after migration)
You'd need to do something similar for every relation, so it's a bit of a slog.
Hopefully, someone else will come up with a better solution.
NOTE THIS IS NOT IDEMPOTENT. If it errors, you can't restart it except by redoing the merging completely.