Windows/Linux – Combine SQL Updates

New TrinityCore revisions will frequently come with new .sql updates in the Trinity\sql\updates\ directory that need to be imported in order to keep your DB up to date. This batch file will merge all of those .sql queries into 3 simple files:

  • All_Auth_Updates.sql
  • All_Characters_Updates.sql
  • All_World_Updates.sql

Combining numerous .sql files into only 3 will make importing these new updates much simpler. Furthermore, this batch script will take into consideration the order in which new .sql updates need to be imported as well.

For Windows:

  • Copy/paste the below source into a new Notepad++ file and save it as “gather updates.bat” (without quotes of course, and whatever you’d like to call it)
  • Drop it into your main Trinity\ source directory.
  • After each TrinityCore update that you do, double-click this .bat file to merge the new .SQL queries into 3 organized .SQL files to easily import them into your auth/characters/world databases.

Put this in your Trinity\ folder: (Example output)

@echo off
setlocal EnableDelayedExpansion
set WorldUpdates=All_World_Updates.sql
set CharactersUpdates=All_Characters_Updates.sql
set AuthUpdates=All_Auth_Updates.sql

if exist %CharactersUpdates% del %CharactersUpdates%
if exist %AuthUpdates% del %AuthUpdates%
if exist %WorldUpdates% del %WorldUpdates%

for %%a in (sql\updates\world\*.sql) do (
echo /* >>%WorldUpdates%
echo * %%a >>%WorldUpdates%
echo */ >>%WorldUpdates%
copy/b %WorldUpdates%+"%%a" %WorldUpdates%
echo. >>%WorldUpdates%
echo. >>%WorldUpdates%)

for %%a in (sql\updates\characters\*.sql) do (
echo /* >>%CharactersUpdates%
echo * %%a >>%CharactersUpdates%
echo */ >>%CharactersUpdates%
copy/b %CharactersUpdates%+"%%a" %CharactersUpdates%
echo. >>%CharactersUpdates%
echo. >>%CharactersUpdates%)

for %%a in (sql\updates\auth\*.sql) do (
echo /* >>%AuthUpdates%
echo * %%a >>%AuthUpdates%
echo */ >>%AuthUpdates%
copy/b %AuthUpdates%+"%%a" %AuthUpdates%
echo. >>%AuthUpdates%
echo. >>%AuthUpdates%)

If you want to grab all the .sql files in any folder on your hard drive, put the below code into a batch file as explained above and toss it into the folder where all the .sql files are stored. It will grab every .sql file it sees (except for files in recursive directories) and combine it into a “_MERGED.sql” file (the underscore ensures that the resulting file is at the top of a potentially long list of files). This also shows another method of formatting the text shown between each merged file, and you can pick which one you like best.

Put this in any folder with .sql files to merge them all: (Example Output)

@echo off

set filename=_MERGED.sql

if exist %filename% del %filename%

:: Replace the line below with: for /r %%a in (*.sql) do (
:: to also seek out and merge .sql files in nearby, recursive directories.
for %%a in (*.sql) do (
echo -- -------------------------------------------------------- >>%filename%
echo -- %%a >>%filename%
echo -- -------------------------------------------------------- >>%filename%
copy/b %filename%+"%%a" %filename%
echo. >>%filename%
echo. >>%filename%)

For Linux:

cd into your source/sql/updates directory and choose one of these options:

To combine all updates:

cat world/*.sql > all_world_updates.sql
cat characters/*.sql > all_characters_updates.sql

To combine all updates and immediately import them into your database (remember to use your own username, password, and database names):

for file in world/*.sql; do mysql -u USERNAME -pPASSWORD --database=WORLD < $file; done
for file in characters/*.sql; do mysql -u USERNAME -pPASSWORD --database=CHARACTERS < $file; done

Yazar: Uğur Karal

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.