@@ -67,7 +67,7 @@ def init_new_db(self, config: Configuration, init_db: bool = True) -> None:
67
67
68
68
if init_db :
69
69
self .update_sql_functions (config )
70
- self ._setup_db_tables (config , 'word' )
70
+ self ._setup_db_tables (config )
71
71
self ._create_base_indices (config , 'word' )
72
72
73
73
@@ -128,6 +128,10 @@ def update_statistics(self, config: Configuration) -> None:
128
128
FROM word LEFT JOIN word_frequencies wf
129
129
ON word.word_id = wf.id""" )
130
130
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}}"' )
131
135
conn .commit ()
132
136
self ._create_base_indices (config , 'tmp_word' )
133
137
self ._create_lookup_indices (config , 'tmp_word' )
@@ -234,28 +238,29 @@ def _save_config(self) -> None:
234
238
self .loader .save_config_to_db (conn )
235
239
236
240
237
- def _setup_db_tables (self , config : Configuration , table_name : str ) -> None :
241
+ def _setup_db_tables (self , config : Configuration ) -> None :
238
242
""" Set up the word table and fill it with pre-computed word
239
243
frequencies.
240
244
"""
241
245
with connect (self .dsn ) as conn :
242
246
with conn .cursor () as cur :
243
- cur .drop_table (table_name )
247
+ cur .drop_table ('word' )
244
248
sqlp = SQLPreprocessor (conn , config )
245
249
sqlp .run_string (conn , """
246
- CREATE TABLE {{table_name}} (
250
+ CREATE TABLE word (
247
251
word_id INTEGER,
248
252
word_token text NOT NULL,
249
253
type text NOT NULL,
250
254
word text,
251
255
info jsonb
252
256
) {{db.tablespace.search_data}};
253
- GRANT SELECT ON {{table_name}} TO "{{config.DATABASE_WEBUSER}}";
257
+ GRANT SELECT ON word TO "{{config.DATABASE_WEBUSER}}";
254
258
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 ()
259
264
260
265
261
266
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:
276
281
""" ,
277
282
table_name = table_name , idx_name = name ,
278
283
column_type = ctype )
284
+ conn .commit ()
279
285
280
286
281
287
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
289
295
ON {{table_name}} USING BTREE (word_id) {{db.tablespace.search_index}}
290
296
""" ,
291
297
table_name = table_name )
298
+ conn .commit ()
292
299
293
300
294
301
def _move_temporary_word_table (self , old : str ) -> None :
0 commit comments