ros-apartment 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +52 -9
- data/.ruby-version +1 -1
- data/Appraisals +110 -30
- data/CODE_OF_CONDUCT.md +71 -0
- data/Gemfile +15 -0
- data/README.md +48 -30
- data/Rakefile +42 -24
- data/lib/apartment/active_record/connection_handling.rb +2 -2
- data/lib/apartment/active_record/postgres/schema_dumper.rb +20 -0
- data/lib/apartment/active_record/postgresql_adapter.rb +19 -4
- data/lib/apartment/adapters/abstract_adapter.rb +1 -1
- data/lib/apartment/adapters/postgresql_adapter.rb +15 -19
- data/lib/apartment/deprecation.rb +2 -5
- data/lib/apartment/migrator.rb +15 -3
- data/lib/apartment/tasks/task_helper.rb +3 -1
- data/lib/apartment/version.rb +1 -1
- data/lib/apartment.rb +8 -2
- data/ros-apartment.gemspec +10 -35
- metadata +35 -247
- data/.rubocop_todo.yml +0 -439
- /data/{CHANGELOG.md → legacy_CHANGELOG.md} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7acbb6c519fef676bdf05370eb1de788bf262a30f83040fcb2455b3a950ad58
|
4
|
+
data.tar.gz: c078d989df4e11e7d519bcb0c30c0a99cd8f692adc995407a6a7fdecbd5d6e2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef24485b251bf0d68f1e2af3a6cb82312b25f457383ed4bff1eadf50ee2cacba8af21330cd03853186ee117b07e3454f9224485d81079c687b69fadc9fabbea
|
7
|
+
data.tar.gz: 64c3423beb74472af3f84ad21152eed840162a6bf7d567b360f0a7216314545f7e1ca5eb5af9fb20b753fd681a4d40582478da6335ab69cc8e8795812362d74a
|
data/.rubocop.yml
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
inherit_from: .rubocop_todo.yml
|
2
|
-
|
3
|
-
require:
|
4
|
-
- rubocop-rails
|
5
|
-
- rubocop-performance
|
6
|
-
- rubocop-rspec
|
7
|
-
|
8
1
|
AllCops:
|
2
|
+
NewCops: enable
|
9
3
|
Exclude:
|
10
4
|
- vendor/bundle/**/*
|
11
5
|
- gemfiles/**/*.gemfile
|
@@ -13,12 +7,20 @@ AllCops:
|
|
13
7
|
- spec/dummy_engine/dummy_engine.gemspec
|
14
8
|
- spec/schemas/**/*.rb
|
15
9
|
|
16
|
-
|
10
|
+
require:
|
11
|
+
- rubocop-rails
|
12
|
+
- rubocop-performance
|
13
|
+
- rubocop-thread_safety
|
14
|
+
- rubocop-rake
|
15
|
+
- rubocop-rspec
|
17
16
|
|
18
17
|
Gemspec/RequiredRubyVersion:
|
19
18
|
Exclude:
|
20
19
|
- 'ros-apartment.gemspec'
|
21
20
|
|
21
|
+
Layout/MultilineMethodCallIndentation:
|
22
|
+
EnforcedStyle: indented
|
23
|
+
|
22
24
|
Metrics/BlockLength:
|
23
25
|
Exclude:
|
24
26
|
- spec/**/*.rb
|
@@ -33,4 +35,45 @@ Rails/Output:
|
|
33
35
|
Enabled: false
|
34
36
|
|
35
37
|
Style/Documentation:
|
36
|
-
Enabled: false
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/StringLiterals:
|
41
|
+
EnforcedStyle: single_quotes
|
42
|
+
|
43
|
+
Style/InlineComment:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/FrozenStringLiteralComment:
|
47
|
+
Enabled: true
|
48
|
+
Exclude:
|
49
|
+
- Gemfile
|
50
|
+
|
51
|
+
Style/MethodCallWithArgsParentheses:
|
52
|
+
Enabled: true
|
53
|
+
EnforcedStyle: require_parentheses
|
54
|
+
AllowedPatterns:
|
55
|
+
- 'puts'
|
56
|
+
- 'info'
|
57
|
+
- 'warn'
|
58
|
+
- 'debug'
|
59
|
+
- 'error'
|
60
|
+
- 'fatal'
|
61
|
+
- 'fail'
|
62
|
+
|
63
|
+
Style/TrailingCommaInArrayLiteral:
|
64
|
+
EnforcedStyleForMultiline: comma
|
65
|
+
|
66
|
+
Style/TrailingCommaInHashLiteral:
|
67
|
+
EnforcedStyleForMultiline: comma
|
68
|
+
|
69
|
+
Style/ClassAndModuleChildren:
|
70
|
+
EnforcedStyle: nested
|
71
|
+
AutoCorrect: true
|
72
|
+
|
73
|
+
Style/CollectionMethods:
|
74
|
+
PreferredMethods:
|
75
|
+
collect: 'map'
|
76
|
+
collect!: 'map!'
|
77
|
+
inject: 'reduce'
|
78
|
+
detect: 'detect'
|
79
|
+
find_all: 'select'
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3.
|
1
|
+
3.3.6
|
data/Appraisals
CHANGED
@@ -1,50 +1,130 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
appraise 'rails-6-1' do
|
3
|
+
appraise 'rails-6-1-postgresql' do
|
4
4
|
gem 'rails', '~> 6.1.0'
|
5
|
-
|
6
|
-
|
5
|
+
gem 'pg', '~> 1.5'
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise 'rails-6-1-mysql' do
|
9
|
+
gem 'rails', '~> 6.1.0'
|
10
|
+
gem 'mysql2', '~> 0.5'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails-6-1-sqlite3' do
|
14
|
+
gem 'rails', '~> 6.1.0'
|
15
|
+
gem 'sqlite3', '~> 1.4'
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise 'rails-6-1-jdbc-postgresql' do
|
19
|
+
gem 'rails', '~> 6.1.0'
|
20
|
+
platforms :jruby do
|
21
|
+
gem 'activerecord-jdbc-adapter', '~> 61.3'
|
22
|
+
gem 'activerecord-jdbcpostgresql-adapter', '~> 61.3'
|
23
|
+
gem 'jdbc-postgres'
|
7
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
appraise 'rails-6-1-jdbc-mysql' do
|
28
|
+
gem 'rails', '~> 6.1.0'
|
8
29
|
platforms :jruby do
|
9
|
-
gem 'activerecord-jdbc-adapter', '~> 61.
|
10
|
-
gem 'activerecord-
|
11
|
-
gem '
|
30
|
+
gem 'activerecord-jdbc-adapter', '~> 61.3'
|
31
|
+
gem 'activerecord-jdbcmysql-adapter', '~> 61.3'
|
32
|
+
gem 'jdbc-mysql'
|
12
33
|
end
|
13
34
|
end
|
14
35
|
|
15
|
-
appraise 'rails-
|
16
|
-
gem 'rails', '~>
|
17
|
-
platforms :
|
18
|
-
gem '
|
36
|
+
appraise 'rails-6-1-jdbc-sqlite3' do
|
37
|
+
gem 'rails', '~> 6.1.0'
|
38
|
+
platforms :jruby do
|
39
|
+
gem 'activerecord-jdbc-adapter', '~> 61.3'
|
40
|
+
gem 'activerecord-jdbcsqlite3-adapter', '~> 61.3'
|
41
|
+
gem 'jdbc-sqlite3'
|
19
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
appraise 'rails-7-0-postgresql' do
|
46
|
+
gem 'rails', '~> 7.0.0'
|
47
|
+
gem 'pg', '~> 1.5'
|
48
|
+
end
|
49
|
+
|
50
|
+
appraise 'rails-7-0-mysql' do
|
51
|
+
gem 'rails', '~> 7.0.0'
|
52
|
+
gem 'mysql2', '~> 0.5'
|
53
|
+
end
|
54
|
+
|
55
|
+
appraise 'rails-7-0-sqlite3' do
|
56
|
+
gem 'rails', '~> 7.0.0'
|
57
|
+
gem 'sqlite3', '~> 1.4'
|
58
|
+
end
|
59
|
+
|
60
|
+
appraise 'rails-7-0-jdbc-postgresql' do
|
61
|
+
gem 'rails', '~> 7.0.0'
|
20
62
|
platforms :jruby do
|
21
63
|
gem 'activerecord-jdbc-adapter', '~> 70.0'
|
22
64
|
gem 'activerecord-jdbcpostgresql-adapter', '~> 70.0'
|
23
|
-
gem '
|
65
|
+
gem 'jdbc-postgres'
|
24
66
|
end
|
25
67
|
end
|
26
68
|
|
27
|
-
appraise 'rails-7-
|
28
|
-
gem 'rails', '~> 7.
|
29
|
-
platforms :
|
30
|
-
gem '
|
69
|
+
appraise 'rails-7-0-jdbc-mysql' do
|
70
|
+
gem 'rails', '~> 7.0.0'
|
71
|
+
platforms :jruby do
|
72
|
+
gem 'activerecord-jdbc-adapter', '~> 70.0'
|
73
|
+
gem 'activerecord-jdbcmysql-adapter', '~> 70.0'
|
74
|
+
gem 'jdbc-mysql'
|
31
75
|
end
|
76
|
+
end
|
77
|
+
|
78
|
+
appraise 'rails-7-0-jdbc-sqlite3' do
|
79
|
+
gem 'rails', '~> 7.0.0'
|
32
80
|
platforms :jruby do
|
33
|
-
gem 'activerecord-jdbc-adapter', '~>
|
34
|
-
gem 'activerecord-
|
35
|
-
gem '
|
81
|
+
gem 'activerecord-jdbc-adapter', '~> 70.0'
|
82
|
+
gem 'activerecord-jdbcsqlite3-adapter', '~> 70.0'
|
83
|
+
gem 'jdbc-sqlite3'
|
36
84
|
end
|
37
85
|
end
|
38
86
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
87
|
+
appraise 'rails-7-1-postgresql' do
|
88
|
+
gem 'rails', '~> 7.1.0'
|
89
|
+
gem 'pg', '~> 1.5'
|
90
|
+
end
|
91
|
+
|
92
|
+
appraise 'rails-7-1-mysql' do
|
93
|
+
gem 'rails', '~> 7.1.0'
|
94
|
+
gem 'mysql2', '~> 0.5'
|
95
|
+
end
|
96
|
+
|
97
|
+
appraise 'rails-7-1-sqlite3' do
|
98
|
+
gem 'rails', '~> 7.1.0'
|
99
|
+
gem 'sqlite3', '~> 2.1'
|
100
|
+
end
|
101
|
+
|
102
|
+
appraise 'rails-7-2-postgresql' do
|
103
|
+
gem 'rails', '~> 7.2.0'
|
104
|
+
gem 'pg', '~> 1.5'
|
105
|
+
end
|
106
|
+
|
107
|
+
appraise 'rails-7-2-mysql' do
|
108
|
+
gem 'rails', '~> 7.2.0'
|
109
|
+
gem 'mysql2', '~> 0.5'
|
110
|
+
end
|
111
|
+
|
112
|
+
appraise 'rails-7-2-sqlite3' do
|
113
|
+
gem 'rails', '~> 7.2.0'
|
114
|
+
gem 'sqlite3', '~> 2.1'
|
115
|
+
end
|
116
|
+
|
117
|
+
appraise 'rails-8-0-postgresql' do
|
118
|
+
gem 'rails', '~> 8.0.0'
|
119
|
+
gem 'pg', '~> 1.5'
|
120
|
+
end
|
121
|
+
|
122
|
+
appraise 'rails-8-0-mysql' do
|
123
|
+
gem 'rails', '~> 8.0.0'
|
124
|
+
gem 'mysql2', '~> 0.5'
|
125
|
+
end
|
126
|
+
|
127
|
+
appraise 'rails-8-0-sqlite3' do
|
128
|
+
gem 'rails', '~> 8.0.0'
|
129
|
+
gem 'sqlite3', '~> 2.1'
|
130
|
+
end
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a safe, welcoming, and inclusive experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
- Demonstrating empathy and kindness toward other people
|
14
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
- Giving and gracefully accepting constructive feedback
|
16
|
+
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
- Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
- The use of sexualized language or imagery, and sexual attention or advances of any kind
|
22
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
23
|
+
- Public or private harassment
|
24
|
+
- Publishing others’ private information, such as a physical or email address, without their explicit permission
|
25
|
+
- Other conduct which could reasonably be considered inappropriate in a professional setting
|
26
|
+
|
27
|
+
## Enforcement Responsibilities
|
28
|
+
|
29
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
32
|
+
|
33
|
+
## Scope
|
34
|
+
|
35
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
36
|
+
|
37
|
+
## Enforcement
|
38
|
+
|
39
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [mauricio@campusesp.com]. All complaints will be reviewed and investigated promptly and fairly.
|
40
|
+
|
41
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
42
|
+
|
43
|
+
## Enforcement Guidelines
|
44
|
+
|
45
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
46
|
+
|
47
|
+
### 1. Correction
|
48
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
49
|
+
|
50
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
51
|
+
|
52
|
+
### 2. Warning
|
53
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
54
|
+
|
55
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period. Violating these terms may lead to a temporary or permanent ban.
|
56
|
+
|
57
|
+
### 3. Temporary Ban
|
58
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
59
|
+
|
60
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period.
|
61
|
+
|
62
|
+
### 4. Permanent Ban
|
63
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
64
|
+
|
65
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
66
|
+
|
67
|
+
## Attribution
|
68
|
+
|
69
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
|
70
|
+
|
71
|
+
For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq.
|
data/Gemfile
CHANGED
@@ -3,3 +3,18 @@
|
|
3
3
|
source 'http://rubygems.org'
|
4
4
|
|
5
5
|
gemspec
|
6
|
+
|
7
|
+
gem 'appraisal', '~> 2.3'
|
8
|
+
gem 'bundler', '< 3.0'
|
9
|
+
gem 'pry', '~> 0.13'
|
10
|
+
gem 'rake', '< 14.0'
|
11
|
+
gem 'rspec', '~> 3.10'
|
12
|
+
gem 'rspec_junit_formatter', '~> 0.4'
|
13
|
+
gem 'rspec-rails', '>= 6.1.0', '< 8.1'
|
14
|
+
gem 'rubocop', '~> 1.12'
|
15
|
+
gem 'rubocop-performance', '~> 1.10'
|
16
|
+
gem 'rubocop-rails', '~> 2.10'
|
17
|
+
gem 'rubocop-rake', '~> 0.5'
|
18
|
+
gem 'rubocop-rspec', '~> 3.1'
|
19
|
+
gem 'rubocop-thread_safety', '~> 0.4'
|
20
|
+
gem 'simplecov', require: false
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Apartment
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/ros-apartment.svg)](https://badge.fury.io/rb/ros-apartment)
|
4
|
-
[![
|
4
|
+
[![codecov](https://codecov.io/gh/rails-on-services/apartment/graph/badge.svg?token=Q4I5QL78SA)](https://codecov.io/gh/rails-on-services/apartment)
|
5
5
|
|
6
6
|
*Multitenancy for Rails and ActiveRecord*
|
7
7
|
|
@@ -9,21 +9,17 @@ Apartment provides tools to help you deal with multiple tenants in your Rails
|
|
9
9
|
application. If you need to have certain data sequestered based on account or company,
|
10
10
|
but still allow some data to exist in a common tenant, Apartment can help.
|
11
11
|
|
12
|
-
## Apartment
|
12
|
+
## Apartment Fork: ros-apartment
|
13
13
|
|
14
|
-
|
15
|
-
came. Since we wanted to upgrade our application to Rails 6 we decided to fork
|
16
|
-
and start some development to support Rails 6. Because we don't have access
|
17
|
-
to the apartment gem itself, the solution was to release it under a different
|
18
|
-
name but providing the exact same API as it was before.
|
14
|
+
This gem is a fork of the original Apartment gem, which is no longer maintained. We have continued development under the name `ros-apartment` to keep the gem up-to-date and compatible with the latest versions of Rails. `ros-apartment` is designed as a drop-in replacement for the original, allowing you to seamlessly transition your application without code changes.
|
19
15
|
|
20
|
-
##
|
16
|
+
## Community Support
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
This project thrives on community support. Whether you have an idea for a new feature, find a bug, or need help with `ros-apartment`, we encourage you to participate! For questions and troubleshooting, check out our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to connect with the community. You can also open issues or submit pull requests directly. We are committed to maintaining `ros-apartment` and ensuring it remains a valuable tool for Rails developers.
|
19
|
+
|
20
|
+
### Maintainer Update
|
21
|
+
|
22
|
+
As of May 2024, Apartment is maintained with the support of [CampusESP](https://www.campusesp.com). We continue to keep Apartment open-source under the MIT license. We also want to recognize and thank the previous maintainers for their valuable contributions to this project.
|
27
23
|
|
28
24
|
## Installation
|
29
25
|
|
@@ -47,10 +43,6 @@ Configure as needed using the docs below.
|
|
47
43
|
That's all you need to set up the Apartment libraries. If you want to switch tenants
|
48
44
|
on a per-user basis, look under "Usage - Switching tenants per request", below.
|
49
45
|
|
50
|
-
> NOTE: If using [postgresql schemas](http://www.postgresql.org/docs/9.0/static/ddl-schemas.html) you must use:
|
51
|
-
>
|
52
|
-
> * for Rails 3.1.x: _Rails ~> 3.1.2_, it contains a [patch](https://github.com/rails/rails/pull/3232) that makes prepared statements work with multiple schemas
|
53
|
-
|
54
46
|
## Usage
|
55
47
|
|
56
48
|
### Video Tutorial
|
@@ -630,24 +622,50 @@ $ APARTMENT_DISABLE_INIT=true DATABASE_URL=postgresql://localhost:1234/buk_devel
|
|
630
622
|
# 1
|
631
623
|
```
|
632
624
|
|
633
|
-
##
|
625
|
+
## Contribution Guidelines
|
626
|
+
|
627
|
+
We welcome and appreciate contributions to `ros-apartment`! Whether you want to report a bug, propose a new feature, or submit a pull request, your help keeps this project thriving. Please review the guidelines below to ensure a smooth collaboration process.
|
628
|
+
|
629
|
+
### How to Contribute
|
630
|
+
|
631
|
+
1. **Check Existing Issues and Discussions**
|
632
|
+
- Before opening a new issue, please check the [issue tracker](https://github.com/rails-on-services/apartment/issues) and our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to see if the topic has already been reported or discussed. This helps us avoid duplication and focus on solving the issue efficiently.
|
633
|
+
|
634
|
+
2. **Submitting a Bug Report**
|
635
|
+
- Ensure your report includes a clear description of the problem, steps to reproduce, and relevant logs or error messages.
|
636
|
+
- If possible, provide a minimal reproducible example or a failing test case that demonstrates the issue.
|
637
|
+
|
638
|
+
3. **Proposing a Feature**
|
639
|
+
- For new features, open an issue to discuss your idea before starting development. This allows the maintainers and community to provide feedback and ensure the feature aligns with the project's goals.
|
640
|
+
- Please be as detailed as possible when describing the feature, its use case, and its potential impact on the existing functionality.
|
641
|
+
|
642
|
+
4. **Submitting a Pull Request**
|
643
|
+
- Fork the repository and create a feature branch (`git checkout -b my-feature-branch`).
|
644
|
+
- Follow the existing code style and ensure your changes are well-documented and tested.
|
645
|
+
- Run the tests locally to verify that your changes do not introduce new issues.
|
646
|
+
- Use [Appraisal](https://github.com/thoughtbot/appraisal) to test against multiple Rails versions. Ensure all tests pass for supported Rails versions.
|
647
|
+
- Submit your pull request to the `development` branch, not `main`.
|
648
|
+
- Include a detailed description of your changes and reference any related issue numbers (e.g., "Fixes #123" or "Closes #456").
|
649
|
+
|
650
|
+
5. **Code Review and Merging Process**
|
651
|
+
- The maintainers will review your pull request and may provide feedback or request changes. We appreciate your patience during this process, as we strive to maintain a high standard for code quality.
|
652
|
+
- Once approved, your pull request will be merged into the `development` branch. Periodically, we merge the `development` branch into `main` for official releases.
|
653
|
+
|
654
|
+
6. **Testing**
|
655
|
+
- Ensure your code is thoroughly tested. We do not merge code changes without adequate tests. Use RSpec for unit and integration tests.
|
656
|
+
- If your contribution affects multiple versions of Rails, use Appraisal to verify compatibility across versions.
|
657
|
+
- Rake tasks (see the Rakefile) are available to help set up your test databases and run tests.
|
634
658
|
|
635
|
-
|
636
|
-
* Copy them into the same directory but with the name `database.yml`
|
637
|
-
* Edit them to fit your own settings
|
638
|
-
* Rake tasks (see the Rakefile) will help you setup your dbs necessary to run tests
|
639
|
-
* Please issue pull requests to the `development` branch. All development happens here, master is used for releases.
|
640
|
-
* Ensure that your code is accompanied with tests. No code will be merged without tests
|
659
|
+
### Code of Conduct
|
641
660
|
|
642
|
-
|
661
|
+
We are committed to providing a welcoming and inclusive environment for all contributors. Please review and adhere to our [Code of Conduct](CODE_OF_CONDUCT.md) when participating in the project.
|
643
662
|
|
644
|
-
###
|
663
|
+
### Questions and Support
|
645
664
|
|
646
|
-
|
647
|
-
If you face problems running bundle install in OSX, try installing the gem running:
|
665
|
+
If you have any questions or need support while contributing or using `ros-apartment`, visit our [Discussions board](https://github.com/rails-on-services/apartment/discussions) to ask questions and connect with the maintainer team and community.
|
648
666
|
|
649
|
-
|
667
|
+
We look forward to your contributions and thank you for helping us keep `ros-apartment` a reliable and robust tool for the Rails community!
|
650
668
|
|
651
669
|
## License
|
652
670
|
|
653
|
-
Apartment
|
671
|
+
Apartment remains an open-source project under the [MIT License](http://www.opensource.org/licenses/MIT). We value open-source principles and aim to make multitenancy accessible to all Rails developers.
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'appraisal'
|
|
13
13
|
require 'rspec'
|
14
14
|
require 'rspec/core/rake_task'
|
15
15
|
|
16
|
-
RSpec::Core::RakeTask.new(spec: %w[db:
|
16
|
+
RSpec::Core::RakeTask.new(spec: %w[db:load_credentials db:test:prepare]) do |spec|
|
17
17
|
spec.pattern = 'spec/**/*_spec.rb'
|
18
18
|
# spec.rspec_opts = '--order rand:47078'
|
19
19
|
end
|
@@ -37,19 +37,36 @@ task default: :spec
|
|
37
37
|
|
38
38
|
namespace :db do
|
39
39
|
namespace :test do
|
40
|
-
|
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
|
41
54
|
end
|
42
55
|
|
43
56
|
desc "copy sample database credential files over if real files don't exist"
|
44
|
-
task :
|
45
|
-
|
46
|
-
|
47
|
-
rails_db_file = 'spec/dummy/config/database.yml'
|
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')
|
48
60
|
|
49
|
-
unless
|
50
|
-
|
51
|
-
|
52
|
-
|
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)
|
53
70
|
end
|
54
71
|
end
|
55
72
|
|
@@ -67,11 +84,11 @@ namespace :postgres do
|
|
67
84
|
params << "-p#{pg_config['port']}" if pg_config['port']
|
68
85
|
|
69
86
|
begin
|
70
|
-
|
87
|
+
system("createdb #{params.join(' ')}")
|
71
88
|
rescue StandardError
|
72
89
|
'test db already exists'
|
73
90
|
end
|
74
|
-
ActiveRecord::Base.establish_connection
|
91
|
+
ActiveRecord::Base.establish_connection(pg_config)
|
75
92
|
migrate
|
76
93
|
end
|
77
94
|
|
@@ -83,7 +100,7 @@ namespace :postgres do
|
|
83
100
|
params << "-U#{pg_config['username']}"
|
84
101
|
params << "-h#{pg_config['host']}" if pg_config['host']
|
85
102
|
params << "-p#{pg_config['port']}" if pg_config['port']
|
86
|
-
|
103
|
+
system("dropdb #{params.join(' ')}")
|
87
104
|
end
|
88
105
|
end
|
89
106
|
|
@@ -96,14 +113,14 @@ namespace :mysql do
|
|
96
113
|
params = []
|
97
114
|
params << "-h #{my_config['host']}" if my_config['host']
|
98
115
|
params << "-u #{my_config['username']}" if my_config['username']
|
99
|
-
params << "-p#{my_config['password']}" if my_config['password']
|
100
|
-
params << "
|
116
|
+
params << "-p #{my_config['password']}" if my_config['password']
|
117
|
+
params << "-P #{my_config['port']}" if my_config['port']
|
101
118
|
begin
|
102
|
-
|
119
|
+
system("mysqladmin #{params.join(' ')} create #{my_config['database']}")
|
103
120
|
rescue StandardError
|
104
121
|
'test db already exists'
|
105
122
|
end
|
106
|
-
ActiveRecord::Base.establish_connection
|
123
|
+
ActiveRecord::Base.establish_connection(my_config)
|
107
124
|
migrate
|
108
125
|
end
|
109
126
|
|
@@ -113,13 +130,12 @@ namespace :mysql do
|
|
113
130
|
params = []
|
114
131
|
params << "-h #{my_config['host']}" if my_config['host']
|
115
132
|
params << "-u #{my_config['username']}" if my_config['username']
|
116
|
-
params << "-p#{my_config['password']}" if my_config['password']
|
117
|
-
params << "
|
118
|
-
|
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")
|
119
136
|
end
|
120
137
|
end
|
121
138
|
|
122
|
-
# TODO: clean this up
|
123
139
|
def config
|
124
140
|
Apartment::Test.config['connections']
|
125
141
|
end
|
@@ -133,7 +149,9 @@ def my_config
|
|
133
149
|
end
|
134
150
|
|
135
151
|
def migrate
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
139
157
|
end
|
@@ -15,10 +15,10 @@ module ActiveRecord # :nodoc:
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
else
|
18
|
-
def connected_to_with_tenant(role: nil, prevent_writes: false, &blk)
|
18
|
+
def connected_to_with_tenant(role: nil, shard: nil, prevent_writes: false, &blk)
|
19
19
|
current_tenant = Apartment::Tenant.current
|
20
20
|
|
21
|
-
connected_to_without_tenant(role: role, prevent_writes: prevent_writes) do
|
21
|
+
connected_to_without_tenant(role: role, shard: shard, prevent_writes: prevent_writes) do
|
22
22
|
Apartment::Tenant.switch!(current_tenant)
|
23
23
|
yield(blk)
|
24
24
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This patch prevents `create_schema` from being added to db/schema.rb as schemas are managed by Apartment
|
4
|
+
# not ActiveRecord like they would be in a vanilla Rails setup.
|
5
|
+
|
6
|
+
require 'active_record/connection_adapters/abstract/schema_dumper'
|
7
|
+
require 'active_record/connection_adapters/postgresql/schema_dumper'
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
module ConnectionAdapters
|
11
|
+
module PostgreSQL
|
12
|
+
class SchemaDumper
|
13
|
+
alias _original_schemas schemas
|
14
|
+
def schemas(stream)
|
15
|
+
_original_schemas(stream) unless Apartment.use_schemas
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|