Should I use multiple databases?

I am going to create an application with Ruby on Rails, and I would like to use several databases, basically this is an accounting application that will have several companies for each user. I would like to create a database for each company

I found this post http://programmerassist.com/article/302 But I would like to read more thoughts about this issue. I have to decide between MySQL and PosgreSQL which database can best fit my problem.

+3
source share
4 answers

There are several options for handling an application with multiple tenants.

First, you can add a region to your tables (as suggested by Chad Birch - using company_id). For most use cases, this is normal. If you process sensitive data (such as credentials), you must be very careful in your testing to ensure data privacy.

. , , . , . . (capistrano, chef, puppet ..) . , , .

PostgreSQL, - . PostgresQL . , , , . , .

Rails , .

- :

before_filter :set_app

def set_app
  current_app = App.find_by_subdomain(...)
  schema = current_app.schema

  set_schema_path(schema)
end 


def set_schema_path(schema)
  connection = ActiveRecord::Base.connection
  connection.execute("SET search_path TO #{schema}, #{connection.schema_search_path}")
end

def  reset_schema_path
  connection = ActiveRecord::Base.connection
  connection.execute("SET search_path TO #{connection.schema_search_path}")
end
+6

, , . , , , , . http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html

Ruby on Rails Postgresql.

( ) - SaaS. , , - . . - () . -, , . . , .. , . . , - , ( ). - . . . .

, COBOL ISAM CGI. , : a) , COBOL , b) , c) d) -. , .

, , , .

+1

, PostgreSQL, . , , .

# app/models/organisation.rb
class Organisation < ActiveRecord::Base
  self.table_name = 'common.organisations'
  # set relationships as usual
end

# app/models/user.rb    
class User < ActiveRecord::Base
  self.table_name = 'common.users'
  # set relationships as usual
end

. http://timnew.github.com/blog/2012/07/17/use-postgres-multiple-schema-database-in-rails/ , , , , , railscasts.

, . , , , , , .

0

, .

, , , , , .

, , " " , , .

-1

Source: https://habr.com/ru/post/1736222/


All Articles