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

+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("База данных успешно инициализирована!")