feat(db/InitializeDB.py): Initialize db
Initialized test db strusture for project
-Type is used for classificate prodycts by type
-Products is products performance
This commit is contained in:
1 parent
09eef7b206
commit
a6a267fbcc
1 file changed
+30
@@ -0,0 +1,30 @@
|
|||||||
|
import sqlite3
|
||||||
|
import uuid
|
||||||
|
from loguru import logger as log
|
||||||
|
|
||||||
|
def init_database():
|
||||||
|
conn = sqlite3.connect('products.db')
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS Product (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
price REAL,
|
||||||
|
image_path TEXT NOT NULL
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS Type (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
product_id INTEGER,
|
||||||
|
FOREIGN KEY (product_id) REFERENCES Product (id)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
log.info("База данных успешно инициализирована!")
|
||||||
Reference in new issue
Block a user