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:
@@ -1,9 +1,11 @@
|
||||
// Package models defines the data models used by the chat application.
|
||||
// All model structs embed Base, which provides database access for
|
||||
// relation-fetching methods directly on model instances.
|
||||
package models
|
||||
|
||||
import "database/sql"
|
||||
|
||||
// DB is the interface that models use to query relations.
|
||||
// DB is the interface that models use to query the database.
|
||||
// This avoids a circular import with the db package.
|
||||
type DB interface {
|
||||
GetDB() *sql.DB
|
||||
@@ -18,3 +20,8 @@ type Base struct {
|
||||
func (b *Base) SetDB(d DB) {
|
||||
b.db = d
|
||||
}
|
||||
|
||||
// GetDB returns the database interface for use in model methods.
|
||||
func (b *Base) GetDB() *sql.DB {
|
||||
return b.db.GetDB()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user