Port of Mars is an interdisciplinary research project sponsored by Arizona State University's Interplanetary Initiative. Its original incarnation was designed and implemented as a physical card game for 5 players. We are developing a digital version of the Port of Mars game to serve as a scalable research testbed for studying collective action.
If you'd like to get involved, please let us know!
These instructions are intended for Linux / MacOS (less tested on MacOS; please submit an issue or PR if you encounter any problems) and assume you have recent versions of Docker and Docker Compose installed on your system (you may also need to install make).
To set up a development environment that starts a hot-reloading client and server, run:
% ./configure dev
% make secrets # create secrets for the database
% make # create a new docker-compose.yml and build client and server docker images
If this completes successfully you will be able to bring up all necessary services (client, server, database, redis) with docker-compose up -d
If you are starting from scratch you will need to initialize the database and initialize the schema and then load data fixtures into the database for the Port of Mars tutorial quiz questions.
% docker-compose exec server bash # open a bash shell into the server container
% yarn typeorm schema:drop # DESTRUCTIVE OPERATION, be careful with this! Drops the existing port of mars database if it exists
% yarn typeorm migration:run # initialize the port of mars database schema and apply all defined typeorm migrations in server/src/migration
% yarn load-fixtures # load data fixtures into the database
At this point you should be able to test the Port of Mars by visiting http://localhost:8081
in your browser.
For more info on typeorm data migrations see https://orkhan.gitbook.io/typeorm/docs/migrations
% yarn typeorm migration:create -n NameOfMigration
This will create a new file prefixed by a timestamp, add the custom logic in the up
and down
methods.
To display or run database migrations (for schema changes etc.) use yarn typeorm
commands e.g., migration:show
and migration:run
Example:
% yarn typeorm migration:show # shows all available migrations and any pending ones
yarn run v1.22.5
$ ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:show
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
[X] Initial1600968396723
[ ] UserMetadataAddition1607117297405
% yarn typeorm migration:run
yarn run v1.22.5
$ ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js migration:run
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'migrations'
query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC
1 migrations are already loaded in the database.
2 migrations were found in the source code.
Initial1600968396723 is the last executed migration. It was executed on Thu Sep 24 2020 17:26:36 GMT+0000 (Coordinated Universal Time).
1 migrations are new migrations that needs to be executed.
query: START TRANSACTION
query: ALTER TABLE "user" ADD "isActive" boolean NOT NULL DEFAULT true
query: ALTER TABLE "user" ADD "dateCreated" TIMESTAMP NOT NULL DEFAULT now()
query: INSERT INTO "migrations"("timestamp", "name") VALUES ($1, $2) -- PARAMETERS: [1607117297405,"UserMetadataAddition1607117297405"]
Migration UserMetadataAddition1607117297405 has been executed successfully.
query: COMMIT
Done in 1.75s.
Server tests: https://github.com/virtualcommons/port-of-mars/tree/master/server/tests
Client tests: https://github.com/virtualcommons/port-of-mars/tree/master/client/tests
You can run all of the tests via
% make test
make docker-compose.yml
generates the docker-compose.yml
from templates and can be re-run to apply any changes in these templates.
make browser
requires the open-url-in-container
Firefox extension: https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/
% ./configure staging
% make deploy
Copy the Sentry DSN url into keys/sentry_dsn
. Then
% ./configure prod
% make deploy
Development
In development, data from a tournament can be exported by running:
% ./dump.sh prod --tournamentRoundId 1 2 # tournment ids
In development, data can be exported from the database by running:
% ./dump.sh dev # all games
% ./dump.sh dev --ids 1 2 4 6 # games matching ids
Production
In staging or production, change dev
to prod
:
% ./dump.sh prod # all games
% ./dump.sh prod --ids 1 2 4 6 # game matching ids
This generates CSV files with every persisted game event as well as summary csv files with game, player and tournament data. The csv files will be in the docker/dump
folder. You can pack the results into an archive with zip -r <name-of-archive> docker/dump/processed
.
Thanks to all the contributors to this project! emoji key