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.
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/chat/internal/config"
|
||||
"git.eeqj.de/sneak/chat/internal/logger"
|
||||
@@ -51,19 +50,9 @@ func (s *Database) GetDB() *sql.DB {
|
||||
return s.db
|
||||
}
|
||||
|
||||
// NewChannel creates a Channel model instance with the db reference injected.
|
||||
func (s *Database) NewChannel(id int64, name, topic, modes string, createdAt, updatedAt time.Time) *models.Channel {
|
||||
c := &models.Channel{
|
||||
ID: id,
|
||||
Name: name,
|
||||
Topic: topic,
|
||||
Modes: modes,
|
||||
CreatedAt: createdAt,
|
||||
UpdatedAt: updatedAt,
|
||||
}
|
||||
c.SetDB(s)
|
||||
|
||||
return c
|
||||
// Hydrate injects the database reference into any model that embeds Base.
|
||||
func (s *Database) Hydrate(m interface{ SetDB(d models.DB) }) {
|
||||
m.SetDB(s)
|
||||
}
|
||||
|
||||
// New creates a new Database instance and registers lifecycle hooks.
|
||||
|
||||
Reference in New Issue
Block a user