fix(db): Delete unused value of name

This commit is contained in:
Black_Raven committed 2026-07-26 19:07:21 +03:00
1 parent 30c81e5aa5
commit 0a6418d84d
4 files changed
+39 -23

No files matched your search

+3 -15
View File
@@ -63,11 +63,8 @@ def parse_product_data(product_text):
else:
length = 0
short_name = f"Труба ПВХ {diameter}мм {application_type} {length}мм" if diameter else product_text[:50]
return {
'short_name': short_name,
'full_name': product_text,
'name': product_text,
'diameter': diameter,
'wall_thickness': wall_thickness,
'length': length,
@@ -96,14 +93,6 @@ def add_product(conn, product_text, category_id, image_path=None,
application_type = application_type or product_data['application_type']
stiffness_class = stiffness_class or product_data['stiffness_class']
# Формируем короткое имя
if diameter and length:
name = f"Труба ПВХ {diameter}мм {application_type} {length}мм"
elif fitting_type and diameter:
name = f"{fitting_type.capitalize()} ПВХ {diameter}мм"
else:
name = product_text[:100]
# Формируем описание
description_parts = []
if fitting_type:
@@ -127,12 +116,11 @@ def add_product(conn, product_text, category_id, image_path=None,
try:
cursor.execute('''
INSERT INTO products (
name, full_name, description, category_id,
name, description, category_id,
diameter, wall_thickness, length, color,
application_type, stiffness_class, image_path
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (
name,
product_text,
description,
category_id,
+31 -1
View File
@@ -22,7 +22,6 @@ def init_database(db_name='pipe_store.db'):
CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
full_name TEXT NOT NULL,
description TEXT,
category_id INTEGER NOT NULL,
diameter INTEGER,
@@ -63,6 +62,37 @@ def init_database(db_name='pipe_store.db'):
cursor.execute('CREATE INDEX IF NOT EXISTS idx_products_length ON products(length)')
cursor.execute('CREATE INDEX IF NOT EXISTS idx_product_filters_key_value ON product_filters(filter_key, value)')
# Миграция: переименовываем full_name → name
cursor.execute("PRAGMA table_info(products)")
columns = {row[1] for row in cursor.fetchall()}
if 'full_name' in columns and 'name' not in columns:
cursor.executescript('''
PRAGMA foreign_keys=OFF;
CREATE TABLE products_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT,
category_id INTEGER NOT NULL,
diameter INTEGER,
wall_thickness REAL,
length INTEGER,
color TEXT,
application_type TEXT,
stiffness_class TEXT,
image_path TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES categories (id)
);
INSERT INTO products_new (id, name, description, category_id, diameter, wall_thickness, length, color, application_type, stiffness_class, image_path, created_at)
SELECT id, full_name, description, category_id, diameter, wall_thickness, length, color, application_type, stiffness_class, image_path, created_at FROM products;
DROP TABLE products;
ALTER TABLE products_new RENAME TO products;
CREATE INDEX IF NOT EXISTS idx_products_category ON products(category_id);
CREATE INDEX IF NOT EXISTS idx_products_diameter ON products(diameter);
CREATE INDEX IF NOT EXISTS idx_products_length ON products(length);
''')
log.info("Migrated products table: renamed 'full_name' → 'name'")
conn.commit()
conn.close()
log.success("База данных успешно инициализирована!")
+5 -6
View File
@@ -141,7 +141,7 @@ def get_product_by_id(product_id: int, db_name: str = 'pipe_store.db') -> Option
try:
cursor.execute("""
SELECT p.id, p.name, p.full_name, p.description,
SELECT p.id, p.name, p.description,
p.diameter, p.wall_thickness, p.length, p.color,
p.application_type, p.stiffness_class, p.image_path,
p.created_at, p.category_id
@@ -192,7 +192,6 @@ def get_product_by_id(product_id: int, db_name: str = 'pipe_store.db') -> Option
return {
"id": row['id'],
"name": row['name'],
"full_name": row['full_name'],
"description": full_description,
"price": None,
"categoryId": row['category_id'],
@@ -239,8 +238,8 @@ def generate_full_description(row: sqlite3.Row) -> str:
"""Сгенерировать полное описание товара"""
parts = []
if row['full_name']:
parts.append(row['full_name'])
if row['name']:
parts.append(row['name'])
if row['description']:
parts.append(row['description'])
@@ -264,7 +263,7 @@ def generate_full_description(row: sqlite3.Row) -> str:
def get_product_list(page=1, limit=100, category_id=None):
"""
Получить список товаров с пагинацией (без фильтров).
Возвращает список словарей с полями id, full_name, description.
Возвращает список словарей с полями id, name, description.
"""
conn = None
try:
@@ -278,7 +277,7 @@ def get_product_list(page=1, limit=100, category_id=None):
for row in rows:
products.append({
'id': row['id'],
'full_name': row['full_name'],
'name': row['name'],
'description': row['description']
})
return products