mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 03:37:40 +00:00
setups script
This commit is contained in:
parent
fefd17ae74
commit
cbba4fe384
96
Pearlception/apartment_copy.rb
Normal file
96
Pearlception/apartment_copy.rb
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# You can have Apartment route to the appropriate Tenant by adding some Rack middleware.
|
||||||
|
# Apartment can support many different "Elevators" that can take care of this routing to your data.
|
||||||
|
# Require whichever Elevator you're using below or none if you have a custom one.
|
||||||
|
#
|
||||||
|
# require 'apartment/elevators/generic'
|
||||||
|
# require 'apartment/elevators/domain'
|
||||||
|
require 'apartment/elevators/subdomain'
|
||||||
|
# require 'apartment/elevators/first_subdomain'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apartment Configuration
|
||||||
|
#
|
||||||
|
Apartment.configure do |config|
|
||||||
|
|
||||||
|
# Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
|
||||||
|
# A typical example would be a Customer or Tenant model that stores each Tenant's information.
|
||||||
|
#
|
||||||
|
config.excluded_models = [ "User", "Company" ]
|
||||||
|
|
||||||
|
# In order to migrate all of your Tenants you need to provide a list of Tenant names to Apartment.
|
||||||
|
# You can make this dynamic by providing a Proc object to be called on migrations.
|
||||||
|
# This object should yield either:
|
||||||
|
# - an array of strings representing each Tenant name.
|
||||||
|
# - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
|
||||||
|
#
|
||||||
|
# config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
|
||||||
|
# config.tenant_names = ['tenant1', 'tenant2']
|
||||||
|
# config.tenant_names = {
|
||||||
|
# 'tenant1' => {
|
||||||
|
# adapter: 'postgresql',
|
||||||
|
# host: 'some_server',
|
||||||
|
# port: 5555,
|
||||||
|
# database: 'postgres' # this is not the name of the tenant's db
|
||||||
|
# # but the name of the database to connect to before creating the tenant's db
|
||||||
|
# # mandatory in postgresql
|
||||||
|
# },
|
||||||
|
# 'tenant2' => {
|
||||||
|
# adapter: 'postgresql',
|
||||||
|
# database: 'postgres' # this is not the name of the tenant's db
|
||||||
|
# # but the name of the database to connect to before creating the tenant's db
|
||||||
|
# # mandatory in postgresql
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# config.tenant_names = lambda do
|
||||||
|
# Tenant.all.each_with_object({}) do |tenant, hash|
|
||||||
|
# hash[tenant.name] = tenant.db_configuration
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
|
||||||
|
names = (Company.pluck :company_name) - ["IVA"]
|
||||||
|
|
||||||
|
names.map!{|tenant| tenant.gsub(/'/,'').gsub(/\s/,'')}
|
||||||
|
|
||||||
|
config.tenant_names = names
|
||||||
|
|
||||||
|
# ==> PostgreSQL only options
|
||||||
|
|
||||||
|
# Specifies whether to use PostgreSQL schemas or create a new database per Tenant.
|
||||||
|
# The default behaviour is true.
|
||||||
|
#
|
||||||
|
config.use_schemas = false
|
||||||
|
|
||||||
|
# Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
|
||||||
|
# Use this when you are using some extra features in PostgreSQL that can't be respresented in
|
||||||
|
# schema.rb, like materialized views etc. (only applies with use_schemas set to true).
|
||||||
|
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
|
||||||
|
#
|
||||||
|
# config.use_sql = false
|
||||||
|
|
||||||
|
# There are cases where you might want some schemas to always be in your search_path
|
||||||
|
# e.g when using a PostgreSQL extension like hstore.
|
||||||
|
# Any schemas added here will be available along with your selected Tenant.
|
||||||
|
#
|
||||||
|
# config.persistent_schemas = %w{ hstore }
|
||||||
|
|
||||||
|
# <== PostgreSQL only options
|
||||||
|
#
|
||||||
|
|
||||||
|
# By default, and only when not using PostgreSQL schemas, Apartment will prepend the environment
|
||||||
|
# to the tenant name to ensure there is no conflict between your environments.
|
||||||
|
# This is mainly for the benefit of your development and test environments.
|
||||||
|
# Uncomment the line below if you want to disable this behaviour in production.
|
||||||
|
#
|
||||||
|
config.prepend_environment = !Rails.env.production?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that
|
||||||
|
# you want to switch to.
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
|
||||||
|
# request.host.split('.').first
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::Domain'
|
||||||
|
Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::FirstSubdomain'
|
||||||
@ -8,11 +8,13 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@user = User.new(sign_up_params)
|
@user = User.new(sign_up_params)
|
||||||
|
if params[:password] == nil || params[:password_confirmation] == nil
|
||||||
|
flash[:error] = "Need a password to sign up"
|
||||||
|
redirect_to '/signin'
|
||||||
|
end
|
||||||
if params[:company_serial]
|
if params[:company_serial]
|
||||||
params.require(:user).permit(:company_id)
|
params.require(:user).permit(:company_id)
|
||||||
company = Company.find_by(company_token: params[:company_serial])
|
company = Company.find_by(company_token: params[:company_serial])
|
||||||
|
|
||||||
if company
|
if company
|
||||||
@user.company_id = company.id
|
@user.company_id = company.id
|
||||||
if company.company_name == "IVA"
|
if company.company_name == "IVA"
|
||||||
@ -20,7 +22,6 @@ class RegistrationsController < Devise::RegistrationsController
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
end
|
end
|
||||||
@user.save
|
@user.save
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<!--<h2>Sign up!</h2>
|
<!--<h2>Sign up!</h2>
|
||||||
|
|
||||||
|
<%if flash[:error]%>
|
||||||
|
<p><%=flash[:error]%></p>
|
||||||
|
<%end%>
|
||||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||||
<%= devise_error_messages! %>
|
<%= devise_error_messages! %>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|||||||
91
init/apartment.rb
Normal file
91
init/apartment.rb
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
# You can have Apartment route to the appropriate Tenant by adding some Rack middleware.
|
||||||
|
# Apartment can support many different "Elevators" that can take care of this routing to your data.
|
||||||
|
# Require whichever Elevator you're using below or none if you have a custom one.
|
||||||
|
#
|
||||||
|
# require 'apartment/elevators/generic'
|
||||||
|
# require 'apartment/elevators/domain'
|
||||||
|
require 'apartment/elevators/subdomain'
|
||||||
|
# require 'apartment/elevators/first_subdomain'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apartment Configuration
|
||||||
|
#
|
||||||
|
Apartment.configure do |config|
|
||||||
|
|
||||||
|
# Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
|
||||||
|
# A typical example would be a Customer or Tenant model that stores each Tenant's information.
|
||||||
|
#
|
||||||
|
config.excluded_models = [ "User", "Company" ]
|
||||||
|
|
||||||
|
# In order to migrate all of your Tenants you need to provide a list of Tenant names to Apartment.
|
||||||
|
# You can make this dynamic by providing a Proc object to be called on migrations.
|
||||||
|
# This object should yield either:
|
||||||
|
# - an array of strings representing each Tenant name.
|
||||||
|
# - a hash which keys are tenant names, and values custom db config (must contain all key/values required in database.yml)
|
||||||
|
#
|
||||||
|
# config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
|
||||||
|
# config.tenant_names = ['tenant1', 'tenant2']
|
||||||
|
# config.tenant_names = {
|
||||||
|
# 'tenant1' => {
|
||||||
|
# adapter: 'postgresql',
|
||||||
|
# host: 'some_server',
|
||||||
|
# port: 5555,
|
||||||
|
# database: 'postgres' # this is not the name of the tenant's db
|
||||||
|
# # but the name of the database to connect to before creating the tenant's db
|
||||||
|
# # mandatory in postgresql
|
||||||
|
# },
|
||||||
|
# 'tenant2' => {
|
||||||
|
# adapter: 'postgresql',
|
||||||
|
# database: 'postgres' # this is not the name of the tenant's db
|
||||||
|
# # but the name of the database to connect to before creating the tenant's db
|
||||||
|
# # mandatory in postgresql
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# config.tenant_names = lambda do
|
||||||
|
# Tenant.all.each_with_object({}) do |tenant, hash|
|
||||||
|
# hash[tenant.name] = tenant.db_configuration
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# ==> PostgreSQL only options
|
||||||
|
|
||||||
|
# Specifies whether to use PostgreSQL schemas or create a new database per Tenant.
|
||||||
|
# The default behaviour is true.
|
||||||
|
#
|
||||||
|
config.use_schemas = false
|
||||||
|
|
||||||
|
# Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
|
||||||
|
# Use this when you are using some extra features in PostgreSQL that can't be respresented in
|
||||||
|
# schema.rb, like materialized views etc. (only applies with use_schemas set to true).
|
||||||
|
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
|
||||||
|
#
|
||||||
|
# config.use_sql = false
|
||||||
|
|
||||||
|
# There are cases where you might want some schemas to always be in your search_path
|
||||||
|
# e.g when using a PostgreSQL extension like hstore.
|
||||||
|
# Any schemas added here will be available along with your selected Tenant.
|
||||||
|
#
|
||||||
|
# config.persistent_schemas = %w{ hstore }
|
||||||
|
|
||||||
|
# <== PostgreSQL only options
|
||||||
|
#
|
||||||
|
|
||||||
|
# By default, and only when not using PostgreSQL schemas, Apartment will prepend the environment
|
||||||
|
# to the tenant name to ensure there is no conflict between your environments.
|
||||||
|
# This is mainly for the benefit of your development and test environments.
|
||||||
|
# Uncomment the line below if you want to disable this behaviour in production.
|
||||||
|
#
|
||||||
|
config.prepend_environment = !Rails.env.production?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Setup a custom Tenant switching middleware. The Proc should return the name of the Tenant that
|
||||||
|
# you want to switch to.
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::Generic', lambda { |request|
|
||||||
|
# request.host.split('.').first
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::Domain'
|
||||||
|
Rails.application.config.middleware.use 'Apartment::Elevators::Subdomain'
|
||||||
|
# Rails.application.config.middleware.use 'Apartment::Elevators::FirstSubdomain'
|
||||||
30
setup.rb
Normal file
30
setup.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#Link every result to run id 48
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
#This will run the initial migration that sets up the db to be apartment friendly
|
||||||
|
def initial_migration
|
||||||
|
apartment_copy_path = 'init/apartment.rb'
|
||||||
|
apartment_path = 'Pearlception/config/initializers/apartment.rb'
|
||||||
|
FileUtils.cp(apartment_path, 'init/apartment_copy' ) #Copy the original file back
|
||||||
|
FileUtils.rm(apartment_path) #Remove the original file
|
||||||
|
FileUtils.cp(apartment_copy_path,apartment_path) #Copy the blank copy into init
|
||||||
|
Dir.chdir('Pearlception') do
|
||||||
|
puts `rake db:migrate` #Run the migration
|
||||||
|
end
|
||||||
|
FileUtils.rm(apartment_path) #Remove the blank copy
|
||||||
|
FileUtils.cp('init/apartment_copy',apartment_path)
|
||||||
|
FileUtils.rm('init/apartment_copy')
|
||||||
|
end
|
||||||
|
|
||||||
|
#Runs the initial bundle install
|
||||||
|
def bundle
|
||||||
|
Dir.chdir("Pearlception") do
|
||||||
|
puts `bundle install`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
########## MAIN METHOD #####################
|
||||||
|
bundle #bundle install
|
||||||
|
initial_migration #Setup db
|
||||||
|
#add in og admin
|
||||||
|
#Migrate all the oysters,runs,results from the AWS DB
|
||||||
Loading…
x
Reference in New Issue
Block a user