[Windows/Linux] Combine SQL Updates

New TrinityCore revisions will frequently come with new .sql updates in the Trinitysqlupdates 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:

[ul][li]All_Auth_Updates.sql[/li]
[li]All_Characters_Updates.sql[/li]
[li]All_World_Updates.sql[/li]
[/ul]

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.

[SIZE=18px]For Windows[/SIZE]:

[ol][li]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)[/li]
[li]Drop it into your main Trinity source directory.[/li]
[li]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.[/li]
[/ol]

Put this in your Trinity folder: (Example output)

[SPOILER]

[CODE]

@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%)

[/CODE][/SPOILER]

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)

[CODE]cat world/*.sql > all_world_updates.sql

cat characters/*.sql > all_characters_updates.sql[/CODE]

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

[CODE]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[/CODE]

Don’t forget to √ Like this post if it helps!

[SPOILER]

[CODE]

@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%)[/CODE][/SPOILER]

[SIZE=18px]For Linux[/SIZE]:

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

To combine all updates:

Very useful, I have to try it!

Thank you /emoticons/default_wink.png

linux version of it would be nice /emoticons/default_tongue.png

not all of us uses windows. lol.

Thank you /emoticons/default_biggrin.png

will test this its prob better then having to do in cmd cd to dir and then “copy world.sql worldfull.sql” xD

Thanks!

Please someone test and share the results /emoticons/default_smile.png

under linux, instead of combining all updates files use this simple commands:

[CODE]cd “/path_to_updates_files/”

for i in ls *world*.sql; do mysql -u trinity --password=trinity -f world<$i; done

for i in ls *characters*.sql; do mysql -u trinity --password=trinity -f characters<$i; done[/CODE]

but if u still want to combine them before update the db

use:

[CODE]cat world.sql >world_update.sql

cat characters.sql >characters_update.sql[/CODE]

sorry for my bad english…

Excellent, thank you, Steel. OP updated with Linux instructions.

Checked the version for Windows. There were no errors. A very useful tool. Thanks for sharing.

BR

Broom

thanks for sharing /emoticons/default_smile.png

No need for “ls”, a file or filemask works fine.

Linux: for file in *world*.sql; do mysql --database=world < $file; done

Equivalent command on Windows:

Windows: for /f %a in ('dir /b *world*.sql') do mysql --database=world < %a

Thanks, leak. OP updated.

thanks for share it

seems to be very usefull

suggestion. possible to add in the names of the files as a comment?

Your wish is my command. Try the updated batch script I posted in my OP.

Good idea, too. I like seeing the file names before each section of SQL.

I also added a 2nd way of combining .sql files from any location in your hard drive just by tossing the batch file into the folder where the .sql files are stored, which is much more versatile.

Thanks a lot, very useful tool

good stuff. looks a lot better now. /emoticons/default_smile.png

This was very useful, thank you! /emoticons/default_smile.png

Updated to the new folder format in the latest rev (“sql\updates\world” and “sql\updates\auth_char”).

Indeed, a useful tool for Linux servers, but it has a downside : It overrides manual fixes/patches done by you if the trinity updates contain queries in that area. That’s why it’s recommended to put trinity SQL updates manually ( read them first). Or , use this if you NEVER touch your DB/Core ( Blackbox mode ). Anyway, good job Greg.