Please Install Ruby on Rails on your machines using RVM. Below commands work in Ubuntu O.S.
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ sudo apt-get install curl
$ \curl -sSL https://get.rvm.io | bash -s stable --rails$ ruby --version
$ rails --versionNOTE: Make Sure MySQL is there on your system
Run the below commands (LINUX USERS)
$ git clone git@github.com:navpreetsingh/multi_tenant_architecture.git
$ cd multi_tenant_architecture
$ gem install bundler
$ bundle installRun the below commands (WINDOWS USERS)
C:\users> git clone git@github.com:navpreetsingh/multi_tenant_architecture.git
C:\users> cd multi_tenant_architecture
C:\users> gem install bundler
C:\users> bundle installNOTE: Change the password in file /config/database.yml with your local mysql password.
$ rake db:createThis will create a db in MySQL with name 'dummy'.
$ rake db:migrateThis will create a table 'users' in db 'dummy'
$ RAILS_ENV=dev_server_1 rake db:create
$ RAILS_ENV=dev_server_2 rake db:create
$ RAILS_ENV=dev_server_3 rake db:createThis will create a 3 db's in MySQL with name 'dummy_1', 'dummy_2' & 'dummy_3'.
$ RAILS_ENV=dev rake db:mass_migrationThis will create a table 'users' in all db's
NOTE: Copy a file in folder '/db' with name '20161017055930_add_address_table.rb' to folder '/db/migrate'. This is a migration file.
$ rake db:migrateThis will create a table 'addresses' in db 'dummy'
$ RAILS_ENV=dev rake db:mass_migrationThis will create a table 'addresses' in all db's
NOTE: Change a line in file '/config/database.yml'
dev_count: 3TO
dev_count: 4This change will identify 1 more db in mass_migration. You can see the key 'dev_server_4' having details of the db. You can add more db's in same format and changing the dev_count in given file above.
Run Below commands to create new db
$ RAILS_ENV=dev_server_4 rake db:createNew DB has been created with name 'dummy_4'
$ RAILS_ENV=dev rake db:mass_migrationNew DB has been populated with tables 'users' & 'addresses'
Find it as suitable option to handle migrations on multiple db's across different environments, we can do much more
UBUNTU USERS install graphviz
$ sudo apt-get install graphvizCreate Schema diagram by running below commmands
$ bundle exec erd
$ rake diagram:allCheck the schema diagram in files => '/erd.pdf' => '/doc/models_complete.svg'