1
0
Fork 0
mirror of https://github.com/Findus23/cr-search.git synced 2024-09-19 15:23:44 +02:00
cr-search/createdb.py

27 lines
695 B
Python
Raw Normal View History

2020-03-08 18:48:14 +01:00
from sys import argv
2020-03-07 10:45:39 +01:00
2021-07-07 17:27:21 +02:00
from app import db
from models import Series, Phrase, Episode, Person, Line
2020-03-08 18:48:14 +01:00
def confirm(message: str) -> None:
if "y" not in input(message):
raise ValueError("abort")
if len(argv) < 2:
raise ValueError("select mode")
mode = argv[1]
if mode == "all":
confirm("Delete all Data? ")
2020-04-15 18:11:45 +02:00
db.drop_tables([Series, Episode, Person, Line, Phrase])
db.create_tables([Series, Episode, Person, Line, Phrase])
2020-03-08 18:48:14 +01:00
elif mode == "phrases":
confirm("Delete all Phrases? ")
db.drop_tables([Phrase])
db.create_tables([Phrase])
2020-03-08 19:49:06 +01:00
if mode in ["all", "phrases"]:
db.execute_sql("CREATE INDEX phrases_text_index ON phrase USING gin (text gin_trgm_ops)")