Skip to content

How to update the static data of the game

RobertCzinege edited this page Aug 13, 2020 · 8 revisions

IMPORTANT NOTES

The app's phase 1 implementation does not handle different content versions! This means that whenever the content is updated or modified, the previously played games' historical data will be lost for later reviews irreversibly.

Currently, changing the static content's structure or its relations is not possible without changing the underlying database's structure. We highly recommend NOT changing that manually as this will break the application if the corresponding logic is not updated accordingly.

NODE-ENV environment variable: The value of this environment variable decides if the database has to be reset automatically. We introduced this function for avoiding manual database reset on the staging environment where the updates are getting deployed frequently.

In the production environment, the database will NOT be reset in order to ensure data persistence. If it is necessary to reset the database, it has to be done manually.

In the staging environment (or if you would like to reset and reseed the database on every deployment/startup): NODE_ENV=test For all the other environments, please set the value to anything you would like: NODE_ENV=prod

What happens on database reset?

  1. Rolling back all the migrations (basically dropping all the tables and their content)
  2. Re-run of all the migrations (recreating all the tables and relations)
  3. Inserting the static content from the hardcoded files

Static data in the project

The static data in the project is inside the seeds folder of the CyberSim-Backend repository. Each static data set like injections or mitigations is separated into different javascript files. These files have a static prefix, followed by the number and then the name of the data set. To add new data to these sets, open the file using an editor and simply copy and paste an existing data item from the set then modify it accordingly. Each item is written inside curly braces, so in order to add a new action item copy the following code from the static_7_action.js file:

{
 id: 'A14',
description: 'Share Facebook posts from phones',
 type: 'local',
 cost: 0,
 budget_increase: 200,
 poll_increase: 0,
 required_systems: ['S7', 'S10'],
},

Then paste it to the end of the copied item:

{
 id: 'A14',
 description: 'Share Facebook posts from phones',
 type: 'local',
 cost: 0,
 budget_increase: 200,
 poll_increase: 0,
 required_systems: ['S7', 'S10'],
},
{
 id: 'A15',
 description: 'Share Facebook posts from tablets',
 type: 'hq',
 cost: 0,
 budget_increase: 300,
 poll_increase: 0,
 required_systems: ['S7', 'S10'],
},

After a new data item is added save the file and run the following commands:

 # Add new files to staging.
 $ git add .
 # Commit new changes.
 $ git commit --m "<CUSTOM_COMMIT_MESSAGE>"
 # Push changes to the github repository
 $ git push origin master
 # Reset db and update new seed data.
 $ npm run reset-db

Please note that it is important to follow the predefined structures of the data sets upon creating new data items, since incorrect new data may broke the application.

Predefined data structures

Injection (static_1_injection.js) fields

  • id: Unique identifier of the action. Type: String
  • title: Title presented on the top of the event card. Type: String
  • description: Description section on the event card. Type: String
  • trigger_time: Time in milliseconds when the event will become deliverable. Type: Number
  • location: Name of the branch that can respond to the event. It's value must be either hq or local. Type: String
  • type: Type of the event. It's value must be either Table, Background or Board. Type: String
  • recipient_role: Recipient who can respond to the event. Type: String
  • asset_code: Code of the asset that should be delivered to the table when the event occurs. Type: String
  • poll_change: Change in percent the event will affect the public opinion. Type: Number
  • systems_to_disable: List of systems (system ids) the event will disable. Type: String[]
  • skipper_mitigation: Id of the mitigation which if TRUE mitigates the event. Type: String
  • skipper_mitigation_type: Type of the skipper mitigation. It's value must be either hq, local or party. Type: String

Mitigation (static_2_mitiagtion.js) fields

  • id: Unique identifier of the mitigation. Type: String
  • description: Description of the mitigation. Type: String
  • is_hq: If true, it can be bought by the HQ branch. It's value must be either true or false. Type: Boolean
  • is_local: If true, it can be bought by the LOCAL branch. It's value must be either true or false. Type: Boolean
  • hq_cost: Cost of the mitigation for the HQ branch. Type: Number
  • local_cost: Cost of the mitigation for the LOCAL branch. Type: Number
  • category: Category of the mitigaton. It's value must be either Operation, National party voter database, National party website, Accounts, Devices. Type: String

Response (static_3_response.js) fields

  • id: Unique identifier of the mitigation. Type: String
  • description: Description of the response shown under responses of the corresponding event. Type: String
  • cost:Cost of the response. Type: Number
  • location: Name of the branch that can take the response. It's value must be either hq, local or party. Type: String
  • mitigation_id: Id of the mitigation that taking the response provides. Type: String
  • mitigation_type: Type of the mitigation that taking the response provides. It's value must be either hq, local or party. Type: String
  • systems_to_restore: List of systems (system ids) that taking the response restores. Type: String[]
  • required_mitigation: Id of the mitigation that is required to take the response. Type: String
  • required_mitigation_type: Type of the mitigation that is required to take the response. It's value must be either hq, local or party. Type: String

System (static_4_system.js) fields

  • id: Unique identifier of the system. Type: String
  • description: Description of the system. Type: String
  • name: Name of the system shown under technical systems. Type: String
  • type: Type of the system. It's value must be either hq, local or party. Type: String

Injection_Response (static_5_injection_response.js) fields

  • injection_id: Id of the injection. Type: String
  • response_id: Id of the response. Type: String
  • injection_to_prevent: Id of the injection taking the corresponding response under the injection will prevent. Type: String

Role (static_6_role.js) fields

  • id: Id of the role. Type: String
  • name: Name of the role. Type: String

Action (static_8_action.js) fields

  • id: Id of the action. Type: String
  • description: Description of the action. Type: String
  • type: Type of the action. It's value must be either hq, local or party. Type: String
  • cost: Cost of the action. Type: Number
  • **budget_change: Amount the event will affect the budget. Type: Number
  • poll_change: Change in percent the event will affect the public opinion. Type: Number
  • required_systems: List of systems (system ids) that is required to take the action. Type: String[]

Action_Role (static_8_action_role.js) fields

  • action_id: Id of the action. Type: String
  • role_id: Id of the role. Type: String

Curveball (static_9_curveball.js) fields

  • id: Id of the curveball event. Type: String
  • description: Description of the curveball event. Type: String
  • **budget_change: Amount the event will affect the budget. Type: Number
  • poll_change: Change in percent the event will affect the public opinion. Type: Number