this repo has no description
1from .utils import extract_and_save_source
2
3MIGRATIONS = []
4
5
6def migration(fn):
7 MIGRATIONS.append(fn)
8 return fn
9
10
11@migration
12def convert_source_column(db):
13 tables = set(db.table_names())
14 if "tweets" not in tables:
15 return
16 # Now we extract any '<a href=...' records from the source
17 for id, source in db.conn.execute(
18 "select id, source from tweets where source like '<%'"
19 ).fetchall():
20 db["tweets"].update(id, {"source": extract_and_save_source(db, source)})
21 try:
22 db["tweets"].create_index(["source"])
23 except Exception:
24 pass
25 try:
26 db["tweets"].add_foreign_key("source")
27 except Exception:
28 pass