Add complete database schema and ORM models #4

Merged
clawbot merged 6 commits from feature/database-schema into main 2026-02-11 03:02:34 +01:00

6 Commits

Author SHA1 Message Date
98a02a150d Merge pull request 'Fix code review feedback (closes #5)' (#6) from fix/review-feedback into feature/database-schema 2026-02-10 18:18:06 +01:00
clawbot
fbe53179b8 Fix code review feedback items 1-6, 8-10
- Item 1: Extract GetUserByID/GetChannelByID lookup methods, use from relation methods
- Item 2: Initialize slices with literals so JSON gets [] not null
- Item 3: Populate CreatedAt/UpdatedAt with time.Now() on all Create methods
- Item 4: Wrap each migration's SQL + recording in a transaction
- Item 5: Check error from res.LastInsertId() in QueueMessage
- Item 6: Add DequeueMessages and AckMessages methods
- Item 8: Add GetUserByNick, GetUserByToken, DeleteAuthToken, UpdateUserLastSeen
- Item 9: Run PRAGMA foreign_keys = ON on every new connection
- Item 10: Builds clean, all tests pass
2026-02-09 21:15:41 -08:00
clawbot
3f7aec7c47 Split schema: 001 = migrations table only, 002 = all schema
All schema changes go into 002_schema.sql until 1.0.0 is tagged.
No migrations during early development phase.
2026-02-09 17:49:27 -08:00
clawbot
28f3b5aef8 Add comprehensive model and relation test suite 2026-02-09 17:45:01 -08:00
clawbot
99d3e4fa0a Consolidate schema into single 001_initial.sql
No need for separate migration files before 1.0.0 — there are no
installed versions to migrate. All tables now in one file.
2026-02-09 17:15:49 -08:00
clawbot
b21508cecc Add complete database schema and ORM models
Schema (002_tables.sql):
- users: accounts with nick, password hash, timestamps
- auth_tokens: per-device tokens with expiry, linked to users
- channels: chat rooms with topic and mode flags
- channel_members: membership with per-user modes (+o, +v)
- messages: channel/DM history with structured JSON meta
- message_queue: per-user pending delivery queue
- sessions: server-held session state with idle timeout
- server_links: federation peer configuration

Models (internal/models/):
- All models embed Base for database access
- Relation methods on models: User.Channels(), User.QueuedMessages(),
  Channel.Members(), Channel.RecentMessages(), ChannelMember.User(),
  ChannelMember.Channel(), AuthToken.User(), Session.User()
- IDs are UUIDs (TEXT), not auto-increment integers
- JSON tags use camelCase per lint rules

All tables verified: migrations apply cleanly, 0 lint issues.
2026-02-09 14:54:35 -08:00