def create_tables(): if '--create' in sys.argv or '-c' in sys.argv: database.create_all() if '--insert' in sys.argv or '-i' in sys.argv: for query in insert_queries: database.session.execute(query) database.session.commit()
def create_tables(): # if the database file already exists, don't recreate it if not os.path.isfile('database.db'): database.create_all() # if the data of the first insert (of 'instert_queries' in database.py) doesn't exist in the table, the test data hasn't been inserted yet, so insert it from models.topic import TopicModel if not TopicModel.query.first( ): # prevent "UNIQUE constraint violation" of primary keys: this will only work as long as a topic is the first thing being inserted (you could fix this by checking every table is empty, but: a. unless you need something to be inserted before a topic there's no reason to rearrange it, and b. this is just test data so this won't be used in release) test.insert_test_data() database.session.commit()
def create_tables(): database.create_all()
def create_all_tables_before_requests(): db.create_all()