-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
158 lines (136 loc) · 4.13 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -*- coding: utf-8 -*-
# python imports
# flask imports
from flask.ext.script import Manager, prompt_bool
# project imports
from application.extensions import db, redis, es
manager = Manager(usage="Perform database operations")
@manager.command
def drop():
"""Drops database tables"""
if prompt_bool("Are you sure you want to lose all your data"):
db.drop_all()
redis.flushdb()
@manager.command
def create():
"""Creates database tables from sqlalchemy models"""
db.create_all()
@manager.command
def recreate():
"""
Recreates database tables (same as issuing 'drop' and then 'create')
"""
drop()
create()
@manager.command
def update():
es.indices.delete(index='example', ignore=[400, 404])
body = {
"settings": {
"index": {"max_result_window": 500000},
"analysis": {
"char_filter": {
"zero_width_spaces": {
"type": "mapping",
"mappings": ["\\u200C=> "]
}
},
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 2,
"max_gram": 50,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"]
},
"persian_stop": {
"type": "stop",
"stopwords": "_persian_"
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"arabic_normalization",
"persian_normalization",
"persian_stop",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"arabic_normalization",
"persian_normalization",
"persian_stop"
]
}
}
}
},
"mappings": {
"player": {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"id": {
"type": "integer",
"index": "no",
"include_in_all": False
},
"name_fa": {
"type": "string",
"index": "not_analyzed"
},
"name_en": {
"type": "string",
"index": "not_analyzed"
},
"post": {
"type": "string",
"index": "not_analyzed"
},
"price": {
"type": "double",
"include_in_all": False
},
"team": {
"type": "string",
"index": "not_analyzed",
}
}
}
}
}
es.indices.create(index='example', body=body)
@manager.command
def fake():
"""
Generate fake data for database
"""
pass
@manager.command
def developer():
"""
Generate fake user for development use
"""
pass
@manager.command
def populate():
pass
@manager.command
def test():
"""Use it for test purpose"""
pass