comparison pylons_app/lib/db_manage.py @ 88:911dab498eb2

Updated db manage
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 19 Apr 2010 22:52:31 +0200
parents ffd9ff6e2f33
children c6526b7531e9
comparison
equal deleted inserted replaced
87:9f6300b96380 88:911dab498eb2
10 def get_sqlite_conn_cur(): 10 def get_sqlite_conn_cur():
11 conn = sqlite3.connect(os.path.join(ROOT, 'hg_app.db')) 11 conn = sqlite3.connect(os.path.join(ROOT, 'hg_app.db'))
12 cur = conn.cursor() 12 cur = conn.cursor()
13 return conn, cur 13 return conn, cur
14 14
15 def check_for_db(): 15 def check_for_db(override):
16 if os.path.isfile(os.path.join(ROOT, 'hg_app.db')): 16 if not override:
17 raise Exception('database already exists') 17 if os.path.isfile(os.path.join(ROOT, 'hg_app.db')):
18 raise Exception('database already exists')
18 19
19 def create_tables(): 20 def create_tables(override=False):
20 """ 21 """
21 Create a auth database 22 Create a auth database
22 """ 23 """
23 check_for_db() 24 check_for_db(override)
24 conn, cur = get_sqlite_conn_cur() 25 conn, cur = get_sqlite_conn_cur()
25 try: 26 try:
26 logging.info('creating table %s', 'users') 27 logging.info('creating table %s', 'users')
27 cur.execute("""DROP TABLE IF EXISTS users """) 28 cur.execute("""DROP TABLE IF EXISTS users """)
28 cur.execute("""CREATE TABLE users 29 cur.execute("""CREATE TABLE users
63 except: 64 except:
64 conn.rollback() 65 conn.rollback()
65 raise 66 raise
66 67
67 if __name__ == '__main__': 68 if __name__ == '__main__':
68 create_tables() 69 create_tables(True)
69 admin_prompt() 70 admin_prompt()
70 71
71 72