Difference between revisions of "Setting up Database"

From Nexus Mods Wiki
Jump to: navigation, search
(Specifying not to download PostgreSQL Version 12)
Line 4: Line 4:
 
The Game database contains all the game data, such as items, dialogues, perks, etc. The modding pack contains a dump of the game database in SQL format. In this tutorial we are going to use PostreSQL hosted locally on your computer, which the modding tools will connect to. 
 
The Game database contains all the game data, such as items, dialogues, perks, etc. The modding pack contains a dump of the game database in SQL format. In this tutorial we are going to use PostreSQL hosted locally on your computer, which the modding tools will connect to. 
  
First download and install PostreSQL from [https://www.postgresql.org/ their website]. After install the database server should be up and running. Then we open pgAdmin (comes with the PostgreSQL package)&nbsp;tool and connect to the server. After connecting to the server we have to create a new database called&nbsp;<tt><q>ConfigDB</q></tt>&nbsp;(the name is unfortunatley hardcoded into some of the tools). When created add new <tt><q>uuid-ossp</q></tt> extention to this database.
+
First download and install PostreSQL from [https://www.postgresql.org/ their website]. (Do not install version 12, as this might cause missing column "adsrc") After install the database server should be up and running. Then we open pgAdmin (comes with the PostgreSQL package)&nbsp;tool and connect to the server. After connecting to the server we have to create a new database called&nbsp;<tt><q>ConfigDB</q></tt>&nbsp;(the name is unfortunatley hardcoded into some of the tools). When created add new <tt><q>uuid-ossp</q></tt> extention to this database.
  
 
https://wiki.nexusmods.com/images/0/0c/Setting_Up_Database_image1.jpg
 
https://wiki.nexusmods.com/images/0/0c/Setting_Up_Database_image1.jpg
  
 
If you do not have acces to the pgAdmin you can run this via command line using&nbsp;''psql.exe''&nbsp;(comes with PostgreSQL package) with the following commands.&nbsp;
 
If you do not have acces to the pgAdmin you can run this via command line using&nbsp;''psql.exe''&nbsp;(comes with PostgreSQL package) with the following commands.&nbsp;
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px"><tt>CREATE DATABASE ConfigDB<br/> CREATE EXTENSION "uuid-ossp"</tt></div>  
+
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px"><tt>CREATE DATABASE ConfigDB<br/> CREATE EXTENSION "uuid-ossp"</tt></div>  
 
After&nbsp;completing first step we use&nbsp;''psql.exe&nbsp;''&nbsp;to restore the database from provided dumps.
 
After&nbsp;completing first step we use&nbsp;''psql.exe&nbsp;''&nbsp;to restore the database from provided dumps.
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px">
+
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px">
 
<tt>psql.exe -f&nbsp;Data_reference/modding.sql -U&nbsp;postgres –d&nbsp;ConfigDB -q&nbsp;</tt>
 
<tt>psql.exe -f&nbsp;Data_reference/modding.sql -U&nbsp;postgres –d&nbsp;ConfigDB -q&nbsp;</tt>
  
Line 23: Line 23:
  
 
Some tables use autoincrement to generate IDs for new entries. If you are going to create new dialogues, you are going to need to adjust the initial value for this autoincrement to a value unique for your mod. If you don’t, your mod will clash with any other mods that also failed to set a unique value. To do this, open file <tt>Data_references.sql/sequences.sql</tt> and change the value 10578 to any value unique to your mod (ideally a value that is far enough from other mod’s values, by at least several hundreds. Since the first ids are used by KCD’s entries,choose a number higher than 100000).Then run following command:&nbsp;
 
Some tables use autoincrement to generate IDs for new entries. If you are going to create new dialogues, you are going to need to adjust the initial value for this autoincrement to a value unique for your mod. If you don’t, your mod will clash with any other mods that also failed to set a unique value. To do this, open file <tt>Data_references.sql/sequences.sql</tt> and change the value 10578 to any value unique to your mod (ideally a value that is far enough from other mod’s values, by at least several hundreds. Since the first ids are used by KCD’s entries,choose a number higher than 100000).Then run following command:&nbsp;
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px"><tt>psql.exe -f Data_reference/sequences.sql -U postgres –d ConfigDB –q&nbsp;</tt></div>  
+
<div style="background:#000; border:1px solid #cccccc; padding:5px 10px"><tt>psql.exe -f Data_reference/sequences.sql -U postgres –d ConfigDB –q&nbsp;</tt></div>  
 
&nbsp;
 
&nbsp;
  

Revision as of 13:31, 31 October 2019

Database

The Game database contains all the game data, such as items, dialogues, perks, etc. The modding pack contains a dump of the game database in SQL format. In this tutorial we are going to use PostreSQL hosted locally on your computer, which the modding tools will connect to. 

First download and install PostreSQL from their website. (Do not install version 12, as this might cause missing column "adsrc") After install the database server should be up and running. Then we open pgAdmin (comes with the PostgreSQL package) tool and connect to the server. After connecting to the server we have to create a new database called ConfigDB (the name is unfortunatley hardcoded into some of the tools). When created add new uuid-ossp extention to this database.

Setting_Up_Database_image1.jpg

If you do not have acces to the pgAdmin you can run this via command line using psql.exe (comes with PostgreSQL package) with the following commands. 

CREATE DATABASE ConfigDB
CREATE EXTENSION "uuid-ossp"

After completing first step we use psql.exe  to restore the database from provided dumps.

psql.exe -f Data_reference/modding.sql -U postgres –d ConfigDB -q 

psql.exe -f Data_reference/public.sql -U postgres –d ConfigDB -q 

Ideally this command should run with no output of any kind (the -q switch hides all non-errors, and there should be no errors). In your database, there should be now a schema called modding with 468 tables.  

 

Autoincrement

Some tables use autoincrement to generate IDs for new entries. If you are going to create new dialogues, you are going to need to adjust the initial value for this autoincrement to a value unique for your mod. If you don’t, your mod will clash with any other mods that also failed to set a unique value. To do this, open file Data_references.sql/sequences.sql and change the value 10578 to any value unique to your mod (ideally a value that is far enough from other mod’s values, by at least several hundreds. Since the first ids are used by KCD’s entries,choose a number higher than 100000).Then run following command: 

psql.exe -f Data_reference/sequences.sql -U postgres –d ConfigDB –q 

 

Setting up tools 

There are several tools that work with the SQL database. Most of them require you to set up correct registry keys which they read connection information from. To do that, modify file Tools/!registry/db.reg  (you only need to modify the password, postgres is the default user) and then run it. All of the tools, except the Sandbox editor, use these registry keys. To get the Sandbox to connect, fill in correct connection information in user.cfg. Sandbox editor also requires an ODBC Driver to use. Install one for postgreSQL from their site (use 64-bit version). 

 

Working with Database

The database can be edited with any SQL client you prefer, or you can use our custom tool.  It is a plugin for MS Excel, which simplifies editing tables by unpacking foreign keys. To use it, you need to install in from Tools/ExcelDbAddin2, which installs it directly into MS Excel (it can be removed at any time in “Add or Remove programs”). It will appear as a new menu item called WHS DB

Any changes made to the database will be visible in the Sandbox editor (with the exception of Localization). The game, however, reads the database from XML files inside Tables.pak or mod PAK files. To create such PAKs, use the editor’s modding window .