Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Games migration draft/skeleton/design/needs feedback #1041

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions db/migrations/202207192223_games_migration.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN;

DROP TABLE IF EXISTS omgwords CASCADE;
DROP TABLE IF EXISTS omgwords_turns CASCADE;
DROP TABLE IF EXISTS omgwords_requests CASCADE;
DROP TABLE IF EXISTS omgwords_tournament_data CASCADE;
DROP TABLE IF EXISTS omgwords_meta_events CASCADE;
DROP TABLE IF EXISTS omgwords_stats CASCADE;

COMMIT;
27 changes: 27 additions & 0 deletions db/migrations/202207192223_games_migration.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
BEGIN;

CREATE TABLE IF NOT EXISTS omgwords (

);

CREATE TABLE IF NOT EXISTS omgwords_turns (

);

CREATE TABLE IF NOT EXISTS omgwords_requests (

);

CREATE TABLE IF NOT EXISTS omgwords_tournament_data (

);

CREATE TABLE IF NOT EXISTS omgwords_meta_events (

);

CREATE TABLE IF NOT EXISTS omgwords_stats (

);

COMMIT;
9 changes: 9 additions & 0 deletions pkg/gameplay/end.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ func performEndgameDuties(ctx context.Context, g *entity.Game, gameStore GameSto

// send each player their new profile with updated ratings.
sendProfileUpdate(ctx, g, users)

// Asynchronously write the game stats to the db the new way:
// go func() {
// err := omgwords.HandleGameEnded(ctx, g)
// if err != nil {
// log.Info().Err(err)
// }
// }()

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/stores/game/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,14 @@ func (s *DBStore) Set(ctx context.Context, g *entity.Game) error {
result := ctxDB.Model(&game{}).Clauses(clause.Locking{Strength: "UPDATE"}).
Where("uuid = ?", g.GameID()).Updates(dbg)

// Asynchronously write the game to the db the new way:
// go func() {
// err := omgwords.Set(ctx, g)
// if err != nil {
// log.Info().Err(err)
// }
// }()

return result.Error
}

Expand Down
39 changes: 39 additions & 0 deletions pkg/stores/omgwords/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package omgwords

import (
"context"

"github.com/domino14/liwords/pkg/entity"
"github.com/jackc/pgx/v4/pgxpool"
)

type DBStore struct {
dbPool *pgxpool.Pool
}

func NewDBStore(p *pgxpool.Pool) (*DBStore, error) {
return &DBStore{dbPool: p}, nil
}

func (s *DBStore) Disconnect() {
s.dbPool.Close()
}

func (s *DBStore) Create(ctx context.Context, g *entity.Game) error {
// Create row in omgwords table
// Create row in omgwords_requests table
// Create row in omgwords_tournament_data table
return nil
}

func (s *DBStore) Set(ctx context.Context, g *entity.Game) error {
// Conditionally create row in omgwords_turns
// Conditionally create row in omgwords_meta_events
// Conditionally modify omgwords table
return nil
}

func (s *DBStore) HandleGameEnded(ctx context.Context, g *entity.Game) error {
// Create row in omgwords_stats
return nil
}