Initialized test db strusture for project
-Type is used for classificate prodycts by type
-Products is products performance
31 lines
755 B
Python
31 lines
755 B
Python
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("База данных успешно инициализирована!")
|