synerma-apartment 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.pryrc +5 -0
- data/.rspec +4 -0
- data/.rubocop.yml +79 -0
- data/.ruby-version +1 -0
- data/Appraisals +182 -0
- data/CODE_OF_CONDUCT.md +71 -0
- data/Gemfile +20 -0
- data/Guardfile +11 -0
- data/README.md +671 -0
- data/Rakefile +157 -0
- data/legacy_CHANGELOG.md +965 -0
- data/lib/apartment/active_record/connection_handling.rb +31 -0
- data/lib/apartment/active_record/internal_metadata.rb +9 -0
- data/lib/apartment/active_record/postgres/schema_dumper.rb +20 -0
- data/lib/apartment/active_record/postgresql_adapter.rb +58 -0
- data/lib/apartment/active_record/schema_migration.rb +11 -0
- data/lib/apartment/adapters/abstract_adapter.rb +275 -0
- data/lib/apartment/adapters/abstract_jdbc_adapter.rb +20 -0
- data/lib/apartment/adapters/jdbc_mysql_adapter.rb +19 -0
- data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +62 -0
- data/lib/apartment/adapters/mysql2_adapter.rb +77 -0
- data/lib/apartment/adapters/postgis_adapter.rb +13 -0
- data/lib/apartment/adapters/postgresql_adapter.rb +280 -0
- data/lib/apartment/adapters/sqlite3_adapter.rb +66 -0
- data/lib/apartment/adapters/trilogy_adapter.rb +29 -0
- data/lib/apartment/console.rb +24 -0
- data/lib/apartment/custom_console.rb +42 -0
- data/lib/apartment/deprecation.rb +8 -0
- data/lib/apartment/elevators/domain.rb +23 -0
- data/lib/apartment/elevators/first_subdomain.rb +18 -0
- data/lib/apartment/elevators/generic.rb +33 -0
- data/lib/apartment/elevators/host.rb +35 -0
- data/lib/apartment/elevators/host_hash.rb +26 -0
- data/lib/apartment/elevators/subdomain.rb +66 -0
- data/lib/apartment/log_subscriber.rb +45 -0
- data/lib/apartment/migrator.rb +46 -0
- data/lib/apartment/model.rb +29 -0
- data/lib/apartment/railtie.rb +68 -0
- data/lib/apartment/tasks/enhancements.rb +55 -0
- data/lib/apartment/tasks/task_helper.rb +54 -0
- data/lib/apartment/tenant.rb +63 -0
- data/lib/apartment/version.rb +5 -0
- data/lib/apartment.rb +155 -0
- data/lib/generators/apartment/install/USAGE +5 -0
- data/lib/generators/apartment/install/install_generator.rb +11 -0
- data/lib/generators/apartment/install/templates/apartment.rb +116 -0
- data/lib/tasks/apartment.rake +106 -0
- data/synerma-apartment.gemspec +40 -0
- metadata +198 -0
data/Rakefile
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue StandardError
|
6
|
+
'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
Bundler.setup
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
require 'appraisal'
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
RSpec::Core::RakeTask.new(spec: %w[db:load_credentials db:test:prepare]) do |spec|
|
17
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
18
|
+
# spec.rspec_opts = '--order rand:47078'
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :spec do
|
22
|
+
%i[tasks unit adapters integration].each do |type|
|
23
|
+
RSpec::Core::RakeTask.new(type => :spec) do |spec|
|
24
|
+
spec.pattern = "spec/#{type}/**/*_spec.rb"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
task :console do
|
30
|
+
require 'pry'
|
31
|
+
require 'apartment'
|
32
|
+
ARGV.clear
|
33
|
+
Pry.start
|
34
|
+
end
|
35
|
+
|
36
|
+
task default: :spec
|
37
|
+
|
38
|
+
namespace :db do
|
39
|
+
namespace :test do
|
40
|
+
case ENV.fetch('DATABASE_ENGINE', nil)
|
41
|
+
when 'postgresql'
|
42
|
+
task prepare: %w[postgres:drop_db postgres:build_db]
|
43
|
+
when 'mysql'
|
44
|
+
task prepare: %w[mysql:drop_db mysql:build_db]
|
45
|
+
when 'sqlite'
|
46
|
+
task :prepare do
|
47
|
+
puts 'No need to prepare sqlite3 database'
|
48
|
+
end
|
49
|
+
else
|
50
|
+
task :prepare do
|
51
|
+
puts 'No database engine specified, skipping db:test:prepare'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "copy sample database credential files over if real files don't exist"
|
57
|
+
task :load_credentials do
|
58
|
+
# If no DATABASE_ENGINE is specified, we default to sqlite so that a db config is generated
|
59
|
+
db_engine = ENV.fetch('DATABASE_ENGINE', 'sqlite')
|
60
|
+
|
61
|
+
next unless db_engine && %w[postgresql mysql sqlite].include?(db_engine)
|
62
|
+
|
63
|
+
# Load and write spec db config
|
64
|
+
db_config_string = ERB.new(File.read("spec/config/#{db_engine}.yml.erb")).result
|
65
|
+
File.write('spec/config/database.yml', db_config_string)
|
66
|
+
|
67
|
+
# Load and write dummy app db config
|
68
|
+
db_config = YAML.safe_load(db_config_string)
|
69
|
+
File.write('spec/dummy/config/database.yml', { test: db_config['connections'][db_engine] }.to_yaml)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
namespace :postgres do
|
74
|
+
require 'active_record'
|
75
|
+
require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s
|
76
|
+
|
77
|
+
desc 'Build the PostgreSQL test databases'
|
78
|
+
task :build_db do
|
79
|
+
params = []
|
80
|
+
params << '-E UTF8'
|
81
|
+
params << pg_config['database']
|
82
|
+
params << "-U#{pg_config['username']}"
|
83
|
+
params << "-h#{pg_config['host']}" if pg_config['host']
|
84
|
+
params << "-p#{pg_config['port']}" if pg_config['port']
|
85
|
+
|
86
|
+
begin
|
87
|
+
system("createdb #{params.join(' ')}")
|
88
|
+
rescue StandardError
|
89
|
+
'test db already exists'
|
90
|
+
end
|
91
|
+
ActiveRecord::Base.establish_connection(pg_config)
|
92
|
+
migrate
|
93
|
+
end
|
94
|
+
|
95
|
+
desc 'drop the PostgreSQL test database'
|
96
|
+
task :drop_db do
|
97
|
+
puts "dropping database #{pg_config['database']}"
|
98
|
+
params = []
|
99
|
+
params << pg_config['database']
|
100
|
+
params << "-U#{pg_config['username']}"
|
101
|
+
params << "-h#{pg_config['host']}" if pg_config['host']
|
102
|
+
params << "-p#{pg_config['port']}" if pg_config['port']
|
103
|
+
system("dropdb #{params.join(' ')}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
namespace :mysql do
|
108
|
+
require 'active_record'
|
109
|
+
require File.join(File.dirname(__FILE__), 'spec', 'support', 'config').to_s
|
110
|
+
|
111
|
+
desc 'Build the MySQL test databases'
|
112
|
+
task :build_db do
|
113
|
+
params = []
|
114
|
+
params << "-h #{my_config['host']}" if my_config['host']
|
115
|
+
params << "-u #{my_config['username']}" if my_config['username']
|
116
|
+
params << "-p #{my_config['password']}" if my_config['password']
|
117
|
+
params << "-P #{my_config['port']}" if my_config['port']
|
118
|
+
begin
|
119
|
+
system("mysqladmin #{params.join(' ')} create #{my_config['database']}")
|
120
|
+
rescue StandardError
|
121
|
+
'test db already exists'
|
122
|
+
end
|
123
|
+
ActiveRecord::Base.establish_connection(my_config)
|
124
|
+
migrate
|
125
|
+
end
|
126
|
+
|
127
|
+
desc 'drop the MySQL test database'
|
128
|
+
task :drop_db do
|
129
|
+
puts "dropping database #{my_config['database']}"
|
130
|
+
params = []
|
131
|
+
params << "-h #{my_config['host']}" if my_config['host']
|
132
|
+
params << "-u #{my_config['username']}" if my_config['username']
|
133
|
+
params << "-p #{my_config['password']}" if my_config['password']
|
134
|
+
params << "-P #{my_config['port']}" if my_config['port']
|
135
|
+
system("mysqladmin #{params.join(' ')} drop #{my_config['database']} --force")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def config
|
140
|
+
Apartment::Test.config['connections']
|
141
|
+
end
|
142
|
+
|
143
|
+
def pg_config
|
144
|
+
config['postgresql']
|
145
|
+
end
|
146
|
+
|
147
|
+
def my_config
|
148
|
+
config['mysql']
|
149
|
+
end
|
150
|
+
|
151
|
+
def migrate
|
152
|
+
if ActiveRecord.version.release < Gem::Version.new('7.1')
|
153
|
+
ActiveRecord::MigrationContext.new('spec/dummy/db/migrate', ActiveRecord::SchemaMigration).migrate
|
154
|
+
else
|
155
|
+
ActiveRecord::MigrationContext.new('spec/dummy/db/migrate').migrate
|
156
|
+
end
|
157
|
+
end
|