start using alembic
This commit is contained in:
parent
b57e0cca26
commit
ffb2e1d033
9 changed files with 162 additions and 5 deletions
27
scripts/20150318-clean-content.py
Normal file
27
scripts/20150318-clean-content.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from config import Config
|
||||
import sqlalchemy
|
||||
import sqlalchemy.orm
|
||||
from woodwind.models import Entry
|
||||
from woodwind import util
|
||||
|
||||
engine = sqlalchemy.create_engine(Config.SQLALCHEMY_DATABASE_URI)
|
||||
Session = sqlalchemy.orm.sessionmaker(bind=engine)
|
||||
|
||||
try:
|
||||
engine.execute('alter table entry add column content_cleaned text')
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
session = Session()
|
||||
|
||||
for entry in session.query(Entry).all():
|
||||
print('processing', entry.id)
|
||||
entry.content_cleaned = util.clean(entry.content)
|
||||
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
finally:
|
||||
session.close()
|
Loading…
Add table
Add a link
Reference in a new issue