You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85Lines changed: 85 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,91 @@ production:
91
91
92
92
> Note: The connection string expects the `couchbases://` or `couchbase://` part.
93
93
94
+
## Couchbase Index Management
95
+
96
+
This application requires specific N1QL indexes on the `travel-sample` bucket to function correctly. These indexes optimize the SQL++ queries used by the application for filtering and joining documents.
97
+
98
+
### Automatic Index Setup
99
+
100
+
Indexes are automatically created when you:
101
+
102
+
- Run `bin/setup` for local development setup
103
+
- Run tests in CI/CD (GitHub Actions automatically creates indexes before running tests)
104
+
105
+
The application uses idempotent index creation (using `CREATE INDEX IF NOT EXISTS`), so it's safe to run the setup multiple times.
106
+
107
+
### Required Indexes
108
+
109
+
The application requires the following indexes on the `travel-sample` bucket:
110
+
111
+
1. **`idx_type`** - General index on the `type` field for all document queries
112
+
2. **`idx_type_country`** - Index for airline queries filtered by country (`Airline.list_by_country_or_all`)
113
+
3. **`idx_type_destinationairport`** - Index for route queries by destination airport (`Airline.to_airport`)
114
+
4. **`idx_type_sourceairport_stops`** - Index for route queries by source airport and stops (`Route.direct_connections`)
115
+
5. **`idx_type_airlineid`** - Index for airline queries by airline ID (used in joins with routes)
116
+
117
+
### Manual Index Management
118
+
119
+
You can manually manage indexes using the following Rake tasks:
120
+
121
+
#### Create All Required Indexes
122
+
123
+
```sh
124
+
bundle exec rake couchbase:setup_indexes
125
+
```
126
+
127
+
This command creates all required indexes on the `travel-sample` bucket. It's idempotent and safe to run multiple times.
128
+
129
+
#### List All Indexes
130
+
131
+
```sh
132
+
bundle exec rake couchbase:list_indexes
133
+
```
134
+
135
+
This command lists all indexes currently present in the `travel-sample` bucket, including their state, type, and indexed fields.
136
+
137
+
#### Drop Application Indexes
138
+
139
+
```sh
140
+
bundle exec rake couchbase:drop_indexes
141
+
```
142
+
143
+
This command drops all application-managed indexes. It requires confirmation before executing. For automated scripts, you can force the operation:
cluster.query("SELECT raw META(air).id FROM (SELECT DISTINCT META(airline).id AS airlineId FROM `#{bucket.name}` AS route JOIN `#{bucket.name}` AS airline ON route.airlineid = META(airline).id WHERE route.destinationairport = #{quote(values[0])}) AS subquery JOIN `#{bucket.name}` AS air ON META(air).id = subquery.airlineId LIMIT #{values[1]} OFFSET #{values[2]}",options)
32
+
cluster.query("SELECT raw META(air).id FROM (SELECT DISTINCT META(airline).id AS airlineId FROM `#{bucket.name}` AS route JOIN `#{bucket.name}` AS airline ON route.airlineid = META(airline).id AND airline.type = 'airline' WHERE route.type = 'route' AND route.destinationairport = #{quote(values[0])} ORDER BY META(airline).id) AS subquery JOIN `#{bucket.name}` AS air ON META(air).id = subquery.airlineId AND air.type = 'airline' LIMIT #{values[1]} OFFSET #{values[2]}",options)
0 commit comments