Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check CLI flag #232

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 2 additions & 56 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,59 +25,5 @@ on:
default: 'Manual trigger'

jobs:
Tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.8, 3.9]
requirements-level: [pypi]
db-service: [postgresql13]
search-service: [elasticsearch7,opensearch2]
include:
- db-service: postgresql13
DB_EXTRAS: "postgresql"

- search-service: elasticsearch7
SEARCH_EXTRAS: "elasticsearch7"

- search-service: opensearch2
SEARCH_EXTRAS: "opensearch2"

env:
DB: ${{ matrix.db-service }}
SEARCH: ${{ matrix.search-service }}
EXTRAS: tests,${{ matrix.SEARCH_EXTRAS }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Generate dependencies
run: |
pip install wheel requirements-builder
requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('.${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt') }}

- name: Install dependencies
run: |
pip install -r .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt
pip install ".[$EXTRAS]"
pip freeze
docker --version
docker-compose --version

- name: Run tests
run: |
./run-tests.sh
Python:
uses: inveniosoftware/workflows/.github/workflows/tests-python.yml@master
5 changes: 3 additions & 2 deletions invenio_search/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ def create(index_name, body, force, verbose):

@index.command()
@click.argument("index_name")
@click.option("--check/--no-check", is_flag=True, default=True)
@with_appcontext
@search_version_check
def update(index_name):
def update(index_name, check=True):
"""Update mappings of existing index."""
current_search.update_mapping(index_name)
current_search.update_mapping(index_name, check=check)
click.secho(f"Mapping of index {index_name} updated successfully.", fg="green")


Expand Down
7 changes: 3 additions & 4 deletions invenio_search/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def _build(tree_or_filename, alias=None):
),
)

def update_mapping(self, index):
def update_mapping(self, index, check=True):
"""Update mapping of the existing index."""
mapping_path = self.mappings[index]
index_alias_name = build_alias_name(index)
Expand All @@ -441,11 +441,10 @@ def update_mapping(self, index):

with open(mapping_path, "r") as body:
mapping = json.load(body)["mappings"]
changes = dictdiffer.diff(old_mapping, mapping)
list_of_changes = list(changes)
changes = list(dictdiffer.diff(old_mapping, mapping))

# allow only additions to mappings (backwards compatibility is kept)
if all([change[0] == "add" for change in list_of_changes]):
if not check or all([change[0] == "add" for change in changes]):
# raises 400 if the mapping cannot be updated
# (f.e. type changes or index needs to be closed)
index_.put_mapping(using=self.client, body=mapping)
Expand Down