Initial scaffold for AvtoAmbor parts inventory

SvelteKit 2 + Svelte 4 + adapter-node, SQLite via better-sqlite3 (WAL,
foreign keys on). Bilingual EN/Тоҷикӣ throughout, locale persisted in
localStorage.

Pages: dashboard (totals, low stock, recent movements), parts list with
search and sort, part create/edit, record movement (in/out/adjust with
smart unit-price and adjust-quantity prefill), suppliers list with
inline add.

Schema: categories, suppliers, parts (with _en/_tg name+description
columns, dirams for money), stock_movements with check on movement_type.
On-hand updates are done in JS inside a transaction with the movement
insert.

Dockerized dev: docker compose, named project, bind-mounted data/ for
DB persistence. Seed contains 6 categories, 4 suppliers, 31 realistic
parts (Lada / Nexia / Opel / Toyota bias).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
David Beccue
2026-05-16 07:05:24 +05:00
commit 05be5b03aa
37 changed files with 4617 additions and 0 deletions

35
scripts/init-db.js Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env node
// Build data/avtoambor.db from schema.sql + seed.sql.
// Safe to run from anywhere — paths are resolved relative to this file.
import Database from 'better-sqlite3';
import { readFileSync, mkdirSync, existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, '..');
const DATA_DIR = resolve(ROOT, 'data');
const DB_PATH = resolve(DATA_DIR, 'avtoambor.db');
const SCHEMA = resolve(ROOT, 'src/lib/server/schema.sql');
const SEED = resolve(ROOT, 'src/lib/server/seed.sql');
if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true });
const db = new Database(DB_PATH);
db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON');
console.log(`[init-db] applying schema → ${DB_PATH}`);
db.exec(readFileSync(SCHEMA, 'utf8'));
const partsCount = db.prepare(`SELECT COUNT(*) AS n FROM parts`).get().n;
if (partsCount === 0) {
console.log('[init-db] inserting seed data…');
db.exec(readFileSync(SEED, 'utf8'));
} else {
console.log(`[init-db] parts table already has ${partsCount} rows — skipping seed.`);
}
db.close();
console.log('[init-db] done.');