yusufgundogdu commited on
Commit
83877fd
·
verified ·
1 Parent(s): 202d214

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +4 -7
database.py CHANGED
@@ -3,15 +3,15 @@ import os
3
  from flask import g
4
 
5
  def get_db_path():
6
- # Docker'da /data dizinine yazma garantisi veriyoruz
7
- if os.environ.get('DOCKER_ENV') == 'true':
8
  return '/data/database.db'
9
- return 'database.db' # Local için proje dizini
10
 
11
  def get_db():
12
  if 'db' not in g:
13
  db_path = get_db_path()
14
- # Dizin yoksa oluştur
15
  os.makedirs(os.path.dirname(db_path), exist_ok=True)
16
  g.db = sqlite3.connect(db_path)
17
  g.db.row_factory = sqlite3.Row
@@ -26,7 +26,6 @@ def init_db(app):
26
  with app.app_context():
27
  db = get_db()
28
  cursor = db.cursor()
29
-
30
  cursor.execute('''
31
  CREATE TABLE IF NOT EXISTS users (
32
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -34,10 +33,8 @@ def init_db(app):
34
  score INTEGER DEFAULT 0
35
  )
36
  ''')
37
-
38
  cursor.execute('SELECT COUNT(*) FROM users')
39
  if cursor.fetchone()[0] == 0:
40
  cursor.executemany('INSERT INTO users (name, score) VALUES (?, ?)',
41
  [('Ahmet', 85), ('Mehmet', 92)])
42
-
43
  db.commit()
 
3
  from flask import g
4
 
5
  def get_db_path():
6
+ # Hugging Face Spaces için özel yol
7
+ if os.path.exists('/data'):
8
  return '/data/database.db'
9
+ return 'database.db' # Local testler için
10
 
11
  def get_db():
12
  if 'db' not in g:
13
  db_path = get_db_path()
14
+ # Dizin yoksa oluştur (Hugging Face için gerekli değil ama local için)
15
  os.makedirs(os.path.dirname(db_path), exist_ok=True)
16
  g.db = sqlite3.connect(db_path)
17
  g.db.row_factory = sqlite3.Row
 
26
  with app.app_context():
27
  db = get_db()
28
  cursor = db.cursor()
 
29
  cursor.execute('''
30
  CREATE TABLE IF NOT EXISTS users (
31
  id INTEGER PRIMARY KEY AUTOINCREMENT,
 
33
  score INTEGER DEFAULT 0
34
  )
35
  ''')
 
36
  cursor.execute('SELECT COUNT(*) FROM users')
37
  if cursor.fetchone()[0] == 0:
38
  cursor.executemany('INSERT INTO users (name, score) VALUES (?, ?)',
39
  [('Ahmet', 85), ('Mehmet', 92)])
 
40
  db.commit()