- Add backend stale process monitoring API (/api/stale-processes) - Add users management route - Add frontend landing page and stale process monitor UI on /scraper-tools - Move old development scripts to backend/archive/ - Update frontend build with new features 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { Pool } from 'pg';
|
|
|
|
const pool = new Pool({
|
|
connectionString: 'postgresql://dutchie:dutchie_local_pass@localhost:54320/dutchie_menus'
|
|
});
|
|
|
|
async function createBrandsTable() {
|
|
try {
|
|
console.log('Creating brands table...');
|
|
|
|
await pool.query(`
|
|
CREATE TABLE IF NOT EXISTS brands (
|
|
id SERIAL PRIMARY KEY,
|
|
store_id INTEGER NOT NULL REFERENCES stores(id) ON DELETE CASCADE,
|
|
name VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
console.log('✅ Brands table created');
|
|
|
|
// Create index for faster queries
|
|
await pool.query(`
|
|
CREATE INDEX IF NOT EXISTS idx_brands_store_id ON brands(store_id)
|
|
`);
|
|
|
|
console.log('✅ Index created on store_id');
|
|
|
|
// Create unique constraint
|
|
await pool.query(`
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_brands_store_name ON brands(store_id, name)
|
|
`);
|
|
|
|
console.log('✅ Unique constraint created on (store_id, name)');
|
|
|
|
console.log('\nCreating specials table...');
|
|
|
|
await pool.query(`
|
|
CREATE TABLE IF NOT EXISTS specials (
|
|
id SERIAL PRIMARY KEY,
|
|
store_id INTEGER NOT NULL REFERENCES stores(id) ON DELETE CASCADE,
|
|
product_id INTEGER REFERENCES products(id) ON DELETE CASCADE,
|
|
name VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
discount_amount NUMERIC(10, 2),
|
|
discount_percentage NUMERIC(5, 2),
|
|
special_price NUMERIC(10, 2),
|
|
original_price NUMERIC(10, 2),
|
|
valid_date DATE NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)
|
|
`);
|
|
|
|
console.log('✅ Specials table created');
|
|
|
|
// Create composite index for fast date-based queries
|
|
await pool.query(`
|
|
CREATE INDEX IF NOT EXISTS idx_specials_store_date ON specials(store_id, valid_date DESC)
|
|
`);
|
|
|
|
console.log('✅ Index created on (store_id, valid_date)');
|
|
|
|
// Create index on product_id for joins
|
|
await pool.query(`
|
|
CREATE INDEX IF NOT EXISTS idx_specials_product_id ON specials(product_id)
|
|
`);
|
|
|
|
console.log('✅ Index created on product_id');
|
|
|
|
console.log('\n🎉 All tables and indexes created successfully!');
|
|
|
|
} catch (error: any) {
|
|
console.error('❌ Error:', error.message);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
createBrandsTable();
|