There are some CSV files located within the `game_manager/assetes/InitialData` directory. These files are used to initialize the database with fresh data before a semester starts. This page will go over how to load those files into the database.
# How CSV Files Work
CSV files are simple. CSV stands for "Comma Separated Values". You can think of them as a table of rows and columns. If you open `VanityInventory.csv` located in the directory mentioned above, you will find that there are 3 items in the first line:
-`playerID`
-`vanityID`
-`isWearing`
These represent a table's columns. Below the first line, you will find a bunch of data, each line representing one row of data, containing the player ID, a vanity ID (which represents a clothing item), and whether the player is wearing that item. Each of these values are separated by commas.
# How This Relates to the Database
A MySQL database consists of a set of tables. The FRPG database, likewise, contains a particular set of tables. one of these tables is called `VanityInventory`. Can you guess what its columns are?
So, these CSV files reflect the FRPG database exactly. They contain a set of defaults that are good for starting a new semester with. So we will need to loaded them into the database.
# Prepare for Import
Importing the files is a somewhat tedious process. hopefully, this guide will make that as simple as possible. To start,
- Open an SSH tunnel into the FRPG server. There is a guide on how to do that here. TODOtodo
Then, navigate into the `assets` directory, where the CSV files are located:
Open MySQL in file loading mode (to make MySQL less angry about those CSV files):
-`mysql --local-infile=1 -uroot -p`
Then run the query:
-`USE frpg;`
# Importing the Files
It's time to import the files. Before you go any further, ensure that there is nothing important in the database currently, and that Dr. Wellington is OK with you proceeding. It also would be a good idea to make a backup of the database before doing this.
For each table that you need to initialize, take note of the first line of the matching CSV file, and run the following queries (replacing "TableName" with the name of the CSV file, and "Column1", "Column2", etc. with all of the columns in the first line of the CSV file, **in the same order as in the CSV file**):
-`DELETE * FROM `TableName`;`
-`LOAD DATA INFILE "/var/lib/mysql-files/InitialData/`TableName`.csv"`
<br>`INTO TABLE `TableName
<br>`COLUMNS TERMINATED BY ','`
<br>`LINES TERMINATED BY '\n'`
<br>`IGNORE 1 LINES`
<br>`(`Column1`,`Column2`,`Column3`);`
## Here's an example with VanityInventory.csv
-`DELETE * FROM `VanityInventory`;`
-`LOAD DATA INFILE "/var/lib/mysql-files/InitialData/`VanityInventory`.csv"`