activerecord-multi-tenant 1.2.0 → 2.4.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 +4 -4
- data/.github/workflows/active-record-multi-tenant-tests.yml +83 -0
- data/.gitignore +6 -0
- data/.readthedocs.yaml +15 -0
- data/.rspec +0 -0
- data/.rubocop.yml +51 -0
- data/Appraisals +6 -22
- data/CHANGELOG.md +51 -0
- data/Gemfile +3 -1
- data/LICENSE +0 -0
- data/README.md +3 -2
- data/Rakefile +1 -1
- data/activerecord-multi-tenant.gemspec +28 -23
- data/docker-compose.yml +24 -18
- data/docs/.gitignore +3 -0
- data/docs/Makefile +28 -0
- data/docs/api-reference.sh +10 -0
- data/docs/requirements.in +4 -0
- data/docs/requirements.txt +62 -0
- data/docs/source/_static/api-reference/ActiveRecord/Associations/Association.html +285 -0
- data/docs/source/_static/api-reference/ActiveRecord/Associations/ClassMethods.html +255 -0
- data/docs/source/_static/api-reference/ActiveRecord/Associations.html +117 -0
- data/docs/source/_static/api-reference/ActiveRecord/ConnectionAdapters/SchemaStatements.html +232 -0
- data/docs/source/_static/api-reference/ActiveRecord/ConnectionAdapters.html +126 -0
- data/docs/source/_static/api-reference/ActiveRecord/QueryMethods.html +336 -0
- data/docs/source/_static/api-reference/ActiveRecord/SchemaDumper.html +121 -0
- data/docs/source/_static/api-reference/ActiveRecord.html +130 -0
- data/docs/source/_static/api-reference/MultiTenant/ArelTenantVisitor.html +755 -0
- data/docs/source/_static/api-reference/MultiTenant/ArelVisitorsDepthFirst.html +208 -0
- data/docs/source/_static/api-reference/MultiTenant/BaseTenantEnforcementClause.html +462 -0
- data/docs/source/_static/api-reference/MultiTenant/Context.html +659 -0
- data/docs/source/_static/api-reference/MultiTenant/ControllerExtensions.html +202 -0
- data/docs/source/_static/api-reference/MultiTenant/CopyFromClient.html +186 -0
- data/docs/source/_static/api-reference/MultiTenant/CopyFromClientHelper.html +362 -0
- data/docs/source/_static/api-reference/MultiTenant/Current.html +124 -0
- data/docs/source/_static/api-reference/MultiTenant/DatabaseStatements.html +366 -0
- data/docs/source/_static/api-reference/MultiTenant/FastTruncate.html +226 -0
- data/docs/source/_static/api-reference/MultiTenant/MigrationExtensions.html +554 -0
- data/docs/source/_static/api-reference/MultiTenant/MissingTenantError.html +124 -0
- data/docs/source/_static/api-reference/MultiTenant/ModelExtensionsClassMethods.html +492 -0
- data/docs/source/_static/api-reference/MultiTenant/QueryMonitor.html +257 -0
- data/docs/source/_static/api-reference/MultiTenant/Table.html +419 -0
- data/docs/source/_static/api-reference/MultiTenant/TenantEnforcementClause.html +148 -0
- data/docs/source/_static/api-reference/MultiTenant/TenantIsImmutable.html +135 -0
- data/docs/source/_static/api-reference/MultiTenant/TenantJoinEnforcementClause.html +310 -0
- data/docs/source/_static/api-reference/MultiTenant/TenantValueVisitor.html +239 -0
- data/docs/source/_static/api-reference/MultiTenant.html +1454 -0
- data/docs/source/_static/api-reference/MultiTenantFindBy.html +180 -0
- data/docs/source/_static/api-reference/Sidekiq/Client.html +302 -0
- data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant/Client.html +217 -0
- data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant/Server.html +219 -0
- data/docs/source/_static/api-reference/Sidekiq/Middleware/MultiTenant.html +126 -0
- data/docs/source/_static/api-reference/Sidekiq.html +126 -0
- data/docs/source/_static/api-reference/_index.html +399 -0
- data/docs/source/_static/api-reference/class_list.html +51 -0
- data/docs/source/_static/api-reference/css/common.css +1 -0
- data/docs/source/_static/api-reference/css/full_list.css +58 -0
- data/docs/source/_static/api-reference/css/style.css +497 -0
- data/docs/source/_static/api-reference/file.README.html +167 -0
- data/docs/source/_static/api-reference/file_list.html +56 -0
- data/docs/source/_static/api-reference/frames.html +17 -0
- data/docs/source/_static/api-reference/index.html +167 -0
- data/docs/source/_static/api-reference/js/app.js +314 -0
- data/docs/source/_static/api-reference/js/full_list.js +216 -0
- data/docs/source/_static/api-reference/js/jquery.js +4 -0
- data/docs/source/_static/api-reference/method_list.html +715 -0
- data/docs/source/_static/api-reference/top-level-namespace.html +126 -0
- data/docs/source/_templates/.gitignore +4 -0
- data/docs/source/api-reference.rst +8 -0
- data/docs/source/appendix.rst +26 -0
- data/docs/source/changelog.rst +8 -0
- data/docs/source/community-and-support.rst +26 -0
- data/docs/source/conf.py +30 -0
- data/docs/source/contributing.rst +70 -0
- data/docs/source/getting-started.rst +37 -0
- data/docs/source/guides-and-tutorials.rst +129 -0
- data/docs/source/index.rst +54 -0
- data/docs/source/introduction.rst +33 -0
- data/docs/source/license.rst +22 -0
- data/docs/source/troubleshooting.rst +41 -0
- data/docs/source/usage-guide.rst +59 -0
- data/lib/activerecord-multi-tenant/arel_visitors_depth_first.rb +183 -174
- data/lib/activerecord-multi-tenant/controller_extensions.rb +15 -4
- data/lib/activerecord-multi-tenant/copy_from_client.rb +4 -0
- data/lib/activerecord-multi-tenant/fast_truncate.rb +4 -2
- data/lib/activerecord-multi-tenant/habtm.rb +50 -0
- data/lib/activerecord-multi-tenant/migrations.rb +87 -10
- data/lib/activerecord-multi-tenant/model_extensions.rb +98 -34
- data/lib/activerecord-multi-tenant/multi_tenant.rb +102 -29
- data/lib/activerecord-multi-tenant/query_monitor.rb +21 -5
- data/lib/activerecord-multi-tenant/query_rewriter.rb +122 -91
- data/lib/activerecord-multi-tenant/sidekiq.rb +46 -19
- data/lib/activerecord-multi-tenant/table_node.rb +13 -0
- data/lib/activerecord-multi-tenant/version.rb +1 -1
- data/lib/activerecord-multi-tenant.rb +3 -13
- data/lib/activerecord_multi_tenant.rb +13 -0
- data/spec/activerecord-multi-tenant/associations_spec.rb +42 -0
- data/spec/activerecord-multi-tenant/controller_extensions_spec.rb +3 -2
- data/spec/activerecord-multi-tenant/fast_truncate_spec.rb +8 -6
- data/spec/activerecord-multi-tenant/model_extensions_spec.rb +347 -143
- data/spec/activerecord-multi-tenant/multi_tenant_spec.rb +69 -13
- data/spec/activerecord-multi-tenant/query_rewriter_spec.rb +60 -59
- data/spec/activerecord-multi-tenant/record_callback_spec.rb +0 -0
- data/spec/activerecord-multi-tenant/record_finding_spec.rb +11 -11
- data/spec/activerecord-multi-tenant/record_modifications_spec.rb +23 -4
- data/spec/activerecord-multi-tenant/sidekiq_spec.rb +10 -10
- data/spec/database.yml +0 -0
- data/spec/schema.rb +43 -2
- data/spec/spec_helper.rb +52 -16
- data/spec/support/format_sql.rb +20 -0
- metadata +126 -36
- data/.github/workflows/CI.yml +0 -63
- data/gemfiles/.bundle/config +0 -2
- data/gemfiles/active_record_5.2.gemfile +0 -16
- data/gemfiles/active_record_6.0.gemfile +0 -8
- data/gemfiles/active_record_6.1.gemfile +0 -8
- data/gemfiles/active_record_7.0.gemfile +0 -8
- data/gemfiles/rails_5.2.gemfile +0 -16
- data/gemfiles/rails_6.0.gemfile +0 -8
- data/gemfiles/rails_6.1.gemfile +0 -8
- data/gemfiles/rails_7.0.gemfile +0 -8
- data/lib/activerecord-multi-tenant/persistence_extension.rb +0 -13
- data/lib/activerecord-multi-tenant/with_lock.rb +0 -15
- data/spec/activerecord-multi-tenant/schema_dumper_tester.rb +0 -0
@@ -0,0 +1,366 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: MultiTenant::DatabaseStatements
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.34
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "MultiTenant::DatabaseStatements";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (D)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">DatabaseStatements</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: MultiTenant::DatabaseStatements
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/activerecord-multi-tenant/query_rewriter.rb</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
<h2>
|
95
|
+
Instance Method Summary
|
96
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
97
|
+
</h2>
|
98
|
+
|
99
|
+
<ul class="summary">
|
100
|
+
|
101
|
+
<li class="public ">
|
102
|
+
<span class="summary_signature">
|
103
|
+
|
104
|
+
<a href="#delete-instance_method" title="#delete (instance method)">#<strong>delete</strong>(arel, name = nil, binds = []) ⇒ Object </a>
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
</span>
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
119
|
+
|
120
|
+
</li>
|
121
|
+
|
122
|
+
|
123
|
+
<li class="public ">
|
124
|
+
<span class="summary_signature">
|
125
|
+
|
126
|
+
<a href="#join_to_delete-instance_method" title="#join_to_delete (instance method)">#<strong>join_to_delete</strong>(delete, *args) ⇒ Object </a>
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
</span>
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
141
|
+
|
142
|
+
</li>
|
143
|
+
|
144
|
+
|
145
|
+
<li class="public ">
|
146
|
+
<span class="summary_signature">
|
147
|
+
|
148
|
+
<a href="#join_to_update-instance_method" title="#join_to_update (instance method)">#<strong>join_to_update</strong>(update, *args) ⇒ Object </a>
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
</span>
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
163
|
+
|
164
|
+
</li>
|
165
|
+
|
166
|
+
|
167
|
+
<li class="public ">
|
168
|
+
<span class="summary_signature">
|
169
|
+
|
170
|
+
<a href="#update-instance_method" title="#update (instance method)">#<strong>update</strong>(arel, name = nil, binds = []) ⇒ Object </a>
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
</span>
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
185
|
+
|
186
|
+
</li>
|
187
|
+
|
188
|
+
|
189
|
+
</ul>
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
<div id="instance_method_details" class="method_details_list">
|
195
|
+
<h2>Instance Method Details</h2>
|
196
|
+
|
197
|
+
|
198
|
+
<div class="method_details first">
|
199
|
+
<h3 class="signature first" id="delete-instance_method">
|
200
|
+
|
201
|
+
#<strong>delete</strong>(arel, name = nil, binds = []) ⇒ <tt>Object</tt>
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
</h3><table class="source_code">
|
208
|
+
<tr>
|
209
|
+
<td>
|
210
|
+
<pre class="lines">
|
211
|
+
|
212
|
+
|
213
|
+
268
|
214
|
+
269
|
215
|
+
270
|
216
|
+
271
|
217
|
+
272
|
218
|
+
273
|
219
|
+
274</pre>
|
220
|
+
</td>
|
221
|
+
<td>
|
222
|
+
<pre class="code"><span class="info file"># File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 268</span>
|
223
|
+
|
224
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_binds'>binds</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
225
|
+
<span class='id identifier rubyid_model'>model</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_multi_tenant_model_for_arel'><span class='object_link'><a href="../MultiTenant.html#multi_tenant_model_for_arel-class_method" title="MultiTenant.multi_tenant_model_for_arel (method)">multi_tenant_model_for_arel</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='rparen'>)</span>
|
226
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>&&</span> <span class='op'>!</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with_write_only_mode_enabled?'><span class='object_link'><a href="../MultiTenant.html#with_write_only_mode_enabled%3F-class_method" title="MultiTenant.with_write_only_mode_enabled? (method)">with_write_only_mode_enabled?</a></span></span> <span class='op'>&&</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_current_tenant_id'><span class='object_link'><a href="../MultiTenant.html#current_tenant_id-class_method" title="MultiTenant.current_tenant_id (method)">current_tenant_id</a></span></span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
227
|
+
<span class='id identifier rubyid_arel'>arel</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="TenantEnforcementClause.html" title="MultiTenant::TenantEnforcementClause (class)">TenantEnforcementClause</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="BaseTenantEnforcementClause.html#initialize-instance_method" title="MultiTenant::BaseTenantEnforcementClause#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_arel_table'>arel_table</span><span class='lbracket'>[</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_partition_key'>partition_key</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
228
|
+
<span class='kw'>end</span>
|
229
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_binds'>binds</span><span class='rparen'>)</span>
|
230
|
+
<span class='kw'>end</span></pre>
|
231
|
+
</td>
|
232
|
+
</tr>
|
233
|
+
</table>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<div class="method_details ">
|
237
|
+
<h3 class="signature " id="join_to_delete-instance_method">
|
238
|
+
|
239
|
+
#<strong>join_to_delete</strong>(delete, *args) ⇒ <tt>Object</tt>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
</h3><table class="source_code">
|
246
|
+
<tr>
|
247
|
+
<td>
|
248
|
+
<pre class="lines">
|
249
|
+
|
250
|
+
|
251
|
+
251
|
252
|
+
252
|
253
|
+
253
|
254
|
+
254
|
255
|
+
255
|
256
|
+
256
|
257
|
+
257
|
258
|
+
258</pre>
|
259
|
+
</td>
|
260
|
+
<td>
|
261
|
+
<pre class="code"><span class="info file"># File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 251</span>
|
262
|
+
|
263
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_join_to_delete'>join_to_delete</span><span class='lparen'>(</span><span class='id identifier rubyid_delete'>delete</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
264
|
+
<span class='id identifier rubyid_delete'>delete</span> <span class='op'>=</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_delete'>delete</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
265
|
+
<span class='id identifier rubyid_model'>model</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_multi_tenant_model_for_table'><span class='object_link'><a href="../MultiTenant.html#multi_tenant_model_for_table-class_method" title="MultiTenant.multi_tenant_model_for_table (method)">multi_tenant_model_for_table</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_delete'>delete</span><span class='period'>.</span><span class='id identifier rubyid_ast'>ast</span><span class='period'>.</span><span class='id identifier rubyid_left'>left</span><span class='period'>.</span><span class='id identifier rubyid_table_name'>table_name</span><span class='rparen'>)</span>
|
266
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>&&</span> <span class='op'>!</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with_write_only_mode_enabled?'><span class='object_link'><a href="../MultiTenant.html#with_write_only_mode_enabled%3F-class_method" title="MultiTenant.with_write_only_mode_enabled? (method)">with_write_only_mode_enabled?</a></span></span> <span class='op'>&&</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_current_tenant_id'><span class='object_link'><a href="../MultiTenant.html#current_tenant_id-class_method" title="MultiTenant.current_tenant_id (method)">current_tenant_id</a></span></span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
267
|
+
<span class='id identifier rubyid_delete'>delete</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="TenantEnforcementClause.html" title="MultiTenant::TenantEnforcementClause (class)">TenantEnforcementClause</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="BaseTenantEnforcementClause.html#initialize-instance_method" title="MultiTenant::BaseTenantEnforcementClause#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_arel_table'>arel_table</span><span class='lbracket'>[</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_partition_key'>partition_key</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
268
|
+
<span class='kw'>end</span>
|
269
|
+
<span class='id identifier rubyid_delete'>delete</span>
|
270
|
+
<span class='kw'>end</span></pre>
|
271
|
+
</td>
|
272
|
+
</tr>
|
273
|
+
</table>
|
274
|
+
</div>
|
275
|
+
|
276
|
+
<div class="method_details ">
|
277
|
+
<h3 class="signature " id="join_to_update-instance_method">
|
278
|
+
|
279
|
+
#<strong>join_to_update</strong>(update, *args) ⇒ <tt>Object</tt>
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
</h3><table class="source_code">
|
286
|
+
<tr>
|
287
|
+
<td>
|
288
|
+
<pre class="lines">
|
289
|
+
|
290
|
+
|
291
|
+
242
|
292
|
+
243
|
293
|
+
244
|
294
|
+
245
|
295
|
+
246
|
296
|
+
247
|
297
|
+
248
|
298
|
+
249</pre>
|
299
|
+
</td>
|
300
|
+
<td>
|
301
|
+
<pre class="code"><span class="info file"># File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 242</span>
|
302
|
+
|
303
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_join_to_update'>join_to_update</span><span class='lparen'>(</span><span class='id identifier rubyid_update'>update</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
304
|
+
<span class='id identifier rubyid_update'>update</span> <span class='op'>=</span> <span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_update'>update</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
305
|
+
<span class='id identifier rubyid_model'>model</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_multi_tenant_model_for_table'><span class='object_link'><a href="../MultiTenant.html#multi_tenant_model_for_table-class_method" title="MultiTenant.multi_tenant_model_for_table (method)">multi_tenant_model_for_table</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_update'>update</span><span class='period'>.</span><span class='id identifier rubyid_ast'>ast</span><span class='period'>.</span><span class='id identifier rubyid_relation'>relation</span><span class='period'>.</span><span class='id identifier rubyid_table_name'>table_name</span><span class='rparen'>)</span>
|
306
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>&&</span> <span class='op'>!</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with_write_only_mode_enabled?'><span class='object_link'><a href="../MultiTenant.html#with_write_only_mode_enabled%3F-class_method" title="MultiTenant.with_write_only_mode_enabled? (method)">with_write_only_mode_enabled?</a></span></span> <span class='op'>&&</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_current_tenant_id'><span class='object_link'><a href="../MultiTenant.html#current_tenant_id-class_method" title="MultiTenant.current_tenant_id (method)">current_tenant_id</a></span></span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
307
|
+
<span class='id identifier rubyid_update'>update</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="TenantEnforcementClause.html" title="MultiTenant::TenantEnforcementClause (class)">TenantEnforcementClause</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="BaseTenantEnforcementClause.html#initialize-instance_method" title="MultiTenant::BaseTenantEnforcementClause#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_arel_table'>arel_table</span><span class='lbracket'>[</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_partition_key'>partition_key</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
308
|
+
<span class='kw'>end</span>
|
309
|
+
<span class='id identifier rubyid_update'>update</span>
|
310
|
+
<span class='kw'>end</span></pre>
|
311
|
+
</td>
|
312
|
+
</tr>
|
313
|
+
</table>
|
314
|
+
</div>
|
315
|
+
|
316
|
+
<div class="method_details ">
|
317
|
+
<h3 class="signature " id="update-instance_method">
|
318
|
+
|
319
|
+
#<strong>update</strong>(arel, name = nil, binds = []) ⇒ <tt>Object</tt>
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
</h3><table class="source_code">
|
326
|
+
<tr>
|
327
|
+
<td>
|
328
|
+
<pre class="lines">
|
329
|
+
|
330
|
+
|
331
|
+
260
|
332
|
+
261
|
333
|
+
262
|
334
|
+
263
|
335
|
+
264
|
336
|
+
265
|
337
|
+
266</pre>
|
338
|
+
</td>
|
339
|
+
<td>
|
340
|
+
<pre class="code"><span class="info file"># File 'lib/activerecord-multi-tenant/query_rewriter.rb', line 260</span>
|
341
|
+
|
342
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_update'>update</span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_binds'>binds</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
343
|
+
<span class='id identifier rubyid_model'>model</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_multi_tenant_model_for_arel'><span class='object_link'><a href="../MultiTenant.html#multi_tenant_model_for_arel-class_method" title="MultiTenant.multi_tenant_model_for_arel (method)">multi_tenant_model_for_arel</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='rparen'>)</span>
|
344
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>&&</span> <span class='op'>!</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_with_write_only_mode_enabled?'><span class='object_link'><a href="../MultiTenant.html#with_write_only_mode_enabled%3F-class_method" title="MultiTenant.with_write_only_mode_enabled? (method)">with_write_only_mode_enabled?</a></span></span> <span class='op'>&&</span> <span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='period'>.</span><span class='id identifier rubyid_current_tenant_id'><span class='object_link'><a href="../MultiTenant.html#current_tenant_id-class_method" title="MultiTenant.current_tenant_id (method)">current_tenant_id</a></span></span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
|
345
|
+
<span class='id identifier rubyid_arel'>arel</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="TenantEnforcementClause.html" title="MultiTenant::TenantEnforcementClause (class)">TenantEnforcementClause</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="BaseTenantEnforcementClause.html#initialize-instance_method" title="MultiTenant::BaseTenantEnforcementClause#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_arel_table'>arel_table</span><span class='lbracket'>[</span><span class='id identifier rubyid_model'>model</span><span class='period'>.</span><span class='id identifier rubyid_partition_key'>partition_key</span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
346
|
+
<span class='kw'>end</span>
|
347
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='id identifier rubyid_arel'>arel</span><span class='comma'>,</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_binds'>binds</span><span class='rparen'>)</span>
|
348
|
+
<span class='kw'>end</span></pre>
|
349
|
+
</td>
|
350
|
+
</tr>
|
351
|
+
</table>
|
352
|
+
</div>
|
353
|
+
|
354
|
+
</div>
|
355
|
+
|
356
|
+
</div>
|
357
|
+
|
358
|
+
<div id="footer">
|
359
|
+
Generated on Sat May 27 10:16:24 2023 by
|
360
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
361
|
+
0.9.34 (ruby-3.2.2).
|
362
|
+
</div>
|
363
|
+
|
364
|
+
</div>
|
365
|
+
</body>
|
366
|
+
</html>
|
@@ -0,0 +1,226 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: MultiTenant::FastTruncate
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.34
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "MultiTenant::FastTruncate";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (F)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../MultiTenant.html" title="MultiTenant (module)">MultiTenant</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">FastTruncate</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: MultiTenant::FastTruncate
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/activerecord-multi-tenant/fast_truncate.rb</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
<h2>
|
95
|
+
Class Method Summary
|
96
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
97
|
+
</h2>
|
98
|
+
|
99
|
+
<ul class="summary">
|
100
|
+
|
101
|
+
<li class="public ">
|
102
|
+
<span class="summary_signature">
|
103
|
+
|
104
|
+
<a href="#run-class_method" title="run (class method)">.<strong>run</strong>(exclude: ['schema_migrations']) ⇒ Object </a>
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
</span>
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
119
|
+
|
120
|
+
</li>
|
121
|
+
|
122
|
+
|
123
|
+
</ul>
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
<div id="class_method_details" class="method_details_list">
|
129
|
+
<h2>Class Method Details</h2>
|
130
|
+
|
131
|
+
|
132
|
+
<div class="method_details first">
|
133
|
+
<h3 class="signature first" id="run-class_method">
|
134
|
+
|
135
|
+
.<strong>run</strong>(exclude: ['schema_migrations']) ⇒ <tt>Object</tt>
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
</h3><table class="source_code">
|
142
|
+
<tr>
|
143
|
+
<td>
|
144
|
+
<pre class="lines">
|
145
|
+
|
146
|
+
|
147
|
+
6
|
148
|
+
7
|
149
|
+
8
|
150
|
+
9
|
151
|
+
10
|
152
|
+
11
|
153
|
+
12
|
154
|
+
13
|
155
|
+
14
|
156
|
+
15
|
157
|
+
16
|
158
|
+
17
|
159
|
+
18
|
160
|
+
19
|
161
|
+
20
|
162
|
+
21
|
163
|
+
22
|
164
|
+
23
|
165
|
+
24
|
166
|
+
25
|
167
|
+
26
|
168
|
+
27
|
169
|
+
28
|
170
|
+
29
|
171
|
+
30
|
172
|
+
31
|
173
|
+
32
|
174
|
+
33
|
175
|
+
34</pre>
|
176
|
+
</td>
|
177
|
+
<td>
|
178
|
+
<pre class="code"><span class="info file"># File 'lib/activerecord-multi-tenant/fast_truncate.rb', line 6</span>
|
179
|
+
|
180
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='label'>exclude:</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>schema_migrations</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
181
|
+
<span class='comment'># This is a slightly faster version of DatabaseCleaner.clean_with(:truncation, pre_count: true)
|
182
|
+
</span> <span class='const'><span class='object_link'><a href="../ActiveRecord.html" title="ActiveRecord (module)">ActiveRecord</a></span></span><span class='op'>::</span><span class='const'>Base</span><span class='period'>.</span><span class='id identifier rubyid_connection'>connection</span><span class='period'>.</span><span class='id identifier rubyid_execute'>execute</span> <span class='id identifier rubyid_format'>format</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>%(</span><span class='tstring_content'>
|
183
|
+
DO LANGUAGE plpgsql $$
|
184
|
+
DECLARE
|
185
|
+
t record;
|
186
|
+
tables text[];
|
187
|
+
seq_exists boolean;
|
188
|
+
needs_truncate boolean;
|
189
|
+
BEGIN
|
190
|
+
FOR t IN SELECT schemaname, tablename FROM pg_tables WHERE schemaname = 'public' AND tablename NOT IN (%s) LOOP
|
191
|
+
EXECUTE 'SELECT EXISTS (SELECT * from pg_class c WHERE c.relkind = ''S''
|
192
|
+
AND c.relname=''' || t.tablename || '_id_seq'')' into seq_exists;
|
193
|
+
IF seq_exists THEN
|
194
|
+
EXECUTE 'SELECT is_called FROM ' || t.tablename || '_id_seq' INTO needs_truncate;
|
195
|
+
ELSE
|
196
|
+
needs_truncate := true;
|
197
|
+
END IF;
|
198
|
+
|
199
|
+
IF needs_truncate THEN
|
200
|
+
tables := array_append(tables, quote_ident(t.schemaname) || '.' || quote_ident(t.tablename));
|
201
|
+
END IF;
|
202
|
+
END LOOP;
|
203
|
+
|
204
|
+
IF array_length(tables, 1) > 0 THEN
|
205
|
+
EXECUTE 'TRUNCATE TABLE ' || array_to_string(tables, ', ') || ' RESTART IDENTITY CASCADE';
|
206
|
+
END IF;
|
207
|
+
END$$;</span><span class='tstring_end'>)</span></span><span class='comma'>,</span> <span class='id identifier rubyid_exclude'>exclude</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_t'>t</span><span class='op'>|</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>'</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_t'>t</span><span class='embexpr_end'>}</span><span class='tstring_content'>'</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>\n</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
208
|
+
<span class='kw'>end</span></pre>
|
209
|
+
</td>
|
210
|
+
</tr>
|
211
|
+
</table>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
</div>
|
215
|
+
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<div id="footer">
|
219
|
+
Generated on Sat May 27 10:16:24 2023 by
|
220
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
221
|
+
0.9.34 (ruby-3.2.2).
|
222
|
+
</div>
|
223
|
+
|
224
|
+
</div>
|
225
|
+
</body>
|
226
|
+
</html>
|