diff --git a/migrations/001_initial_schema.up.sql b/migrations/001_initial_schema.up.sql index 9b2aa59..95deb1c 100644 --- a/migrations/001_initial_schema.up.sql +++ b/migrations/001_initial_schema.up.sql @@ -76,3 +76,13 @@ CREATE TABLE sessions( username TEXT NOT NULL, FOREIGN KEY (username) REFERENCES players(username) ON DELETE CASCADE ); + +CREATE TABLE journal( + id INTEGER PRIMARY KEY AUTOINCREMENT, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + entry TEXT NOT NULL DEFAULT '', + username TEXT NOT NULL, + room_id TEXT NOT NULL, + FOREIGN KEY (username) REFERENCES players(username) ON DELETE CASCADE, + FOREIGN KEY (room_id) REFERENCES rooms(id) ON DELETE CASCADE +); diff --git a/models/main.go b/models/main.go index d745381..bcccb75 100644 --- a/models/main.go +++ b/models/main.go @@ -130,6 +130,14 @@ type CardMark struct { Username string `db:"username"` } +type Journal struct { + ID uint32 `db:"id"` + Username string `db:"username"` + RoomID string `db:"room_id"` + Entry string `db:"entry"` + CreatedAt time.Time `db:"created_at"` +} + type Room struct { ID string `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` @@ -151,7 +159,7 @@ type Room struct { BlueTeam Team `db:"-"` Cards []WordCard `db:"-"` BotMap map[string]BotPlayer `db:"-"` - LogJournal []string `db:"-"` + LogJournal []Journal `db:"-"` Settings GameSettings `db:"-"` } diff --git a/repos/journal.go b/repos/journal.go new file mode 100644 index 0000000..b1746c9 --- /dev/null +++ b/repos/journal.go @@ -0,0 +1,12 @@ +package repos + +import ( + "context" + "gralias/models" +) + +type JournalRepo interface { + JournalByRoomID(ctx context.Context, roomID string) ([]models.Journal, error) + JournalCreate(ctx context.Context, action *models.Journal) error + JournalDeleteByRoomID(ctx context.Context, roomID string) error +}