ros-apartment 2.10.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +256 -59
- data/.ruby-version +1 -1
- data/Appraisals +14 -35
- data/CHANGELOG.md +5 -3
- data/README.md +5 -6
- data/Rakefile +3 -17
- data/lib/apartment/active_record/connection_handling.rb +18 -7
- data/lib/apartment/active_record/postgresql_adapter.rb +43 -0
- data/lib/apartment/active_record/schema_migration.rb +1 -1
- data/lib/apartment/adapters/postgresql_adapter.rb +10 -22
- data/lib/apartment/console.rb +0 -16
- data/lib/apartment/log_subscriber.rb +21 -9
- data/lib/apartment/migrator.rb +3 -21
- data/lib/apartment/railtie.rb +6 -20
- data/lib/apartment/version.rb +1 -1
- data/lib/apartment.rb +6 -16
- data/ros-apartment.gemspec +12 -9
- metadata +24 -38
- data/.circleci/config.yml +0 -76
- data/.github/ISSUE_TEMPLATE.md +0 -21
- data/.github/workflows/changelog.yml +0 -63
- data/.github/workflows/reviewdog.yml +0 -22
- data/.story_branch.yml +0 -5
- data/HISTORY.md +0 -496
- data/TODO.md +0 -50
- data/docker-compose.yml +0 -33
- data/gemfiles/rails_4_2.gemfile +0 -25
- data/gemfiles/rails_5_0.gemfile +0 -23
- data/gemfiles/rails_5_1.gemfile +0 -23
- data/gemfiles/rails_5_2.gemfile +0 -19
- data/gemfiles/rails_6_0.gemfile +0 -23
- data/gemfiles/rails_6_1.gemfile +0 -23
- data/gemfiles/rails_master.gemfile +0 -23
- data/lib/apartment/reloader.rb +0 -22
data/TODO.md
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# Apartment TODOs
|
2
|
-
|
3
|
-
### Below is a list of tasks in the approximate order to be completed of for Apartment
|
4
|
-
### Any help along the way is greatly appreciated (on any items, not particularly in order)
|
5
|
-
|
6
|
-
1. Apartment was originally written (and TDD'd) with just Postgresql in mind. Different adapters were added at a later date.
|
7
|
-
As such, the test suite is a bit of a mess. There's no formal structure for fully integration testing all adapters to ensure
|
8
|
-
proper quality and prevent regressions.
|
9
|
-
|
10
|
-
There's also a test order dependency as some tests run assuming a db connection and if that test randomly ran before a previous
|
11
|
-
one that makes the connection, it would fail.
|
12
|
-
|
13
|
-
I'm proposing the first thing to be done is to write up a standard, high livel integration test case that can be applied to all adapters
|
14
|
-
and makes no assumptions about implementation. It should ensure that each adapter conforms to the Apartment Interface and CRUD's properly.
|
15
|
-
It would be nice if a user can 'register' an adapter such that it would automatically be tested (nice to have). Otherwise one could just use
|
16
|
-
a shared behaviour to run through all of this.
|
17
|
-
|
18
|
-
Then, I'd like to see all of the implementation specific tests just in their own test file for each adapter (ie the postgresql schema adapter checks a lot of things with `schema_search_path`)
|
19
|
-
|
20
|
-
This should ensure that going forward nothing breaks, and we should *ideally* be able to randomize the test order
|
21
|
-
|
22
|
-
2. <del>`Apartment::Database` is the wrong abstraction. When dealing with a multi-tenanted system, users shouldn't thing about 'Databases', they should
|
23
|
-
think about Tenants. I proprose that we deprecate the `Apartment::Database` constant in favour of `Apartment::Tenant` for a nicer abstraction. See
|
24
|
-
http://myronmars.to/n/dev-blog/2011/09/deprecating-constants-and-classes-in-ruby for ideas on how to achieve this.</del>
|
25
|
-
|
26
|
-
4. Apartment::Database.process should be deprecated in favour of just passing a block to `switch`
|
27
|
-
5. Apartment::Database.switch should be renamed to switch! to indicate that using it on its own has side effects
|
28
|
-
|
29
|
-
6. Migrations right now can be a bit of a pain. Apartment currently migrates a single tenant completely up to date, then goes onto the next. If one of these
|
30
|
-
migrations fails on a tenant, the previous one does NOT get reverted and leaves you in an awkward state. Ideally we'd want to wrap all of the migrations in
|
31
|
-
a transaction so if one fails, the whole thing reverts. Once we can ensure an all-or-nothing approach to migrations, we can optimize the migration strategy
|
32
|
-
to not even iterate over the tenants if there are no migrations to run on public.
|
33
|
-
|
34
|
-
7. Apartment has be come one of the most popular/robust Multi-tenant gems for Rails, but it still doesn't work for everyone's use case. It's fairly limited in implementation to either schema based (ie postgresql schemas) or connection based. I'd like to abstract out these implementation details such that one could write a pluggable strategy for Apartment and choose it based on a config selection (something like `config.strategy = :schema`). The next implementation I'd like to see is a scoped based approach that uses a `tenant_id` scoping on all records for multi-tenancy. This is probably the most popular multi-tenant approach and is db independent and really the simplest mechanism for a type of multi-tenancy.
|
35
|
-
|
36
|
-
8. Right now excluded tables still live in all tenanted environments. This is basically because it doesn't matter if they're there, we always query from the public.
|
37
|
-
It's a bit of an annoyance though and confuses lots of people. I'd love to see only tenanted tables in the tenants and only excluded tables in the public tenant.
|
38
|
-
This will be hard because Rails uses public to generate schema.rb. One idea is to have an `excluded` schema that holds all the excluded models and the public can
|
39
|
-
maintain everything.
|
40
|
-
|
41
|
-
9. This one is pretty lofty, but I'd also like to abstract out the fact that Apartment uses ActiveRecord. With the new DataMapper coming out soon and other popular
|
42
|
-
DBMS's (ie. mongo, couch etc...), it'd be nice if Apartment could be the de-facto interface for multi-tenancy on these systems.
|
43
|
-
|
44
|
-
|
45
|
-
===================
|
46
|
-
|
47
|
-
Quick TODOs
|
48
|
-
|
49
|
-
2. deprecation.rb rescues everything, we have a hard dependency on ActiveSupport so this is unnecessary
|
50
|
-
3.
|
data/docker-compose.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
version: '2.3'
|
2
|
-
services:
|
3
|
-
postgresql:
|
4
|
-
image: postgres:9.5.12
|
5
|
-
environment:
|
6
|
-
POSTGRES_PASSWORD: ""
|
7
|
-
ports:
|
8
|
-
- "5432:5432"
|
9
|
-
healthcheck:
|
10
|
-
test: pg_isready -U postgres
|
11
|
-
start_period: 10s
|
12
|
-
interval: 10s
|
13
|
-
timeout: 30s
|
14
|
-
retries: 3
|
15
|
-
mysql:
|
16
|
-
image: mysql:5.7
|
17
|
-
environment:
|
18
|
-
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
19
|
-
ports:
|
20
|
-
- "3306:3306"
|
21
|
-
healthcheck:
|
22
|
-
test: mysqladmin -h 127.0.0.1 -uroot ping
|
23
|
-
start_period: 15s
|
24
|
-
interval: 10s
|
25
|
-
timeout: 30s
|
26
|
-
retries: 3
|
27
|
-
healthcheck:
|
28
|
-
image: busybox
|
29
|
-
depends_on:
|
30
|
-
postgresql:
|
31
|
-
condition: service_healthy
|
32
|
-
mysql:
|
33
|
-
condition: service_healthy
|
data/gemfiles/rails_4_2.gemfile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This file was generated by Appraisal
|
4
|
-
|
5
|
-
source 'http://rubygems.org'
|
6
|
-
|
7
|
-
gem 'rails', '~> 4.2.0'
|
8
|
-
|
9
|
-
group :local do
|
10
|
-
gem 'guard-rspec', '~> 4.2'
|
11
|
-
gem 'pry'
|
12
|
-
end
|
13
|
-
|
14
|
-
platforms :ruby do
|
15
|
-
gem 'mysql2', '~> 0.4.0'
|
16
|
-
gem 'pg', '< 1.0.0'
|
17
|
-
end
|
18
|
-
|
19
|
-
platforms :jruby do
|
20
|
-
gem 'activerecord-jdbc-adapter', '~> 1.3'
|
21
|
-
gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
|
22
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
|
23
|
-
end
|
24
|
-
|
25
|
-
gemspec path: '../'
|
data/gemfiles/rails_5_0.gemfile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 5.0.0"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :ruby do
|
14
|
-
gem "pg", "< 1.0.0"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :jruby do
|
18
|
-
gem "activerecord-jdbc-adapter", "~> 50.0"
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0"
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 50.0"
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
data/gemfiles/rails_5_1.gemfile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 5.1.0"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :ruby do
|
14
|
-
gem "pg", "< 1.0.0"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :jruby do
|
18
|
-
gem "activerecord-jdbc-adapter", "~> 51.0"
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0"
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 51.0"
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
data/gemfiles/rails_5_2.gemfile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 5.2.0"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :jruby do
|
14
|
-
gem "activerecord-jdbc-adapter", "~> 52.0"
|
15
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 52.0"
|
16
|
-
gem "activerecord-jdbcmysql-adapter", "~> 52.0"
|
17
|
-
end
|
18
|
-
|
19
|
-
gemspec path: "../"
|
data/gemfiles/rails_6_0.gemfile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 6.0.0"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :ruby do
|
14
|
-
gem "sqlite3", "~> 1.4"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :jruby do
|
18
|
-
gem "activerecord-jdbc-adapter", "~> 60.0"
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 60.0"
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 60.0"
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
data/gemfiles/rails_6_1.gemfile
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", "~> 6.1.0"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :ruby do
|
14
|
-
gem "sqlite3", "~> 1.4"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :jruby do
|
18
|
-
gem "activerecord-jdbc-adapter", "~> 61.0"
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 61.0"
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 61.0"
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "http://rubygems.org"
|
4
|
-
|
5
|
-
gem "rails", git: "https://github.com/rails/rails.git"
|
6
|
-
gem "rubocop"
|
7
|
-
|
8
|
-
group :local do
|
9
|
-
gem "guard-rspec", "~> 4.2"
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
platforms :ruby do
|
14
|
-
gem "sqlite3", "~> 1.4"
|
15
|
-
end
|
16
|
-
|
17
|
-
platforms :jruby do
|
18
|
-
gem "activerecord-jdbc-adapter", "~> 52.0"
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 52.0"
|
20
|
-
gem "activerecord-jdbcmysql-adapter", "~> 52.0"
|
21
|
-
end
|
22
|
-
|
23
|
-
gemspec path: "../"
|
data/lib/apartment/reloader.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Apartment
|
4
|
-
class Reloader
|
5
|
-
# Middleware used in development to init Apartment for each request
|
6
|
-
# Necessary due to code reload (annoying). When models are reloaded, they no longer have the proper table_name
|
7
|
-
# That is prepended with the schema (if using postgresql schemas)
|
8
|
-
# I couldn't figure out how to properly hook into the Rails reload process *after* files are reloaded
|
9
|
-
# so I've used this in the meantime.
|
10
|
-
#
|
11
|
-
# Also see apartment/console for the re-definition of reload! that re-init's Apartment
|
12
|
-
#
|
13
|
-
def initialize(app)
|
14
|
-
@app = app
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(env)
|
18
|
-
Tenant.init
|
19
|
-
@app.call(env)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|