mysql

package
v0.0.0-...-6b15219 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

Testing this package assumes that you have a MySQL server running at localhost:3306.

WARNING: a database named TEMPORARY_DATABASE_boardgame_test will be created and then dropped by this test. Ensure there's no real data in it!

Connection strings

The connections trings that are passed to storage.Connect() are of a Data Source Name, described at https://github.com/go-sql-driver/mysql#dsn-data-source-name .

Normally these strings contain the password, and so they shouldn't be checked into source control. They are generally configured in config.SECRET.json, in the storageconfig section.

Currently the only db name that is supported is boardgame

A few examples:

Default for just a basic mamp installation

root:root@tcp(localhost:3306)/boardgame

An example of connecting in prod to a Google Cloud SQL service:

prod:PASSWORD_GOES_HERE@unix(/cloudsql/boardgame-159316:us-east1:prod)/boardgame

where the part after the /cloudsql/ can be derived from running gcloud sql instances describe prod, and noting the connectionName in the result. Full instructions for that string are here: https://cloud.google.com/appengine/docs/flexible/go/using-cloud-sql

Creating the database

The boardgame-util db tool is designed to help administer your database.

To set up a database, configure the DSN as described above. Then, sitting in the same folder as config.SECRET.json, run boardgame-util db setup (include --prod if you want to run on the prod database.

Making sure the database is up-to-date

Before doing a push to prod it's a good idea to make sure the database is set up correctly with the most recent changes since the last push. Run boardgame-util db up to make sure all migrations are applied.

Updating the database structure

When making a change to the database structure, create two files in mysql/migrations, named NNNN_<name-of-change>.down.sql and NNNN_<name-of-change>.up.sql where NNNN is the next sequence number. (Don't forget to add them with git add)

Documentation

Overview

Package mysql provides a mysql-backed database that implements both boardgame.StorageManager and boardgame/server.StorageManager. See the README.md for more information on how to configure and use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StorageManager

type StorageManager struct {
	// contains filtered or unexported fields
}

StorageManager is the primary type in this package.

func NewStorageManager

func NewStorageManager(testMode bool) *StorageManager

NewStorageManager returns a new storage manager. Does most of its set-up work in Connect(), which is when the database configuration information is passed. testMode is whether or not the storage manager is being run in the context of a test; if false, then calls to CleanUp (which drops the entire database) won't do anything.

func (*StorageManager) AgentState

func (s *StorageManager) AgentState(gameID string, player boardgame.PlayerIndex) ([]byte, error)

AgentState returns the given AgentState

func (*StorageManager) CleanUp

func (s *StorageManager) CleanUp()

CleanUp drops the test DB, but only if it was created in TestMode.

func (*StorageManager) Close

func (s *StorageManager) Close()

Close closes out the connection to the database.

func (*StorageManager) CombinedGame

CombinedGame returns the given CombinedGame

func (*StorageManager) Connect

func (s *StorageManager) Connect(config string) error

Connect connects to the database using the given DSN config string.

func (*StorageManager) ConnectCookieToUser

func (s *StorageManager) ConnectCookieToUser(cookie string, user *users.StorageRecord) error

ConnectCookieToUser affiliates the given cookie to the given user

func (*StorageManager) ExtendedGame

func (s *StorageManager) ExtendedGame(id string) (*extendedgame.StorageRecord, error)

ExtendedGame returns the given ExtendedGame

func (*StorageManager) FetchInjectedDataForGame

func (s *StorageManager) FetchInjectedDataForGame(gameID string, dataType string) interface{}

FetchInjectedDataForGame can just return nil

func (*StorageManager) Game

Game returns the given Game

func (*StorageManager) GetUserByCookie

func (s *StorageManager) GetUserByCookie(cookie string) *users.StorageRecord

GetUserByCookie gets the given user

func (*StorageManager) GetUserByID

func (s *StorageManager) GetUserByID(uid string) *users.StorageRecord

GetUserByID gets the given user

func (*StorageManager) ListGames

func (s *StorageManager) ListGames(max int, list listing.Type, userID string, gameType string) []*extendedgame.CombinedStorageRecord

ListGames lists the given games

func (*StorageManager) Move

func (s *StorageManager) Move(gameID string, version int) (*boardgame.MoveStorageRecord, error)

Move returns the given Move

func (*StorageManager) Moves

func (s *StorageManager) Moves(gameID string, fromVersion, toVersion int) ([]*boardgame.MoveStorageRecord, error)

Moves returns the given moves

func (*StorageManager) Name

func (s *StorageManager) Name() string

Name returns 'mysql'

func (*StorageManager) PlayerMoveApplied

func (s *StorageManager) PlayerMoveApplied(game *boardgame.GameStorageRecord) error

PlayerMoveApplied does nothing

func (*StorageManager) SaveAgentState

func (s *StorageManager) SaveAgentState(gameID string, player boardgame.PlayerIndex, state []byte) error

SaveAgentState saves the given agent state

func (*StorageManager) SaveGameAndCurrentState

SaveGameAndCurrentState saves the given game and current state.

func (*StorageManager) SetPlayerForGame

func (s *StorageManager) SetPlayerForGame(gameID string, playerIndex boardgame.PlayerIndex, userID string) error

SetPlayerForGame affiliates the given user in the given game to the given player

func (*StorageManager) State

func (s *StorageManager) State(gameID string, version int) (boardgame.StateStorageRecord, error)

State returns the given state

func (*StorageManager) UpdateExtendedGame

func (s *StorageManager) UpdateExtendedGame(id string, eGame *extendedgame.StorageRecord) error

UpdateExtendedGame updates the given extended game properties

func (*StorageManager) UpdateUser

func (s *StorageManager) UpdateUser(user *users.StorageRecord) error

UpdateUser updates the given user

func (*StorageManager) UserIDsForGame

func (s *StorageManager) UserIDsForGame(gameID string) []string

UserIDsForGame returns the given UserIds

func (*StorageManager) WithManagers

func (s *StorageManager) WithManagers(managers []*boardgame.GameManager)

WithManagers does nothing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL