apartment 2.2.0 → 2.2.1
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 +4 -4
- data/.travis.yml +7 -1
- data/HISTORY.md +11 -0
- data/README.md +25 -0
- data/docker-compose.yml +21 -2
- data/lib/apartment/adapters/abstract_adapter.rb +19 -19
- data/lib/apartment/adapters/postgresql_adapter.rb +4 -1
- data/lib/apartment/tenant.rb +1 -1
- data/lib/apartment/version.rb +1 -1
- data/lib/tasks/apartment.rake +1 -1
- data/spec/config/database.yml.sample +8 -0
- data/spec/dummy/config/database.yml.sample +4 -0
- data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +13 -0
- data/spec/dummy/db/schema.rb +25 -19
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be448dd133ac9668f7ba463444dbf7ea92c12d844b3b87a319c2b380cc26d9a6
|
4
|
+
data.tar.gz: 36ad7e20ba2897f2696262c010295a2912c52a10050445971495fc3c452afd1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4a32ff51228ad18573838b29980fe507df2856e23b3269f9eb0be8dcddd4a3e86e08c40038e45a21d41f884fa7e1c38ae570753ba40e7e21e512bf243a047e3
|
7
|
+
data.tar.gz: 42231f505295be8cd0babe3e58252867d1a6bc59ef5df3c9eacda2a80858ba8ba3d0fa584c73883986ab136b7611a865684c50f8bd540b6acc9a2f8b37cd90de
|
data/.travis.yml
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
sudo: required
|
1
2
|
language: ruby
|
3
|
+
services:
|
4
|
+
- docker
|
2
5
|
rvm:
|
6
|
+
- jruby-9.1.15.0
|
3
7
|
- 2.1.9
|
4
8
|
- 2.2.9
|
5
9
|
- 2.3.6
|
6
10
|
- 2.4.3
|
7
11
|
- 2.5.0
|
8
12
|
- ruby-head
|
9
|
-
- jruby-9.1.15.0
|
10
13
|
gemfile:
|
11
14
|
- gemfiles/rails_4_2.gemfile
|
12
15
|
- gemfiles/rails_5_0.gemfile
|
@@ -15,6 +18,9 @@ gemfile:
|
|
15
18
|
- gemfiles/rails_master.gemfile
|
16
19
|
bundler_args: --without local
|
17
20
|
before_install:
|
21
|
+
- sudo /etc/init.d/mysql stop
|
22
|
+
- sudo /etc/init.d/postgresql stop
|
23
|
+
- docker-compose up -d
|
18
24
|
- gem install bundler -v '> 1.5.0'
|
19
25
|
env:
|
20
26
|
RUBY_GC_MALLOC_LIMIT: 90000000
|
data/HISTORY.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
# 2.2.1
|
2
|
+
* June 19, 2019
|
3
|
+
|
4
|
+
## Added
|
5
|
+
- #566: IGNORE_EMPTY_TENANTS environment variable to ignore empty tenants
|
6
|
+
warning. [Pysis868]
|
7
|
+
|
8
|
+
## Fixed
|
9
|
+
- #586: Ignore `CREATE SCHEMA public` statement in pg dump [artemave]
|
10
|
+
- #549: Fix Postgres schema creation with dump SQL [ancorcruz]
|
11
|
+
|
1
12
|
# 2.2.0
|
2
13
|
* April 14, 2018
|
3
14
|
|
data/README.md
CHANGED
@@ -533,6 +533,31 @@ end
|
|
533
533
|
|
534
534
|
See [apartment-sidekiq](https://github.com/influitive/apartment-sidekiq) or [apartment-activejob](https://github.com/influitive/apartment-activejob).
|
535
535
|
|
536
|
+
## Callbacks
|
537
|
+
|
538
|
+
You can execute callbacks when switching between tenants or creating a new one, Apartment provides the following callbacks:
|
539
|
+
|
540
|
+
- before_create
|
541
|
+
- after_create
|
542
|
+
- before_switch
|
543
|
+
- after_switch
|
544
|
+
|
545
|
+
You can register a callback using [ActiveSupport::Callbacks](https://api.rubyonrails.org/classes/ActiveSupport/Callbacks.html) the following way:
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
require 'apartment/adapters/abstract_adapter'
|
549
|
+
|
550
|
+
module Apartment
|
551
|
+
module Adapters
|
552
|
+
class AbstractAdapter
|
553
|
+
set_callback :switch, :before do |object|
|
554
|
+
...
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
end
|
559
|
+
```
|
560
|
+
|
536
561
|
## Contributing
|
537
562
|
|
538
563
|
* In both `spec/dummy/config` and `spec/config`, you will see `database.yml.sample` files
|
data/docker-compose.yml
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
-
version: '2'
|
1
|
+
version: '2.3'
|
2
2
|
services:
|
3
3
|
postgresql:
|
4
|
-
image: postgres:
|
4
|
+
image: postgres:9.5.12
|
5
5
|
environment:
|
6
6
|
POSTGRES_PASSWORD: ""
|
7
7
|
ports:
|
8
8
|
- "5432:5432"
|
9
|
+
healthcheck:
|
10
|
+
test: pg_isready -U postgres
|
11
|
+
start_period: 10s
|
12
|
+
interval: 10s
|
13
|
+
timeout: 30s
|
14
|
+
retries: 3
|
9
15
|
mysql:
|
10
16
|
image: mysql:5.7
|
11
17
|
environment:
|
12
18
|
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
13
19
|
ports:
|
14
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
|
@@ -120,6 +120,25 @@ module Apartment
|
|
120
120
|
end
|
121
121
|
alias_method :seed, :seed_data
|
122
122
|
|
123
|
+
# Prepend the environment if configured and the environment isn't already there
|
124
|
+
#
|
125
|
+
# @param {String} tenant Database name
|
126
|
+
# @return {String} tenant name with Rails environment *optionally* prepended
|
127
|
+
#
|
128
|
+
def environmentify(tenant)
|
129
|
+
unless tenant.include?(Rails.env)
|
130
|
+
if Apartment.prepend_environment
|
131
|
+
"#{Rails.env}_#{tenant}"
|
132
|
+
elsif Apartment.append_environment
|
133
|
+
"#{tenant}_#{Rails.env}"
|
134
|
+
else
|
135
|
+
tenant
|
136
|
+
end
|
137
|
+
else
|
138
|
+
tenant
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
123
142
|
protected
|
124
143
|
|
125
144
|
def process_excluded_model(excluded_model)
|
@@ -163,25 +182,6 @@ module Apartment
|
|
163
182
|
raise_connect_error!(tenant, exception)
|
164
183
|
end
|
165
184
|
|
166
|
-
# Prepend the environment if configured and the environment isn't already there
|
167
|
-
#
|
168
|
-
# @param {String} tenant Database name
|
169
|
-
# @return {String} tenant name with Rails environment *optionally* prepended
|
170
|
-
#
|
171
|
-
def environmentify(tenant)
|
172
|
-
unless tenant.include?(Rails.env)
|
173
|
-
if Apartment.prepend_environment
|
174
|
-
"#{Rails.env}_#{tenant}"
|
175
|
-
elsif Apartment.append_environment
|
176
|
-
"#{tenant}_#{Rails.env}"
|
177
|
-
else
|
178
|
-
tenant
|
179
|
-
end
|
180
|
-
else
|
181
|
-
tenant
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
185
|
# Import the database schema
|
186
186
|
#
|
187
187
|
def import_database_schema
|
@@ -110,6 +110,9 @@ module Apartment
|
|
110
110
|
/SET lock_timeout/i, # new in postgresql 9.3
|
111
111
|
/SET row_security/i, # new in postgresql 9.5
|
112
112
|
/SET idle_in_transaction_session_timeout/i, # new in postgresql 9.6
|
113
|
+
/CREATE SCHEMA public/i,
|
114
|
+
/COMMENT ON SCHEMA public/i,
|
115
|
+
|
113
116
|
]
|
114
117
|
|
115
118
|
def import_database_schema
|
@@ -204,7 +207,7 @@ module Apartment
|
|
204
207
|
if Apartment.pg_excluded_names.any? { |name| match.include? name }
|
205
208
|
match
|
206
209
|
else
|
207
|
-
match.gsub(default_tenant, %{"#{current}"})
|
210
|
+
match.gsub("#{default_tenant}.", %{"#{current}".})
|
208
211
|
end
|
209
212
|
end
|
210
213
|
end
|
data/lib/apartment/tenant.rb
CHANGED
@@ -8,7 +8,7 @@ module Apartment
|
|
8
8
|
extend self
|
9
9
|
extend Forwardable
|
10
10
|
|
11
|
-
def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each, :reset, :set_callback, :seed, :current_tenant, :default_tenant
|
11
|
+
def_delegators :adapter, :create, :drop, :switch, :switch!, :current, :each, :reset, :set_callback, :seed, :current_tenant, :default_tenant, :environmentify
|
12
12
|
|
13
13
|
attr_writer :config
|
14
14
|
|
data/lib/apartment/version.rb
CHANGED
data/lib/tasks/apartment.rake
CHANGED
@@ -130,7 +130,7 @@ apartment_namespace = namespace :apartment do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def warn_if_tenants_empty
|
133
|
-
if tenants.empty?
|
133
|
+
if tenants.empty? && ENV['IGNORE_EMPTY_TENANTS'] != "true"
|
134
134
|
puts <<-WARNING
|
135
135
|
[WARNING] - The list of tenants to migrate appears to be empty. This could mean a few things:
|
136
136
|
|
@@ -9,6 +9,8 @@ connections:
|
|
9
9
|
url: jdbc:postgresql://localhost:5432/apartment_postgresql_test
|
10
10
|
timeout: 5000
|
11
11
|
pool: 5
|
12
|
+
host: localhost
|
13
|
+
port: 5432
|
12
14
|
|
13
15
|
mysql:
|
14
16
|
adapter: mysql
|
@@ -19,6 +21,8 @@ connections:
|
|
19
21
|
url: jdbc:mysql://localhost:3306/apartment_mysql_test
|
20
22
|
timeout: 5000
|
21
23
|
pool: 5
|
24
|
+
host: 127.0.0.1
|
25
|
+
port: 3306
|
22
26
|
<% else %>
|
23
27
|
connections:
|
24
28
|
postgresql:
|
@@ -28,12 +32,16 @@ connections:
|
|
28
32
|
username: postgres
|
29
33
|
schema_search_path: public
|
30
34
|
password:
|
35
|
+
host: localhost
|
36
|
+
port: 5432
|
31
37
|
|
32
38
|
mysql:
|
33
39
|
adapter: mysql2
|
34
40
|
database: apartment_mysql_test
|
35
41
|
username: root
|
36
42
|
password:
|
43
|
+
host: 127.0.0.1
|
44
|
+
port: 3306
|
37
45
|
|
38
46
|
sqlite:
|
39
47
|
adapter: sqlite3
|
@@ -29,6 +29,8 @@ test:
|
|
29
29
|
min_messages: WARNING
|
30
30
|
pool: 5
|
31
31
|
timeout: 5000
|
32
|
+
host: localhost
|
33
|
+
port: 5432
|
32
34
|
|
33
35
|
development:
|
34
36
|
adapter: postgresql
|
@@ -37,4 +39,6 @@ development:
|
|
37
39
|
min_messages: WARNING
|
38
40
|
pool: 5
|
39
41
|
timeout: 5000
|
42
|
+
host: localhost
|
43
|
+
port: 5432
|
40
44
|
<% end %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
migration_class = (ActiveRecord::VERSION::MAJOR >= 5) ? ActiveRecord::Migration[4.2] : ActiveRecord::Migration
|
2
|
+
class CreatePublicTokens < migration_class
|
3
|
+
def up
|
4
|
+
create_table :public_tokens do |t|
|
5
|
+
t.string :token
|
6
|
+
t.integer :user_id, foreign_key: true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
drop_table :public_tokens
|
12
|
+
end
|
13
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -9,41 +8,48 @@
|
|
9
8
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
9
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
10
|
#
|
12
|
-
# It's strongly recommended
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
12
|
|
14
|
-
ActiveRecord::Schema.define(:
|
13
|
+
ActiveRecord::Schema.define(version: 2018_04_15_260934) do
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
# These are extensions that must be enabled in order to support this database
|
16
|
+
enable_extension "plpgsql"
|
17
|
+
|
18
|
+
create_table "books", force: :cascade do |t|
|
19
|
+
t.string "name"
|
20
|
+
t.integer "pages"
|
19
21
|
t.datetime "published"
|
20
22
|
end
|
21
23
|
|
22
|
-
create_table "companies", :
|
24
|
+
create_table "companies", force: :cascade do |t|
|
23
25
|
t.boolean "dummy"
|
24
|
-
t.string
|
26
|
+
t.string "database"
|
25
27
|
end
|
26
28
|
|
27
|
-
create_table "delayed_jobs", :
|
28
|
-
t.integer
|
29
|
-
t.integer
|
30
|
-
t.text
|
31
|
-
t.text
|
29
|
+
create_table "delayed_jobs", force: :cascade do |t|
|
30
|
+
t.integer "priority", default: 0
|
31
|
+
t.integer "attempts", default: 0
|
32
|
+
t.text "handler"
|
33
|
+
t.text "last_error"
|
32
34
|
t.datetime "run_at"
|
33
35
|
t.datetime "locked_at"
|
34
36
|
t.datetime "failed_at"
|
35
|
-
t.string
|
37
|
+
t.string "locked_by"
|
36
38
|
t.datetime "created_at"
|
37
39
|
t.datetime "updated_at"
|
38
|
-
t.string
|
40
|
+
t.string "queue"
|
41
|
+
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
|
39
42
|
end
|
40
43
|
|
41
|
-
|
44
|
+
create_table "public_tokens", id: :serial, force: :cascade do |t|
|
45
|
+
t.string "token"
|
46
|
+
t.integer "user_id"
|
47
|
+
end
|
42
48
|
|
43
|
-
create_table "users", :
|
44
|
-
t.string
|
49
|
+
create_table "users", force: :cascade do |t|
|
50
|
+
t.string "name"
|
45
51
|
t.datetime "birthdate"
|
46
|
-
t.string
|
52
|
+
t.string "sex"
|
47
53
|
end
|
48
54
|
|
49
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apartment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brunner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- spec/dummy/config/routes.rb
|
273
273
|
- spec/dummy/db/migrate/20110613152810_create_dummy_models.rb
|
274
274
|
- spec/dummy/db/migrate/20111202022214_create_table_books.rb
|
275
|
+
- spec/dummy/db/migrate/20180415260934_create_public_tokens.rb
|
275
276
|
- spec/dummy/db/schema.rb
|
276
277
|
- spec/dummy/db/seeds.rb
|
277
278
|
- spec/dummy/db/seeds/import.rb
|
@@ -359,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
359
360
|
version: '0'
|
360
361
|
requirements: []
|
361
362
|
rubyforge_project:
|
362
|
-
rubygems_version: 2.7.
|
363
|
+
rubygems_version: 2.7.8
|
363
364
|
signing_key:
|
364
365
|
specification_version: 4
|
365
366
|
summary: A Ruby gem for managing database multitenancy
|
@@ -396,6 +397,7 @@ test_files:
|
|
396
397
|
- spec/dummy/config/routes.rb
|
397
398
|
- spec/dummy/db/migrate/20110613152810_create_dummy_models.rb
|
398
399
|
- spec/dummy/db/migrate/20111202022214_create_table_books.rb
|
400
|
+
- spec/dummy/db/migrate/20180415260934_create_public_tokens.rb
|
399
401
|
- spec/dummy/db/schema.rb
|
400
402
|
- spec/dummy/db/seeds.rb
|
401
403
|
- spec/dummy/db/seeds/import.rb
|