Skip to content

Commit 030bd7a

Browse files
committed
Merged fixes for ASKBOT#845 and ASKBOT#846
2 parents 7a3b351 + 8c3739e commit 030bd7a

20 files changed

+26
-94
lines changed

askbot/doc/source/mysql-to-postgres.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ Test this by running a search query on the askbot site.
8282

8383
..
8484
If you have an issue with the above command, it is possible to run the search setup sql script manually:
85-
1. Download `thread_and_post_models_10032013.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/thread_and_post_models_10032013.plsql>`_
86-
2. Download `user_profile_search_08312012.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/user_profile_search_08312012.plsql>`_
85+
1. Download `thread_and_post_models_03012016.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/thread_and_post_models_03012016.plsql>`_
86+
2. Download `user_profile_search_12202015.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/user_profile_search_12202015.plsql>`_
8787
3. Apply the scripts to your postgres database::
8888
psql your_database < thread_and_post_models_10032013.plsql
89-
psql your_database < user_profile_search_08312012.plsql
89+
psql your_database < user_profile_search_12202015.plsql
9090
9191

9292
Fixing data types

askbot/migrations/0004_auto_20151219_0751.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ def init_postgresql_fts(apps, schema_editor):
1313
askbot.get_install_directory(),
1414
'search',
1515
'postgresql',
16-
'thread_and_post_models_10032013.plsql'
16+
'thread_and_post_models_03012016.plsql'
1717
)
1818
setup_full_text_search(script_path)
1919

2020
script_path = os.path.join(
2121
askbot.get_install_directory(),
2222
'search',
2323
'postgresql',
24-
'user_profile_search_12192015.plsql'
24+
'user_profile_search_12202015.plsql'
2525
)
2626
setup_full_text_search(script_path)
2727

askbot/migrations/0007_auto_20151220_0653.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

askbot/migrations/0008_auto_20160101_0951.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
class Migration(migrations.Migration):
99

1010
dependencies = [
11-
('askbot', '0007_auto_20151220_0653'),
11+
('askbot', '0006_auto_20151220_0459'),
12+
1213
]
1314

