activerecord-precompiled 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +284 -0
- data/exe/ar-precompile +47 -0
- data/lib/active_record_precompiled/assoc_site.rb +65 -0
- data/lib/active_record_precompiled/build.rb +52 -0
- data/lib/active_record_precompiled/capture.rb +94 -0
- data/lib/active_record_precompiled/friendly_site.rb +49 -0
- data/lib/active_record_precompiled/keys.rb +41 -0
- data/lib/active_record_precompiled/preload.rb +619 -0
- data/lib/active_record_precompiled/railtie.rb +46 -0
- data/lib/active_record_precompiled/rewriter.rb +917 -0
- data/lib/active_record_precompiled/schema_dump.rb +181 -0
- data/lib/active_record_precompiled/scope_analyzer.rb +246 -0
- data/lib/active_record_precompiled/scope_check.rb +59 -0
- data/lib/active_record_precompiled/scopes.rb +32 -0
- data/lib/active_record_precompiled/site.rb +481 -0
- data/lib/active_record_precompiled/version.rb +5 -0
- data/lib/active_record_precompiled.rb +64 -0
- data/lib/activerecord-precompiled.rb +4 -0
- metadata +102 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveRecordPrecompiled
|
|
4
|
+
class Railtie < Rails::Railtie
|
|
5
|
+
rake_tasks do
|
|
6
|
+
namespace :ar_precompile do
|
|
7
|
+
desc "Rewrite ActiveRecord queries into precompiled SQLite calls, in place " \
|
|
8
|
+
"(production only unless FORCE=1; DRY_RUN=1 to preview; AR_PRECOMPILE_PATHS=app,lib; " \
|
|
9
|
+
"AR_PRECOMPILE_SCHEMA=auto|dump|database)"
|
|
10
|
+
task build: :environment do
|
|
11
|
+
# After loading the app: rake doesn't eager load, and models connect
|
|
12
|
+
# to their databases (connects_to) as they load.
|
|
13
|
+
Rails.application.eager_load!
|
|
14
|
+
ActiveRecordPrecompiled::SchemaDump.use(Rails.root, mode: ENV["AR_PRECOMPILE_SCHEMA"], out: $stdout)
|
|
15
|
+
ActiveRecordPrecompiled::Build.new(
|
|
16
|
+
root: Rails.root,
|
|
17
|
+
paths: ENV.fetch("AR_PRECOMPILE_PATHS", "app,lib").split(","),
|
|
18
|
+
env: Rails.env,
|
|
19
|
+
dry_run: ENV["DRY_RUN"] == "1",
|
|
20
|
+
force: ENV["FORCE"] == "1",
|
|
21
|
+
out: $stdout,
|
|
22
|
+
).run
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
namespace :schema do
|
|
26
|
+
desc "Write the schema the build needs to #{ActiveRecordPrecompiled::SchemaDump::PATH}, for builds " \
|
|
27
|
+
"without the database (docker build); run on production and commit it (FORCE=1 elsewhere)"
|
|
28
|
+
task dump: :environment do
|
|
29
|
+
unless Rails.env.production? || ENV["FORCE"] == "1"
|
|
30
|
+
abort "activerecord-precompiled: the build needs the production schema; run this with " \
|
|
31
|
+
"RAILS_ENV=production where the production database is, or override with FORCE=1"
|
|
32
|
+
end
|
|
33
|
+
Rails.application.eager_load! # every database a model connects to
|
|
34
|
+
ActiveRecordPrecompiled::SchemaDump.dump(Rails.root, out: $stdout)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
desc "List every scope and whether activerecord-precompiled can compile it (read-only, any environment)"
|
|
39
|
+
task scopes: :environment do
|
|
40
|
+
Rails.application.eager_load!
|
|
41
|
+
ActiveRecordPrecompiled::ScopeCheck.new(root: Rails.root).run(out: $stdout)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|