yusufgundogdu commited on
Commit
3bff85a
·
verified ·
1 Parent(s): f949032

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +0 -95
database.py CHANGED
@@ -25,101 +25,6 @@ def close_db(e=None):
25
  if db is not None:
26
  db.close()
27
 
28
- def init_db(app):
29
- """Veritabanı tablolarını oluşturur ve örnek verileri ekler"""
30
- with app.app_context():
31
- db = get_db()
32
- cursor = db.cursor()
33
-
34
- # Kullanıcılar tablosu
35
- cursor.execute('''
36
- CREATE TABLE IF NOT EXISTS users (
37
- id INTEGER PRIMARY KEY AUTOINCREMENT,
38
- udid TEXT NOT NULL UNIQUE,
39
- platform TEXT NOT NULL CHECK (platform IN ('AND', 'IOS')),
40
- premium_account BOOLEAN DEFAULT FALSE,
41
- usage_limit INTEGER DEFAULT 10,
42
- invoice TEXT DEFAULT '',
43
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
44
- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
45
- )
46
- ''')
47
-
48
- # Generate list tablosu
49
- cursor.execute('''
50
- CREATE TABLE IF NOT EXISTS generate_list (
51
- id INTEGER PRIMARY KEY AUTOINCREMENT,
52
- title TEXT NOT NULL,
53
- image_url TEXT NOT NULL,
54
- contour INTEGER NOT NULL,
55
- item_order INTEGER NOT NULL DEFAULT 0
56
- )
57
- ''')
58
-
59
- # Örnek kullanıcı verileri
60
- cursor.execute('SELECT COUNT(*) FROM users')
61
- if cursor.fetchone()[0] == 0:
62
- cursor.executemany('''
63
- INSERT INTO users (udid, platform, premium_account, usage_limit, invoice)
64
- VALUES (?, ?, ?, ?, ?)
65
- ''', [
66
- ('test_udid_1', 'AND', True, 4, 'test_invoice_1'),
67
- ('test_udid_2', 'IOS', False, 4, 'test_invoice_2')
68
- ])
69
-
70
- # Örnek model verileri
71
- cursor.execute('SELECT COUNT(*) FROM generate_list')
72
- if cursor.fetchone()[0] == 0:
73
- default_models = [
74
- ("REALISTIC", "https://huggingface.co/spaces/anime-backend/stablediffusionapi/blob/main/assets/images/0.jpg", 0, 0),
75
- ("DRAWING", "https://huggingface.co/spaces/anime-backend/stablediffusionapi/blob/main/assets/images/1.jpg", 10, 1),
76
- ("TOY FIGURE", "https://huggingface.co/spaces/anime-backend/stablediffusionapi/blob/main/assets/images/2.jpg", 10, 2),
77
- ("3D", "https://huggingface.co/spaces/anime-backend/stablediffusionapi/blob/main/assets/images/3.jpg", 40, 3),
78
- ("ANIMATION", "https://huggingface.co/spaces/anime-backend/stablediffusionapi/blob/main/assets/images/4.jpg", 50, 4)
79
- ]
80
- cursor.executemany('''
81
- INSERT INTO generate_list (title, image_url, contour, item_order)
82
- VALUES (?, ?, ?, ?)
83
- ''', default_models)
84
-
85
- db.commit()
86
-
87
- def get_generate_list(db):
88
- """Generate listesindeki tüm öğeleri sıralı şekilde getirir"""
89
- cursor = db.cursor()
90
- cursor.execute('''
91
- SELECT id, title, image_url, contour, item_order
92
- FROM generate_list
93
- ORDER BY item_order ASC
94
- ''')
95
- return cursor.fetchall()
96
-
97
- def add_to_generate_list(db, title, image_url, contour, order=None):
98
- """Generate listesine yeni öğe ekler"""
99
- cursor = db.cursor()
100
-
101
- if order is None:
102
- cursor.execute('SELECT MAX(item_order) FROM generate_list')
103
- max_order = cursor.fetchone()[0] or 0
104
- order = max_order + 1
105
-
106
- cursor.execute('''
107
- INSERT INTO generate_list (title, image_url, contour, item_order)
108
- VALUES (?, ?, ?, ?)
109
- ''', (title, image_url, contour, order))
110
- db.commit()
111
- return cursor.lastrowid
112
-
113
- def update_item_order(db, item_id, new_order):
114
- """Öğenin sıralama pozisyonunu günceller"""
115
- cursor = db.cursor()
116
- cursor.execute('''
117
- UPDATE generate_list
118
- SET item_order = ?
119
- WHERE id = ?
120
- ''', (new_order, item_id))
121
- db.commit()
122
- return cursor.rowcount > 0
123
 
124
  def create_user(udid, platform):
125
  """Yeni kullanıcı oluşturur"""
 
25
  if db is not None:
26
  db.close()
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  def create_user(udid, platform):
30
  """Yeni kullanıcı oluşturur"""