A brief summary of the things to do to create an alias of all players.
0. Before make any changes in your database, make sure you have a backup.
To create a backup of your database, you have to open your pgadmin by Start>All programs>Postgresql X.X> pgadmin. Then connect to "PostgreSQL" and insert your user and password if requested and right click on your database.
After that, you can choice the "Backup" option and select the name and folder of your backup file. Make sure that at the end of the process it returns the 0 exit code (means no error).
To restore the database, the correct procedure is to create a new database by HEM, then open pgadmin III, right click on the created database and then choice "Restore". At this point, you have to select the file containing the database backup and click ok. Again, make sure there are no errors at the end of the process.
1. After the backup, first of all you have to create an alias for your nicknames. It's simple to do that on HEM: in HEM1, for example, click on Options>Player Aliases, then click on Add alias, choice a name for it (ie Hero) and then add to it all your nicknames clicking on Add Player. I don't use HEM2, but I assume the process is the same.
2. Open your pgadmin by clicking on Start> All Programs> PostgreSQL X.X (for me it's 9.0) and click on pgadmin. Once opened, expand Server and double-click on PostgreSQL X.X (localhost: yyyy). If required, enter the password. At this point you have to expand Databases and click on your database of interest (for me it's SNG HU).
3. Then you have to open the query tools by Tools> Query tools. When the new window opens, make sure you are using the correct database checking the window title (for me it's Query - SNG HU on ...). Then insert the codes listed below. For every code, you have to run it by clicking on Query>Execute (or just press F5). If you have to insert a new code, open a new query window by clicking File>New window (or just press CTRL+N)
At this point the things changes if you are using HEM1 (a) or HEM2 (b).
4.Run this query. It create the new alias 'Global alias' and return its id; note the number, it will serve you in a minute.
a)
Code:
INSERT INTO players (site_id, playername, cashhands, tourneyhands, playertype_id)
VALUES (-1, 'Global alias', 0, 0, 0)
RETURNING player_id;
b)
Code:
INSERT INTO players (playername, pokersite_id, cashhands, tourneyhands, optimizationstatus, icon)
VALUES ('Global alias', -1, 0, 0, 0, 0)
RETURNING player_id;
5. Assume that the number returned by the previous query is 12345.
Then populate the alias with this code. You have to replace "12345" with the number returned by the previous query and "Hero" with the
alias name choosed for your nicknames in step 1 (not your nickname!!! ).
a)
Code:
INSERT INTO aliases
SELECT 12345, p1.player_id
FROM players p1
WHERE p1.player_id NOT IN
(
SELECT a1.player_id
FROM aliases a1
WHERE a1.aliasplayer_id = 12345
-- to exclude players yet inserted
)
AND p1.player_id NOT IN
(
SELECT a2.player_id
FROM players p2 JOIN aliases a2 ON p2.player_id = a2.aliasplayer_id
WHERE p2.site_id = -1 and p2.playername = 'Hero'
-- to exclude hero nicknames from the insert
)
AND p1.site_id <> -1
-- to exclude other aliases
;
b)
Code:
INSERT INTO aliases
SELECT 12345, p1.player_id
FROM players p1
WHERE p1.player_id NOT IN
(
SELECT a1.player_id
FROM aliases a1
WHERE a1.aliasplayer_id = 12345
-- to exclude players yet inserted
)
AND p1.player_id NOT IN
(
SELECT a2.player_id
FROM players p2 JOIN aliases a2 ON p2.player_id = a2.aliasplayer_id
WHERE p2.pokersite_id = -1 and p2.playername = 'Hero'
-- to exclude hero nicknames from the insert
)
AND p1.pokersite_id <> -1
-- to exclude other aliases
;
6. If your database has more than 10 000 players, the first time you run the script you have to separate the players in different groups. At the end of code in step 5 (before the last semicolon) insert this code and run it
Code:
-- ...all the previous code above...
AND p1.player_id < 5000;
Then, as above, insert at the end of the code in step 5 this code and run it
Code:
-- ...all the previous code above...
AND p1.player_id >= 5000 AND p1.player_id < 10000;
Continue until you inserted the whole players.
For the next times you have to execute only code in step 5.
7. Optimize your database. To do it right-click on your database by pgadmin (for me it's SNG HU) and:
a) click on Maintenance, select VACUUM, check FULL and ANALYZE and click OK. When it completes, click on Done.
b) Select REINDEX and click OK; again, at the end click on Done.
8. Now you can close pgadmin and look at your alias on HEM. If you had it opened restart it and ... enjoy!!
NB: I'm sorry for my bad English. Some terms can be different on your pgadmin because I don't use an English version.
Any help with the work on the Global Alias is appreciated.