full_search 0.3.5 → 0.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3b466311e2305f90987a48ff58cee59f4c81af6e960b5fcd2fe09cf845b985b
4
- data.tar.gz: 1d355e22aa06d280d984d7da1df90e57a8ca4a5f5676b7870424f2b048c051ba
3
+ metadata.gz: 01b6db287587e57e3bc4f7226eff10257303eadf30c6a6a64e53be1e2e52afb5
4
+ data.tar.gz: 01ec5e01cf2d479245338c5a7ab23f778a9f953c78c7a0a1ab4f428a4472c98c
5
5
  SHA512:
6
- metadata.gz: 9489ff8c9bf04c59b6380cd1810871a39a947421754379ac6fb1c1cb36cbf7850a753d0a7354e25f38b591aeae63cbb05cd7d8c0f187bb84ba6ef191aba19755
7
- data.tar.gz: a23ce1270f3ac088b02774a43178fb277811e7df65a7d518f3fde4b8899cfb2db3f07164c72ea75ec26bb3b8ed9ef29b94d05aa53009ef1f82dd9d1bb4d14f79
6
+ metadata.gz: 6a3bd6143a47be3e7abd89df28506f247ee562205372ee9b5bedf6064d463413e212b7bca67dffb3e980531963e55984750adfed5504cf70b7e0dc7fa250185b
7
+ data.tar.gz: 3b793c3bfd872cf1a247a18c030ade28433d16d40bc71438d35dc79be2cd306d15ec79f0afc371c0866ef9feeca8d3292ed9f8af35c9bb6c572b8073be88a12b
data/README.md CHANGED
@@ -125,6 +125,22 @@ These two operations are often confused:
125
125
  > within the same process/connection. For multi-process or multi-host deployments,
126
126
  > run `full_search:rebuild` from a single deployment step.
127
127
 
128
+ ### First-deploy setup
129
+
130
+ After `db:prepare` creates your application tables, FTS virtual tables like `customers_fts` do not yet exist. Run `full_search:prepare` to create them:
131
+
132
+ ```bash
133
+ bin/rails full_search:prepare
134
+ ```
135
+
136
+ For Docker-based deployments, add this to your entrypoint script after `db:prepare:with_data`:
137
+
138
+ ```bash
139
+ ./bin/rails full_search:prepare
140
+ ```
141
+
142
+ The `full_search:prepare` task is idempotent — it only creates missing tables and installs triggers. It will not drop or rebuild existing indexes, making it safe to run on every deploy.
143
+
128
144
  ### Auto-rebuild on app load
129
145
 
130
146
  When `auto_rebuild_schema` is enabled (default in the generated initializer), the railtie hooks into Rails `after_initialize` and:
@@ -162,6 +178,7 @@ bin/rails full_search:reset
162
178
 
163
179
  | Task | Description |
164
180
  |------|-------------|
181
+ | `full_search:prepare` | Idempotent setup — creates missing FTS tables and triggers without dropping existing ones. Safe to run on every deploy. Add to your Docker entrypoint after `db:prepare:with_data` for first-deploy automation. |
165
182
  | `full_search:rebuild` | Drops and recreates the FTS virtual table only when the DSL config hash has changed (safe for production). Pass model names to target specific tables. |
166
183
  | `full_search:reset` | Force a full rebuild — drops and recreates all FTS tables regardless of config hash. Use when data may be out of sync. |
167
184
  | `full_search:optimize` | Run FTS5 [`optimize`](https://www.sqlite.org/fts5.html#the_optimize_command) to merge b-tree segments. Useful after bulk updates. |
@@ -223,6 +240,17 @@ end
223
240
 
224
241
  When this option is `true`, the first search that detects a stale index automatically calls `FullSearch::Index.rebuild_if_needed!` and then proceeds with the query, so you don't need to restart the server or run a Rake task during iterative development. In production, this defaults to `false`; use `full_search:rebuild` or boot-time `auto_rebuild_schema` instead.
225
242
 
243
+ ### Missing table error
244
+
245
+ When the FTS table does not exist and a search is attempted, `full_search` raises `MissingTableError` with a clear message:
246
+
247
+ ```
248
+ FullSearch::MissingTableError: FTS table `customers_fts` does not exist.
249
+ Run `bin/rails full_search:prepare` to create it.
250
+ ```
251
+
252
+ This mirrors how Rails handles missing database tables — you see the error, run the task, and move on. Add `full_search:prepare` to your deploy pipeline or Docker entrypoint after `db:prepare:with_data` to prevent the error in production.
253
+
226
254
  ## Query operators
227
255
 
228
256
  ```ruby
@@ -8,5 +8,6 @@ module FullSearch
8
8
  class InvalidFieldError < Error; end
9
9
  class NotConfiguredError < Error; end
10
10
  class UnsupportedDatabaseError < Error; end
11
+ class MissingTableError < Error; end
11
12
  class InvalidQueryError < Error; end
12
13
  end
@@ -174,6 +174,10 @@ module FullSearch
174
174
  row&.[]("config_hash")
175
175
  end
176
176
 
177
+ def missing_table?(model)
178
+ !table_exists?(model)
179
+ end
180
+
177
181
  private
178
182
 
179
183
  def connection
@@ -78,7 +78,15 @@ module FullSearch
78
78
  end
79
79
 
80
80
  def check_stale_config!
81
- stored = FullSearch::Index.stored_config_hash(model)
81
+ if FullSearch::Index.missing_table?(model)
82
+ raise MissingTableError, "FTS table `#{FullSearch::Index.fts_table_name(model)}` does not exist. Run `bin/rails full_search:prepare` to create it."
83
+ end
84
+
85
+ stored = begin
86
+ FullSearch::Index.stored_config_hash(model)
87
+ rescue StandardError
88
+ nil
89
+ end
82
90
  return unless stored
83
91
 
84
92
  return if stored == dsl.config_hash
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FullSearch
4
- VERSION = "0.3.5"
4
+ VERSION = "0.3.6"
5
5
  end
@@ -17,6 +17,29 @@ def resolve_full_search_models(args)
17
17
  end
18
18
 
19
19
  namespace :full_search do
20
+ desc "Create full_search FTS tables and triggers if missing (idempotent, safe for first deploy)"
21
+ task :prepare, [:models] => :environment do |_t, args|
22
+ Rails.application.eager_load!
23
+
24
+ models = if args[:models]
25
+ args[:models].split(",").map do |name|
26
+ klass = begin
27
+ name.singularize.camelize.constantize
28
+ rescue NameError, LoadError
29
+ FullSearch.models.find { |m| m.table_name == name }
30
+ end
31
+ klass
32
+ end.compact
33
+ else
34
+ FullSearch.models
35
+ end
36
+
37
+ FullSearch.setup!
38
+ models.each do |model|
39
+ puts "Prepared #{FullSearch::Index.fts_table_name(model)}"
40
+ end
41
+ end
42
+
20
43
  desc "Rebuild indexes when DSL has changed (checks config hash; safe for production)"
21
44
  task :rebuild, [:models] => :environment do |_t, args|
22
45
  Rails.application.eager_load!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: full_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben D'Angelo