1415
operations = [

askbot/migrations/0009_auto_20160103_1150.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

askbot/migrations/0010_populate_language_code_for_reps_20160108_1052.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def calculate_localized_reps(apps, schema_editor):
7676
class Migration(migrations.Migration):
7777

7878
dependencies = [
79-
('askbot', '0009_auto_20160103_1150'),
79+
('askbot', '0008_auto_20160101_0951'),
8080
]
8181

8282
operations = [

askbot/search/postgresql/thread_and_post_models_03012016.plsql

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* function testing for existence of a column in a table
22
if table does not exists, function will return "false" */
33
CREATE OR REPLACE FUNCTION column_exists(colname text, tablename text)
4-
RETURNS boolean AS
4+
RETURNS boolean AS
55
$$
66
DECLARE
77
q text;
88
onerow record;
99
BEGIN
1010

11-
q = 'SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT oid FROM pg_class WHERE relname = '''||tablename||''') AND attname = '''||colname||'''';
11+
q = 'SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT oid FROM pg_class WHERE relname = '''||tablename||''') AND attname = '''||colname||'''';
1212

1313
FOR onerow IN EXECUTE q LOOP
1414
RETURN true;
@@ -48,12 +48,8 @@ $$ LANGUAGE plpgsql;
4848

4949
CREATE OR REPLACE FUNCTION setup_aggregates() RETURNS boolean AS
5050
$$
51-
DECLARE
52-
onerow record;
5351
BEGIN
54-
FOR onerow IN SELECT * FROM pg_proc WHERE proname = 'concat_tsvectors' AND proisagg LOOP
55-
DROP AGGREGATE concat_tsvectors(tsvector);
56-
END LOOP;
52+
DROP AGGREGATE IF EXISTS concat_tsvectors(tsvector);
5753
CREATE AGGREGATE concat_tsvectors (
5854
BASETYPE = tsvector,
5955
SFUNC = tsv_add,
@@ -181,7 +177,7 @@ DECLARE
181177
onerow record;
182178
BEGIN
183179
query = 'SELECT concat_tsvectors(text_search_vector), count(*) FROM askbot_post' ||
184-
' WHERE parent_id=' || parent_id ||
180+
' WHERE parent_id=' || parent_id ||
185181
' AND post_type=''comment'' AND deleted=false';
186182
FOR onerow IN EXECUTE query LOOP
187183
IF onerow.count = 0 THEN
@@ -259,7 +255,7 @@ BEGIN
259255
RETURN new;
260256
END;
261257
$$ LANGUAGE plpgsql;
262-
CREATE TRIGGER thread_search_vector_update_trigger
258+
CREATE TRIGGER thread_search_vector_update_trigger
263259
BEFORE UPDATE ON askbot_thread FOR EACH ROW EXECUTE PROCEDURE thread_update_trigger();
264260

265261
CREATE OR REPLACE FUNCTION thread_insert_trigger() RETURNS trigger AS
@@ -283,7 +279,7 @@ BEGIN
283279
new.post_type,
284280
new.language_code
285281
);
286-
UPDATE askbot_thread SET text_search_vector=text_search_vector ||
282+
UPDATE askbot_thread SET text_search_vector=text_search_vector ||
287283
new.text_search_vector WHERE id=new.thread_id;
288284
ELSIF new.post_type = 'comment' THEN
289285
new.text_search_vector = get_post_tsv(
@@ -297,14 +293,14 @@ BEGIN
297293
return new;
298294
END;
299295
$$ LANGUAGE plpgsql;
300-
CREATE TRIGGER post_search_vector_insert_trigger
301-
BEFORE INSERT ON askbot_post
302-
FOR EACH ROW
296+
CREATE TRIGGER post_search_vector_insert_trigger
297+
BEFORE INSERT ON askbot_post
298+
FOR EACH ROW
303299
EXECUTE PROCEDURE post_trigger();
304300

305-
CREATE TRIGGER post_search_vector_update_trigger
306-
BEFORE UPDATE ON askbot_post
307-
FOR EACH ROW
301+
CREATE TRIGGER post_search_vector_update_trigger
302+
BEFORE UPDATE ON askbot_post
303+
FOR EACH ROW
308304
WHEN (
309305
(old.text IS DISTINCT FROM new.text)
310306
OR (old.text_search_vector IS DISTINCT FROM new.text_search_vector)

askbot/search/postgresql/user_profile_search_12202015.plsql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/*
22
Script depends on functions defined for general askbot full text search.
33
to_tsvector(), add_tsvector_column()
44

55
calculates text search vector for the user profile
6-
the searched fields are:
6+
the searched fields are:
77
1) user name
88
2) user profile
99
3) group names - for groups to which user belongs
@@ -40,8 +40,8 @@ BEGIN
4040
'INNER JOIN askbot_userprofile AS p ON id=p.auth_user_ptr_id ' ||
4141
'WHERE id=' || user_id;
4242
FOR onerow in EXECUTE user_query LOOP
43-
tsv = tsv ||
44-
to_tsvector(onerow.username) ||
43+
tsv = tsv ||
44+
to_tsvector(onerow.username) ||
4545
to_tsvector(onerow.real_name) ||
4646
to_tsvector(onerow.email);
4747
END LOOP;
@@ -69,7 +69,7 @@ $$ LANGUAGE plpgsql;
6969
DROP TRIGGER IF EXISTS auth_user_tsv_update_trigger ON auth_user;
7070

7171
CREATE TRIGGER auth_user_tsv_update_trigger
72-
BEFORE INSERT OR UPDATE ON auth_user
72+
BEFORE INSERT OR UPDATE ON auth_user
7373
FOR EACH ROW EXECUTE PROCEDURE auth_user_tsv_update_handler();
7474

7575
/* localized user profile trigger */
@@ -132,7 +132,7 @@ AFTER INSERT OR DELETE
132132
ON auth_user_groups
133133
FOR EACH ROW EXECUTE PROCEDURE group_membership_tsv_update_handler();
134134

135-
/* todo: whenever group name changes - also
135+
/* todo: whenever group name changes - also
136136
* reindex users belonging to the group */
137137

138138
DROP INDEX IF EXISTS auth_user_search_idx;

0 commit comments

Comments
 (0)