Add multi-account support
- Schema: account_id FK on checks and layout_fields; UNIQUE per-account on check_no and field_name - DB: runtime migration recreates both tables to add account_id (assigns existing rows to account 1) - Routes: GET /api/accounts lists all; GET /api/account/:id replaces hardcoded id=1; POST /api/account/setup always creates a new account and returns accountId - checks.js: all queries scoped by account_id; POST requires account_id in body - pdf.js: resolves account from check's account_id instead of id=1; layout fields fetched per-account - import-mdb.js: always INSERTs a new account (never deletes existing); all records tagged with new accountId - Frontend: account switcher in header; activeAccountId persisted to localStorage; all API calls pass account_id; switching accounts reloads checks; wizard and import auto-switch to newly created account
This commit is contained in:
+26
-33
@@ -1,7 +1,4 @@
|
||||
-- ezcheck SQLite schema
|
||||
-- Mirrors .mdb structure (T100, T104, T200) with readable column names.
|
||||
-- One account per database is the Phase 1 assumption.
|
||||
-- Phase 2 will add foreign keys and an account switcher.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS account (
|
||||
id INTEGER PRIMARY KEY,
|
||||
@@ -16,21 +13,17 @@ CREATE TABLE IF NOT EXISTS account (
|
||||
current_check_no INTEGER NOT NULL DEFAULT 1000,
|
||||
check_width REAL NOT NULL DEFAULT 8.5,
|
||||
check_height REAL NOT NULL DEFAULT 3.5,
|
||||
-- Per-check offset adjustments in inches (for printer calibration)
|
||||
offset_left REAL NOT NULL DEFAULT 0,
|
||||
offset_right REAL NOT NULL DEFAULT 0,
|
||||
offset_up REAL NOT NULL DEFAULT 0,
|
||||
offset_down REAL NOT NULL DEFAULT 0,
|
||||
-- Company info lines (printed top-left of check)
|
||||
company1 TEXT,
|
||||
company2 TEXT,
|
||||
company3 TEXT,
|
||||
company4 TEXT,
|
||||
-- Images stored as base64 data URIs
|
||||
logo_data TEXT,
|
||||
signature_data TEXT,
|
||||
-- Metadata
|
||||
blank_stock INTEGER NOT NULL DEFAULT 1, -- 1 = blank check stock
|
||||
blank_stock INTEGER NOT NULL DEFAULT 1,
|
||||
check_position TEXT NOT NULL DEFAULT '3-per-page',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
@@ -38,10 +31,11 @@ CREATE TABLE IF NOT EXISTS account (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS checks (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
account_id INTEGER NOT NULL DEFAULT 1 REFERENCES account(id),
|
||||
check_no INTEGER NOT NULL,
|
||||
payee TEXT NOT NULL,
|
||||
amount REAL NOT NULL,
|
||||
check_date TEXT NOT NULL, -- ISO date string YYYY-MM-DD
|
||||
check_date TEXT NOT NULL,
|
||||
memo TEXT,
|
||||
note1 TEXT,
|
||||
note2 TEXT,
|
||||
@@ -49,34 +43,33 @@ CREATE TABLE IF NOT EXISTS checks (
|
||||
payee_address2 TEXT,
|
||||
payee_address3 TEXT,
|
||||
payee_address4 TEXT,
|
||||
printed INTEGER NOT NULL DEFAULT 0, -- 0 = not printed, 1 = printed
|
||||
printed INTEGER NOT NULL DEFAULT 0,
|
||||
add_date TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
-- original .mdb CheckID preserved if migrated, null if created in app
|
||||
mdb_check_id INTEGER,
|
||||
UNIQUE(check_no)
|
||||
UNIQUE(account_id, check_no)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS layout_fields (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
field_name TEXT NOT NULL UNIQUE,
|
||||
field_text TEXT, -- static label text (for Text type fields)
|
||||
font_name TEXT NOT NULL DEFAULT 'Helvetica',
|
||||
font_size REAL NOT NULL DEFAULT 10,
|
||||
-- FldFontType from .mdb: 0=normal, 1=bold
|
||||
font_bold INTEGER NOT NULL DEFAULT 0,
|
||||
-- FldType: 'Regular' (data), 'Text' (static label), 'Graph' (image), 'Line'
|
||||
field_type TEXT NOT NULL DEFAULT 'Regular',
|
||||
line_thick INTEGER NOT NULL DEFAULT 1,
|
||||
x_pos REAL NOT NULL DEFAULT 0,
|
||||
y_pos REAL NOT NULL DEFAULT 0,
|
||||
x_end_pos REAL NOT NULL DEFAULT 0,
|
||||
y_end_pos REAL NOT NULL DEFAULT 0,
|
||||
visible INTEGER NOT NULL DEFAULT 1,
|
||||
-- 1 = only used on blank stock (not preprinted). We always render these.
|
||||
not_for_preprint INTEGER NOT NULL DEFAULT 0
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
account_id INTEGER NOT NULL DEFAULT 1 REFERENCES account(id),
|
||||
field_name TEXT NOT NULL,
|
||||
field_text TEXT,
|
||||
font_name TEXT NOT NULL DEFAULT 'Helvetica',
|
||||
font_size REAL NOT NULL DEFAULT 10,
|
||||
font_bold INTEGER NOT NULL DEFAULT 0,
|
||||
field_type TEXT NOT NULL DEFAULT 'Regular',
|
||||
line_thick INTEGER NOT NULL DEFAULT 1,
|
||||
x_pos REAL NOT NULL DEFAULT 0,
|
||||
y_pos REAL NOT NULL DEFAULT 0,
|
||||
x_end_pos REAL NOT NULL DEFAULT 0,
|
||||
y_end_pos REAL NOT NULL DEFAULT 0,
|
||||
visible INTEGER NOT NULL DEFAULT 1,
|
||||
not_for_preprint INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE(account_id, field_name)
|
||||
);
|
||||
|
||||
-- Index for fast ledger queries
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_date ON checks(check_date);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_printed ON checks(printed);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_check_no ON checks(check_no);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_date ON checks(check_date);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_printed ON checks(printed);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_check_no ON checks(check_no);
|
||||
CREATE INDEX IF NOT EXISTS idx_checks_account ON checks(account_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_layout_account ON layout_fields(account_id);
|
||||
|
||||
Reference in New Issue
Block a user