Skip to content

Commit 2833362

Browse files
authored
Merge pull request #3331 from lonvia/fix-word-table-rights
Properly grant rights to read-only user when switching out word table
2 parents 39039e2 + bc51378 commit 2833362

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

nominatim/tokenizer/icu_tokenizer.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def init_new_db(self, config: Configuration, init_db: bool = True) -> None:
6767

6868
if init_db:
6969
self.update_sql_functions(config)
70-
self._setup_db_tables(config, 'word')
70+
self._setup_db_tables(config)
7171
self._create_base_indices(config, 'word')
7272

7373

@@ -128,6 +128,10 @@ def update_statistics(self, config: Configuration) -> None:
128128
FROM word LEFT JOIN word_frequencies wf
129129
ON word.word_id = wf.id""")
130130
cur.drop_table('word_frequencies')
131+
132+
sqlp = SQLPreprocessor(conn, config)
133+
sqlp.run_string(conn,
134+
'GRANT SELECT ON tmp_word TO "{{config.DATABASE_WEBUSER}}"')
131135
conn.commit()
132136
self._create_base_indices(config, 'tmp_word')
133137
self._create_lookup_indices(config, 'tmp_word')
@@ -234,28 +238,29 @@ def _save_config(self) -> None:
234238
self.loader.save_config_to_db(conn)
235239

236240

237-
def _setup_db_tables(self, config: Configuration, table_name: str) -> None:
241+
def _setup_db_tables(self, config: Configuration) -> None:
238242
""" Set up the word table and fill it with pre-computed word
239243
frequencies.
240244
"""
241245
with connect(self.dsn) as conn:
242246
with conn.cursor() as cur:
243-
cur.drop_table(table_name)
247+
cur.drop_table('word')
244248
sqlp = SQLPreprocessor(conn, config)
245249
sqlp.run_string(conn, """
246-
CREATE TABLE {{table_name}} (
250+
CREATE TABLE word (
247251
word_id INTEGER,
248252
word_token text NOT NULL,
249253
type text NOT NULL,
250254
word text,
251255
info jsonb
252256
) {{db.tablespace.search_data}};
253-
GRANT SELECT ON {{table_name}} TO "{{config.DATABASE_WEBUSER}}";
257+
GRANT SELECT ON word TO "{{config.DATABASE_WEBUSER}}";
254258
255-
DROP SEQUENCE IF EXISTS seq_{{table_name}};
256-
CREATE SEQUENCE seq_{{table_name}} start 1;
257-
GRANT SELECT ON seq_{{table_name}} to "{{config.DATABASE_WEBUSER}}";
258-
""", table_name=table_name)
259+
DROP SEQUENCE IF EXISTS seq_word;
260+
CREATE SEQUENCE seq_word start 1;
261+
GRANT SELECT ON seq_word to "{{config.DATABASE_WEBUSER}}";
262+
""")
263+
conn.commit()
259264

260265

261266
def _create_base_indices(self, config: Configuration, table_name: str) -> None:
@@ -276,6 +281,7 @@ def _create_base_indices(self, config: Configuration, table_name: str) -> None:
276281
""",
277282
table_name=table_name, idx_name=name,
278283
column_type=ctype)
284+
conn.commit()
279285

280286

281287
def _create_lookup_indices(self, config: Configuration, table_name: str) -> None:
@@ -289,6 +295,7 @@ def _create_lookup_indices(self, config: Configuration, table_name: str) -> None
289295
ON {{table_name}} USING BTREE (word_id) {{db.tablespace.search_index}}
290296
""",
291297
table_name=table_name)
298+
conn.commit()
292299

293300

294301
def _move_temporary_word_table(self, old: str) -> None:

0 commit comments

Comments
 (0)