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.
@@ -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