Add admin panel: visit counter, product editor, screenshots upload
This commit is contained in:
@@ -7,13 +7,38 @@ import (
|
||||
)
|
||||
|
||||
func Migrate(ctx context.Context, pool *pgxpool.Pool) error {
|
||||
_, err := pool.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS admins (
|
||||
queries := []string{
|
||||
`CREATE TABLE IF NOT EXISTS admins (
|
||||
id SERIAL PRIMARY KEY,
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password_hash VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
`)
|
||||
return err
|
||||
)`,
|
||||
`ALTER TABLE products ADD COLUMN IF NOT EXISTS details TEXT NOT NULL DEFAULT ''`,
|
||||
`ALTER TABLE products ADD COLUMN IF NOT EXISTS is_active BOOLEAN NOT NULL DEFAULT true`,
|
||||
`ALTER TABLE products ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()`,
|
||||
`CREATE TABLE IF NOT EXISTS product_images (
|
||||
id SERIAL PRIMARY KEY,
|
||||
product_id INT NOT NULL REFERENCES products(id) ON DELETE CASCADE,
|
||||
file_path VARCHAR(512) NOT NULL,
|
||||
is_primary BOOLEAN NOT NULL DEFAULT false,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
)`,
|
||||
`CREATE INDEX IF NOT EXISTS idx_product_images_product ON product_images (product_id)`,
|
||||
`CREATE TABLE IF NOT EXISTS site_stats (
|
||||
id INT PRIMARY KEY DEFAULT 1 CHECK (id = 1),
|
||||
total_visits BIGINT NOT NULL DEFAULT 0,
|
||||
today_visits INT NOT NULL DEFAULT 0,
|
||||
visit_date DATE NOT NULL DEFAULT CURRENT_DATE
|
||||
)`,
|
||||
`INSERT INTO site_stats (id) VALUES (1) ON CONFLICT (id) DO NOTHING`,
|
||||
}
|
||||
|
||||
for _, q := range queries {
|
||||
if _, err := pool.Exec(ctx, q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user