Bug update function

This commit is contained in:
NW
2024-12-14 23:12:36 +00:00
parent 682246675e
commit 9d9e0e80ad
9 changed files with 474 additions and 201 deletions

View File

@@ -183,19 +183,30 @@ const initDb = async () => {
// Create purchases table
await db.runAsync(`
CREATE TABLE IF NOT EXISTS purchases (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
wallet_type TEXT NOT NULL,
tx_hash TEXT NOT NULL,
quantity INTEGER NOT NULL CHECK (quantity > 0),
total_price REAL NOT NULL CHECK (total_price > 0),
purchase_date DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
product_id INTEGER NOT NULL,
wallet_type TEXT NOT NULL,
tx_hash TEXT NOT NULL,
quantity INTEGER NOT NULL CHECK (quantity > 0),
total_price REAL NOT NULL CHECK (total_price > 0),
purchase_date DATETIME DEFAULT CURRENT_TIMESTAMP,
status TEXT DEFAULT 'pending',
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (product_id) REFERENCES products(id) ON DELETE CASCADE
)
`);
// Проверка наличия поля status в таблице purchases
const statusExists = await checkColumnExists('purchases', 'status');
if (!statusExists) {
await db.runAsync(`
ALTER TABLE purchases
ADD COLUMN status TEXT DEFAULT 'pending'
`);
console.log('Column status added to purchases table');
}
// Create locations table
await db.runAsync(`
CREATE TABLE IF NOT EXISTS locations (