def create_tables(): with database.atomic(): database.create_tables(all_types, safe=True) for table in all_types: schemaVersion, created = Global.get_or_create(key='schemaVersion.' + table.__name__) schemaVersion.int_value = table.update_schema(not created, schemaVersion.int_value) schemaVersion.save()
def drop_all_tables(i_am_really_sure=False): ''' Call this if you need to nuke everything and restart. Only for development purposes, hopefully. ''' if not i_am_really_sure: raise "You are not really sure. Call with i_am_really_sure=True to proceed." with database.atomic(): for table in all_types: database.drop_table(table)
def atomic(): ''' To run a bunch of stuff within a transaction; e.g.: with model.atomic() as xact: foo bar baz if error: xact.rollback() ''' return database.atomic()