schema-tools 1.0.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/LICENSE +201 -0
- data/README.md +305 -0
- data/bin/integrate +136 -0
- data/bin/setup +23 -0
- data/lib/schema_tools/api_aware_mappings_diff.rb +79 -0
- data/lib/schema_tools/catchup.rb +23 -0
- data/lib/schema_tools/client.rb +472 -0
- data/lib/schema_tools/close.rb +28 -0
- data/lib/schema_tools/config.rb +46 -0
- data/lib/schema_tools/delete.rb +28 -0
- data/lib/schema_tools/diff.rb +263 -0
- data/lib/schema_tools/download.rb +114 -0
- data/lib/schema_tools/json_diff.rb +234 -0
- data/lib/schema_tools/migrate/migrate.rb +90 -0
- data/lib/schema_tools/migrate/migrate_breaking_change.rb +373 -0
- data/lib/schema_tools/migrate/migrate_new.rb +33 -0
- data/lib/schema_tools/migrate/migrate_non_breaking_change.rb +74 -0
- data/lib/schema_tools/migrate/migrate_verify.rb +19 -0
- data/lib/schema_tools/migrate/migration_step.rb +36 -0
- data/lib/schema_tools/migrate/rollback.rb +211 -0
- data/lib/schema_tools/new_alias.rb +165 -0
- data/lib/schema_tools/painless_scripts_delete.rb +21 -0
- data/lib/schema_tools/painless_scripts_download.rb +26 -0
- data/lib/schema_tools/painless_scripts_upload.rb +31 -0
- data/lib/schema_tools/rake_tasks.rb +15 -0
- data/lib/schema_tools/schema_files.rb +53 -0
- data/lib/schema_tools/seed.rb +64 -0
- data/lib/schema_tools/settings_diff.rb +64 -0
- data/lib/schema_tools/settings_filter.rb +27 -0
- data/lib/seeder/seeder.rb +539 -0
- data/lib/tasks/schema.rake +150 -0
- data/lib/tasks/test.rake +8 -0
- metadata +190 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 034254ea56083f762e58093b03fdbeee3d6248a6d184edf90513413cf84760c6
|
4
|
+
data.tar.gz: cf3f652eaac0f2e21bac059b1d09c344c5855d79e6f35ff1a956aa7d145fd250
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fccad10cbe67bceaffcd61fb72548e3bdafce37ebf7b3c5882e8120663d6fd359dc1c3236d2e237abc1831375d05c1762a4b08c398723c65c9b58a844c8a4cff
|
7
|
+
data.tar.gz: a340ea851b79c07f6976b4d4fbd7bb5a7bd41d39b6f0adf2a66bd7398b83fdd74d3d1c65adb7360eff3517278050885650c947998a0494981a6120b1b8229751
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,305 @@
|
|
1
|
+
# Schema Tools for OpenSearch and Elasticsearch
|
2
|
+
|
3
|
+
## Features
|
4
|
+
- Specify index settings and mappings in simple `.json` files.
|
5
|
+
- Migrate and reindex to a new index with zero downtime using aliases.
|
6
|
+
- Download schemas from existing aliases or indices.
|
7
|
+
- Create new aliases with sample schemas.
|
8
|
+
- Manage painless scripts independently from schema migrations.
|
9
|
+
|
10
|
+
## Quick start
|
11
|
+
|
12
|
+
Install this Ruby gem.
|
13
|
+
|
14
|
+
```sh
|
15
|
+
gem install schema-tools
|
16
|
+
```
|
17
|
+
|
18
|
+
### Configuration
|
19
|
+
|
20
|
+
Set the connection URL for your OpenSearch or Elasticsearch instance:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
export OPENSEARCH_URL=http://localhost:9200
|
24
|
+
# or
|
25
|
+
export ELASTICSEARCH_URL=https://your-cluster.com
|
26
|
+
```
|
27
|
+
|
28
|
+
For authenticated instances, optionally set username and password:
|
29
|
+
|
30
|
+
```sh
|
31
|
+
export ELASTICSEARCH_USERNAME=your_username
|
32
|
+
export ELASTICSEARCH_PASSWORD=your_password
|
33
|
+
# or
|
34
|
+
export OPENSEARCH_USERNAME=your_username
|
35
|
+
export OPENSEARCH_PASSWORD=your_password
|
36
|
+
```
|
37
|
+
|
38
|
+
### Download an existing schema
|
39
|
+
|
40
|
+
Run `rake schema:download` to download a schema from an existing alias or index:
|
41
|
+
|
42
|
+
```sh
|
43
|
+
$ rake schema:download
|
44
|
+
|
45
|
+
# Aliases pointing to 1 index:
|
46
|
+
# 1. products -> products-20241201120000
|
47
|
+
# 2. users -> users-20241201120000
|
48
|
+
|
49
|
+
# Indexes not part of any aliases:
|
50
|
+
# 1. old-index
|
51
|
+
# 2. temp-index
|
52
|
+
|
53
|
+
# Please choose an alias or index to download:
|
54
|
+
# Enter 'alias:<name>' for an alias or 'index:<name>' for an index:
|
55
|
+
```
|
56
|
+
|
57
|
+
The task will generate schema definition files in a folder layout like this:
|
58
|
+
|
59
|
+
```
|
60
|
+
schemas/products # Folder name matches the alias name
|
61
|
+
settings.json # OpenSearch/Elasticsearch index settings
|
62
|
+
mappings.json # OpenSearch/Elasticsearch index mappings
|
63
|
+
reindex.painless # Optional reindexing data transformation logic
|
64
|
+
```
|
65
|
+
|
66
|
+
### Migrate schemas
|
67
|
+
|
68
|
+
To migrate your OpenSearch/Elasticsearch indexes to the latest versions defined in the `schemas/` folder:
|
69
|
+
|
70
|
+
```sh
|
71
|
+
rake schema:migrate
|
72
|
+
```
|
73
|
+
|
74
|
+
To migrate a specific alias:
|
75
|
+
|
76
|
+
```sh
|
77
|
+
rake 'schema:migrate[products]'
|
78
|
+
```
|
79
|
+
|
80
|
+
### Create a new alias
|
81
|
+
|
82
|
+
Run `rake schema:new` to create a new alias with an index and a sample schema:
|
83
|
+
|
84
|
+
```sh
|
85
|
+
$ rake schema:new
|
86
|
+
|
87
|
+
# Enter a new alias name:
|
88
|
+
# products
|
89
|
+
# ✓ Created index 'products-20241201120000' with alias 'products'
|
90
|
+
# ✓ Sample schema created at schemas/products
|
91
|
+
# - settings.json
|
92
|
+
# - mappings.json
|
93
|
+
```
|
94
|
+
|
95
|
+
## Directory structure reference
|
96
|
+
|
97
|
+
Example directory structure with multiple aliases:
|
98
|
+
|
99
|
+
```
|
100
|
+
schemas/products
|
101
|
+
settings.json
|
102
|
+
mappings.json
|
103
|
+
reindex.painless # Optional reindexing data transformation logic
|
104
|
+
schemas/users
|
105
|
+
settings.json
|
106
|
+
mappings.json
|
107
|
+
```
|
108
|
+
|
109
|
+
Each schema folder name matches the name of an alias.
|
110
|
+
|
111
|
+
## Other settings and tasks
|
112
|
+
|
113
|
+
Use `rake schema:seed` to seed an index with sample documents that conform to your schema.
|
114
|
+
|
115
|
+
Use `DRYRUN` to simulate but not apply any POST/PUT/DELETE operations to your index:
|
116
|
+
|
117
|
+
```
|
118
|
+
DRYRUN=true rake schema:migrate
|
119
|
+
```
|
120
|
+
|
121
|
+
Use `INTERACTIVE` to prompt to proceed before applying any POST/PUT/DELETE operations to your index:
|
122
|
+
|
123
|
+
```
|
124
|
+
INTERACTIVE=true rake schema:migrate
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
## How migrations work
|
129
|
+
|
130
|
+
When possible, `rake schema:migrate` will update settings and mappings in-place on an aliased index, without reindexing. Only breaking changes require a reindex.
|
131
|
+
|
132
|
+
Migrating breaking changes requires careful orchestration of reads and writes to ensure documents that are created/updated/deleted during the migration are not lost.
|
133
|
+
|
134
|
+
Use case:
|
135
|
+
- I have an alias `products` pointing at index `products-20250301000000`.
|
136
|
+
- I have heavy reads and writes with 100M+ documents in the index
|
137
|
+
- I want to reindex `products-20250301000000` into a new index and update the `products` alias to reference it, without losing any creates/updates/deletes during the process.
|
138
|
+
|
139
|
+
Rake `schema:migrate` solves this use case through the following procedure.
|
140
|
+
|
141
|
+
First, some terms:
|
142
|
+
- `alias_name`: Alias containing the index to migrate
|
143
|
+
- `products`
|
144
|
+
- `current_index`: First and only index in the alias
|
145
|
+
- `products-20250301000000`
|
146
|
+
- `new_index`: Final canonical index into which to migrate `current_index`
|
147
|
+
- `products-20250601000000`
|
148
|
+
- `catchup1_index`: Temp index to preserve writes during reindex
|
149
|
+
- `products-20250601000000-catchup-1`
|
150
|
+
- `catchup2_index`: Temp index to preserve writes while flushing `catchup1_index`
|
151
|
+
- `products-20250601000000-catchup-2`
|
152
|
+
- `log_index`: Index to log the migration state, not stored with `alias_name`
|
153
|
+
- `products-20250601000000-migration-log`
|
154
|
+
|
155
|
+
SETUP
|
156
|
+
|
157
|
+
Create `log_index` to log the migration state.
|
158
|
+
- The migration logs when it starts and completes a step along with a description.
|
159
|
+
|
160
|
+
STEP 1
|
161
|
+
|
162
|
+
Create `catchup1_index` using the new schema.
|
163
|
+
- This index will preserve writes during the reindex.
|
164
|
+
|
165
|
+
STEP 2
|
166
|
+
|
167
|
+
Configure `alias_name` to only write to `catchup1_index` and read from `current_index` and `catchup1_index`.
|
168
|
+
|
169
|
+
STEP 3
|
170
|
+
|
171
|
+
Create `new_index` using the new schema.
|
172
|
+
|
173
|
+
Reindex `current_index` into `new_index`.
|
174
|
+
|
175
|
+
```
|
176
|
+
POST _reindex
|
177
|
+
{
|
178
|
+
"source": { "index": "#{current_index}" },
|
179
|
+
"dest": { "index": "#{new_index}" },
|
180
|
+
"conflicts": "proceed",
|
181
|
+
"refresh": false
|
182
|
+
}
|
183
|
+
```
|
184
|
+
|
185
|
+
STEP 4
|
186
|
+
|
187
|
+
Create `catchup2_index` using the new schema.
|
188
|
+
- This index ensures a place for ongoing writes while flushing `catchup1_index`.
|
189
|
+
|
190
|
+
STEP 5
|
191
|
+
|
192
|
+
Configure `alias_name` to only write to `catchup2_index` and continue reading from `current_index` and `catchup1_index`.
|
193
|
+
|
194
|
+
STEP 6
|
195
|
+
|
196
|
+
Reindex `catchup1_index` into `new_index`.
|
197
|
+
- Merge the first catchup index into the new canonical index.
|
198
|
+
|
199
|
+
STEP 7
|
200
|
+
|
201
|
+
Configure `alias_name` so there are NO write indexes
|
202
|
+
- This guarantees that no writes can sneak into an obsolete catchup index during the second (quick) merge.
|
203
|
+
- Any write operations will fail during this time with: `"reason": "Alias [FOO] has more than one index associated with it [...], can't execute a single index op"`
|
204
|
+
- Clients must retry any failed writes.
|
205
|
+
|
206
|
+
STEP 8
|
207
|
+
|
208
|
+
Reindex `catchup2_index` into `new_index`
|
209
|
+
- Final sync to merge the second catchup index into the new canonical index.
|
210
|
+
|
211
|
+
STEP 9
|
212
|
+
|
213
|
+
Configure `alias_name` to write to and read from `new_index` only.
|
214
|
+
- Writes resume to the single new index. All data and deletes are consistent.
|
215
|
+
|
216
|
+
STEP 10
|
217
|
+
|
218
|
+
Close unused indexes to avoid accidental writes.
|
219
|
+
- Close `catchup1_index`
|
220
|
+
- Close `catchup2_index`
|
221
|
+
- Close `current_index`
|
222
|
+
Operation complete.
|
223
|
+
|
224
|
+
Users can safely delete closed indexes anytime after they are closed.
|
225
|
+
|
226
|
+
Caveats for clients that perform writes during the migration:
|
227
|
+
- Clients MUST retry failed creates/updates/deletes for up to a minute.
|
228
|
+
- Writes will be temporarily disabled for up to a few seconds during the procedure to ensure no data loss.
|
229
|
+
- Clients MUST use `delete_by_query` when deleting documents to ensure documents are deleted from all indexes in the alias during reindexing.
|
230
|
+
- If using `DELETE` to delete a single document from an alias, clients might delete from the wrong index and receive a successful response containing "result: not_found". The new index will _not_ reflect such a deletion.
|
231
|
+
- Clients MUST read and write to an alias, not directly to an index.
|
232
|
+
- To prevent downtime, the migration procedure only operates on aliased indexes.
|
233
|
+
- Run `rake schema:alias` to create a new alias pointed at an index.
|
234
|
+
- Client applications must read and write to alias_name instead of index_name.
|
235
|
+
|
236
|
+
### Diagnosing a failed or aborted migration
|
237
|
+
|
238
|
+
If a migration fails or aborts, check status logs in the index named `#{alias_name}-#{timestamp}-migration-log`
|
239
|
+
|
240
|
+
### Transform data during migration
|
241
|
+
|
242
|
+
Change the data when migrating to a new schema via the `reindex.painless` script. For example, when renaming a field, the `reindex.painless` script can specify how to modify data when migrating.
|
243
|
+
|
244
|
+
`reindex.painless` runs one time when reindexing into a new index.
|
245
|
+
|
246
|
+
### Manage painless scripts
|
247
|
+
|
248
|
+
- Download, edit, and upload centrally managed painless scripts.
|
249
|
+
- Version control painless scripts alongside code
|
250
|
+
- Manage scripts independently from schema migrations
|
251
|
+
- Easily sync scripts between different environments
|
252
|
+
- Track changes to scripts over time
|
253
|
+
|
254
|
+
#### Download painless scripts from cluster
|
255
|
+
|
256
|
+
To download all painless scripts from a cluster and store them in the `painless_scripts/` directory (configurable via `PAINLESS_SCRIPTS_PATH` environment variable):
|
257
|
+
|
258
|
+
```sh
|
259
|
+
rake painless_scripts:download
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Upload painless scripts to cluster
|
263
|
+
|
264
|
+
To upload all `*.painless` script files from the local `painless_scripts` directory into the cluster.
|
265
|
+
|
266
|
+
```sh
|
267
|
+
rake painless_scripts:upload
|
268
|
+
```
|
269
|
+
|
270
|
+
#### Delete a painless script from cluster
|
271
|
+
|
272
|
+
To delete a specific painless script from the cluster:
|
273
|
+
|
274
|
+
```sh
|
275
|
+
rake 'painless_scripts:delete[script_name]'
|
276
|
+
```
|
277
|
+
|
278
|
+
This will:
|
279
|
+
- Delete the specified script from the cluster
|
280
|
+
- Accept script names with or without the `.painless` extension
|
281
|
+
- Handle cases where the script doesn't exist gracefully
|
282
|
+
|
283
|
+
### Apply a schema change to Staging and Production
|
284
|
+
|
285
|
+
Run GitHub Actions for your branch to prepare a given environment. The actions use the `schema:migrate` task underneath.
|
286
|
+
|
287
|
+
GitHub Actions:
|
288
|
+
- OpenSearch Staging Migrate
|
289
|
+
- OpenSearch Production Migrate
|
290
|
+
|
291
|
+
### Delete an index
|
292
|
+
|
293
|
+
Run `rake 'schema:close[index_name]'` to close an index. This will prevent reads and writes to the index. Verify that the application can operate with the index in a closed state before deleting it.
|
294
|
+
|
295
|
+
Run `rake 'schema:delete[index_name]'` to hard-delete an index. For safety, this task only hard-deletes indexes that are closed.
|
296
|
+
|
297
|
+
Run `rake 'schema:close[alias_name]'` to close all indexes in an alias.
|
298
|
+
|
299
|
+
Run `rake 'schema:delete[alias_name]'` to delete an alias and leave its indexes untouched.
|
300
|
+
|
301
|
+
GitHub Actions:
|
302
|
+
- OpenSearch Staging Close Index
|
303
|
+
- OpenSearch Production Close Index
|
304
|
+
- OpenSearch Staging Delete Index
|
305
|
+
- OpenSearch Production Delete Index
|
data/bin/integrate
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
puts "🔧 Schema Tools Integration Helper"
|
6
|
+
puts "=================================="
|
7
|
+
puts ""
|
8
|
+
|
9
|
+
if ARGV.empty?
|
10
|
+
puts "Usage: ./bin/integrate <project_path> [options]"
|
11
|
+
puts ""
|
12
|
+
puts "Options:"
|
13
|
+
puts " --submodule Add as git submodule (recommended)"
|
14
|
+
puts " --copy Copy files into project"
|
15
|
+
puts " --gem Setup as gem dependency"
|
16
|
+
puts ""
|
17
|
+
puts "Examples:"
|
18
|
+
puts " ./bin/integrate ../myapp --submodule"
|
19
|
+
puts " ./bin/integrate ../myapp --copy"
|
20
|
+
puts " ./bin/integrate ../myapp --gem"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
project_path = ARGV[0]
|
25
|
+
option = ARGV[1] || '--submodule'
|
26
|
+
|
27
|
+
unless Dir.exist?(project_path)
|
28
|
+
puts "❌ Project path does not exist: #{project_path}"
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "📁 Project path: #{project_path}"
|
33
|
+
puts "⚙️ Integration method: #{option}"
|
34
|
+
puts ""
|
35
|
+
|
36
|
+
case option
|
37
|
+
when '--submodule'
|
38
|
+
puts "🔗 Setting up as git submodule..."
|
39
|
+
|
40
|
+
# Check if it's a git repository
|
41
|
+
unless Dir.exist?(File.join(project_path, '.git'))
|
42
|
+
puts "❌ Target project is not a git repository"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
# Add submodule
|
47
|
+
system("cd #{project_path} && git submodule add #{`git remote get-url origin`.strip} vendor/schema-tools")
|
48
|
+
system("cd #{project_path} && git submodule update --init --recursive")
|
49
|
+
|
50
|
+
# Create wrapper Rakefile
|
51
|
+
wrapper_rakefile = File.join(project_path, 'Rakefile')
|
52
|
+
if File.exist?(wrapper_rakefile)
|
53
|
+
puts "⚠️ Rakefile already exists. Creating schema-tools.rake instead."
|
54
|
+
wrapper_rakefile = File.join(project_path, 'lib', 'tasks', 'schema-tools.rake')
|
55
|
+
FileUtils.mkdir_p(File.dirname(wrapper_rakefile))
|
56
|
+
end
|
57
|
+
|
58
|
+
File.write(wrapper_rakefile, <<~RUBY)
|
59
|
+
# Schema Tools Integration
|
60
|
+
require_relative 'vendor/schema-tools/Rakefile'
|
61
|
+
|
62
|
+
# Your custom tasks here
|
63
|
+
namespace :myapp do
|
64
|
+
desc "Deploy with schema migration"
|
65
|
+
task :deploy, [:index_name] do |t, args|
|
66
|
+
puts "🚀 Deploying #{args[:index_name]}..."
|
67
|
+
Rake::Task['schema:migrate'].invoke(args[:index_name])
|
68
|
+
puts "✅ Deployment complete!"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
|
73
|
+
puts "✅ Submodule integration complete!"
|
74
|
+
puts "📝 Created: #{wrapper_rakefile}"
|
75
|
+
|
76
|
+
when '--copy'
|
77
|
+
puts "📋 Copying files to project..."
|
78
|
+
|
79
|
+
# Copy lib directory
|
80
|
+
target_lib = File.join(project_path, 'lib', 'schema_tools')
|
81
|
+
FileUtils.mkdir_p(target_lib)
|
82
|
+
FileUtils.cp_r('lib/schema_tools/.', target_lib)
|
83
|
+
|
84
|
+
# Copy tasks
|
85
|
+
target_tasks = File.join(project_path, 'lib', 'tasks')
|
86
|
+
FileUtils.mkdir_p(target_tasks)
|
87
|
+
FileUtils.cp('lib/tasks/opensearch.rake', target_tasks)
|
88
|
+
FileUtils.cp('lib/tasks/elasticsearch.rake', target_tasks)
|
89
|
+
|
90
|
+
puts "✅ Copy integration complete!"
|
91
|
+
puts "📁 Copied to: #{target_lib}"
|
92
|
+
|
93
|
+
when '--gem'
|
94
|
+
puts "💎 Setting up as gem dependency..."
|
95
|
+
|
96
|
+
gemfile_path = File.join(project_path, 'Gemfile')
|
97
|
+
unless File.exist?(gemfile_path)
|
98
|
+
puts "❌ Gemfile not found in project"
|
99
|
+
exit 1
|
100
|
+
end
|
101
|
+
|
102
|
+
# Add gem to Gemfile
|
103
|
+
gem_entry = "gem 'schema-tools', path: '#{File.expand_path('.')}'"
|
104
|
+
|
105
|
+
if File.read(gemfile_path).include?('schema-tools')
|
106
|
+
puts "⚠️ schema-tools already in Gemfile"
|
107
|
+
else
|
108
|
+
File.open(gemfile_path, 'a') do |f|
|
109
|
+
f.puts ""
|
110
|
+
f.puts "# Schema Tools"
|
111
|
+
f.puts gem_entry
|
112
|
+
end
|
113
|
+
puts "✅ Added to Gemfile: #{gem_entry}"
|
114
|
+
end
|
115
|
+
|
116
|
+
puts "📝 Run 'bundle install' in your project to install the gem"
|
117
|
+
|
118
|
+
else
|
119
|
+
puts "❌ Unknown option: #{option}"
|
120
|
+
exit 1
|
121
|
+
end
|
122
|
+
|
123
|
+
puts ""
|
124
|
+
puts "🎉 Integration complete!"
|
125
|
+
puts ""
|
126
|
+
puts "Next steps:"
|
127
|
+
puts "1. Set environment variables:"
|
128
|
+
puts " export OPENSEARCH_URL=https://your-cluster.com"
|
129
|
+
puts " export SCHEMAS_PATH=db/schemas"
|
130
|
+
puts ""
|
131
|
+
puts "2. Create your schemas in the schemas directory"
|
132
|
+
puts ""
|
133
|
+
puts "3. Run migrations:"
|
134
|
+
puts " rake 'schema:migrate[your-index]'"
|
135
|
+
puts ""
|
136
|
+
puts "📖 See INTEGRATION_GUIDE.md for more details"
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
puts "Setting up Schema Tools..."
|
6
|
+
|
7
|
+
FileUtils.mkdir_p('schemas')
|
8
|
+
FileUtils.mkdir_p('lib/tasks')
|
9
|
+
FileUtils.mkdir_p('test')
|
10
|
+
|
11
|
+
puts "Installing dependencies..."
|
12
|
+
system('bundle install')
|
13
|
+
|
14
|
+
puts "Setting up example schemas..."
|
15
|
+
system('cp -r examples/* schemas/') if Dir.exist?('examples')
|
16
|
+
|
17
|
+
puts "Setup complete!"
|
18
|
+
puts ""
|
19
|
+
puts "To get started:"
|
20
|
+
puts "1. Start OpenSearch: docker-compose up -d"
|
21
|
+
puts "2. Create your first schema in schemas/"
|
22
|
+
puts "3. Run: rake 'schema:migrate[your_index_name]'"
|
23
|
+
puts "4. Run tests: rake spec"
|