Skip to content

Commit e8e084e

Browse files
authored
Add namespace separator for Elasticsearch namespaces (#364)
* Allow custom separator in Elasticsearch namespaces * Bump version: 0.8.0 → 0.8.1
1 parent 390b9e1 commit e8e084e

File tree

10 files changed

+40
-10
lines changed

10 files changed

+40
-10
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.8.0
2+
current_version = 0.8.1
33
commit = True
44
tag = True
55

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: stable
3+
rev: 21.12b0
44
hooks:
55
- id: black
66
language_version: python3.8

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Release History
22
===============
33

4+
0.8.1
5+
-----
6+
7+
* Allow custom separator in Elasticsearch namespaces
8+
49
0.8.0
510
-----
611

docs/adapters/database.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ Additional options are available for finer control:
2525
Index names in Elasticsearch instance are prefixed with the specified string. For example, if the namespace
2626
prefix is "prod", the index of an aggregate `Person` will be `prod-person`.
2727

28+
.. py:data:: NAMESPACE_SEPARATOR
29+
30+
Custom character to join NAMESPACE_PREFIX and index name. Default is hyphen (`-`). For example, with
31+
`NAMESPACE_SEPARATOR` as `_`, the index of aggregate `Person` will be `prod_person`.
32+
2833
.. py:data:: SETTINGS
2934
3035
Index settings passed on to Elasticsearch instance.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
year = "2021"
2929
author = "Subhash Bhushan C"
3030
copyright = "{0}, {1}".format(year, author)
31-
version = release = "0.8.0"
31+
version = release = "0.8.1"
3232

3333
pygments_style = "autumn"
3434
templates_path = ["."]

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
def read(*names, **kwargs):
1818
"""Helper method to read files"""
1919
return io.open(
20-
join(dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8"),
20+
join(dirname(__file__), *names),
21+
encoding=kwargs.get("encoding", "utf8"),
2122
).read()
2223

2324

@@ -88,7 +89,7 @@ def read(*names, **kwargs):
8889

8990
setup(
9091
name="protean",
91-
version="0.8.0",
92+
version="0.8.1",
9293
license="BSD 3-Clause License",
9394
description="Protean Application Framework",
9495
long_description="%s\n%s"

src/protean/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.8.0"
1+
__version__ = "0.8.1"
22

33
from .core.aggregate import BaseAggregate
44
from .core.application_service import BaseApplicationService

src/protean/adapters/repository/elasticsearch.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,15 @@ def derive_schema_name(self, entity_cls):
305305

306306
# Prepend Namespace prefix if one has been provided
307307
if "NAMESPACE_PREFIX" in self.conn_info and self.conn_info["NAMESPACE_PREFIX"]:
308-
schema_name = (
309-
f"{self.conn_info['NAMESPACE_PREFIX']}_{entity_cls.meta_.schema_name}"
310-
)
308+
# Use custom separator if provided
309+
separator = "_"
310+
if (
311+
"NAMESPACE_SEPARATOR" in self.conn_info
312+
and self.conn_info["NAMESPACE_SEPARATOR"]
313+
):
314+
separator = self.conn_info["NAMESPACE_SEPARATOR"]
315+
316+
schema_name = f"{self.conn_info['NAMESPACE_PREFIX']}{separator}{entity_cls.meta_.schema_name}"
311317

312318
return schema_name
313319

tests/adapters/model/elasticsearch_model/tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ class Person(BaseAggregate):
136136
assert model_cls.__name__ == "PersonModel"
137137
assert model_cls._index._name == "foo_person"
138138

139+
def test_generated_index_name_with_namespace_separator(self, test_domain):
140+
test_domain.config["DATABASES"]["default"]["NAMESPACE_SEPARATOR"] = "#"
141+
142+
class Person(BaseAggregate):
143+
name = String(max_length=50, required=True)
144+
about = Text()
145+
146+
test_domain.register(Person)
147+
model_cls = test_domain.get_model(Person)
148+
149+
assert model_cls.__name__ == "PersonModel"
150+
assert model_cls._index._name == "foo#person"
151+
139152
def test_explicit_index_name_with_namespace_prefix(self, test_domain):
140153
class Person(BaseAggregate):
141154
name = String(max_length=50, required=True)

tests/adapters/model/sqlalchemy_model/postgresql/test_lookups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def test_in_lookup(self, test_domain):
5151

5252
assert (
5353
str(expr.compile())
54-
== "public.generic_postgres.role IN ([POSTCOMPILE_role_1])"
54+
== "public.generic_postgres.role IN (__[POSTCOMPILE_role_1])"
5555
)
5656
assert expr.compile().params == {"role_1": ["foo", "bar", "baz"]}

0 commit comments

Comments
 (0)