First Commit
This commit is contained in:
132
apps/VersionUpdater/VersionUpdater.ps1
Normal file
132
apps/VersionUpdater/VersionUpdater.ps1
Normal file
@@ -0,0 +1,132 @@
|
||||
# Get the directory to acore.json
|
||||
$scriptDirectory = $PSScriptRoot
|
||||
$relativePath = "..\.."
|
||||
$combinedPath = Join-Path -Path $scriptDirectory -ChildPath $relativePath
|
||||
$fullPath = Resolve-Path -Path $combinedPath
|
||||
$jsonFilePath = "$fullPath\acore.json"
|
||||
# Get the directory for SQL update
|
||||
$relativePathDbWorldUpdate = "..\..\data\sql\updates\db_world"
|
||||
$combinedPathDbWorldUpdate = Join-Path -Path $scriptDirectory -ChildPath $relativePathDbWorldUpdate
|
||||
$fullPathDbWorldUpdate = Resolve-Path -Path $combinedPathDbWorldUpdate
|
||||
|
||||
Write-Host " ___ _ _ ___ "
|
||||
Write-Host "/ \ ___ ___ _ _ ___ | |_ | |_ / __| ___ _ _ ___ "
|
||||
Write-Host "| - ||_ // -_)| '_|/ _ \| _|| \ | (__ / _ \| '_|/ -_)"
|
||||
Write-Host "|_|_|/__|\___||_| \___/ \__||_||_| \___|\___/|_| \___|"
|
||||
Write-Host "AzerothCore 3.3.5a - www.azerothcore.org"
|
||||
Write-Host ""
|
||||
Write-Host "Welcome to the AzerothCore Version Updater for database squashes!"
|
||||
Write-Host ""
|
||||
Write-Host "You have configured:"
|
||||
Write-Host "acore.json Path: '$jsonFilePath'"
|
||||
Write-Host "World SQL Updates path: '$fullPathDbWorldUpdate'"
|
||||
Write-Host ""
|
||||
Write-Host "Make sure you read the entire process before you continue."
|
||||
Write-Host "https://github.com/azerothcore/azerothcore-wotlk/blob/master/data/sql/base/database-squash.md"
|
||||
Write-Host "https://github.com/azerothcore/azerothcore-wotlk/blob/master/apps/VersionUpdater/versionupdater.md"
|
||||
Write-Host ""
|
||||
|
||||
# Check if the user wants to continue using the tool
|
||||
do {
|
||||
$confirmation = Read-Host "Do you want to continue using the tool? (Y/N)"
|
||||
|
||||
if ($confirmation -eq 'Y' -or $confirmation -eq 'y') {
|
||||
# Continue the script
|
||||
Write-Host "AzerothCore Version Updater starts."
|
||||
Write-Host ""
|
||||
$continue = $true
|
||||
}
|
||||
elseif ($confirmation -eq 'N' -or $confirmation -eq 'n') {
|
||||
# Exit the script
|
||||
Write-Host "Exiting the AzerothCore Version Updater."
|
||||
exit
|
||||
}
|
||||
else {
|
||||
Write-Host "Invalid input. Please enter Y or N."
|
||||
$continue = $null
|
||||
}
|
||||
} while ($continue -eq $null)
|
||||
|
||||
# Read the JSON file and convert it to a PowerShell object
|
||||
$jsonContent = Get-Content -Path $jsonFilePath | ConvertFrom-Json
|
||||
|
||||
# Get the current version
|
||||
$currentVersion = $jsonContent.version
|
||||
|
||||
# Match version components (major.minor.patch and optional suffix like -dev or -alpha)
|
||||
if ($currentVersion -match '(\d+)\.(\d+)\.(\d+)(-.*)?') {
|
||||
$major = $matches[1]
|
||||
$minor = $matches[2]
|
||||
$patch = $matches[3]
|
||||
$suffix = $matches[4]
|
||||
|
||||
# Increment the major version
|
||||
$major = [int]$major + 1
|
||||
|
||||
# Reset minor and patch version to 0 (if incrementing major)
|
||||
$minor = 0
|
||||
$patch = 0
|
||||
|
||||
# Reassemble the version with the suffix if it exists
|
||||
$newVersion = "$major.$minor.$patch$suffix"
|
||||
|
||||
# Update the version in the JSON object
|
||||
$jsonContent.version = $newVersion
|
||||
} else {
|
||||
Write-Host "Unknown error in $jsonFilePath. Exiting."
|
||||
exit
|
||||
}
|
||||
|
||||
# Convert the updated object back to JSON format
|
||||
$newJsonContent = $jsonContent | ConvertTo-Json -Depth 3
|
||||
|
||||
# Write the updated content back to the file
|
||||
$newJsonContent | Set-Content -Path $jsonFilePath
|
||||
|
||||
Write-Host "acore.json version updated to $newVersion"
|
||||
|
||||
# Create the SQL Version update file.
|
||||
# Get today's date in the format YYYY_MM_DD
|
||||
$today = Get-Date -Format "yyyy_MM_dd"
|
||||
|
||||
# Get the list of files in the directory that match the pattern "YYYY_MM_DD_versionNumber.sql"
|
||||
$existingFiles = Get-ChildItem -Path $fullPathDbWorldUpdate -Filter "$today*_*.sql"
|
||||
|
||||
# If no files exist for today, start with version number 00
|
||||
if ($existingFiles.Count -eq 0) {
|
||||
[int]$newVersionNumber = 0
|
||||
} else {
|
||||
# Extract the version number from the existing files (e.g., YYYY_MM_DD_versionNumber.sql)
|
||||
$maxVersionNumber = $existingFiles | ForEach-Object {
|
||||
if ($_ -match "$today_(\d{2})\.sql") {
|
||||
[int]$matches[1]
|
||||
}
|
||||
} | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum
|
||||
|
||||
# Increment the version number by 1
|
||||
[int]$newVersionNumber = $maxVersionNumber + 1
|
||||
}
|
||||
|
||||
# Format the new version number as a two-digit number (e.g., 01, 02, etc.)
|
||||
$formattedVersionNumber = $newVersionNumber.ToString("D2")
|
||||
|
||||
# Define the new filename using the date and incremented version number
|
||||
$newFileName = "$today" + "_$formattedVersionNumber.sql"
|
||||
$newFilePath = Join-Path -Path $fullPathDbWorldUpdate -ChildPath $newFileName
|
||||
|
||||
# Define the SQL content to write to the file
|
||||
$tableName = '`version`'
|
||||
$db_version = '`db_version`'
|
||||
$db_version_content = "'ACDB 335.$major-dev'"
|
||||
$cache_id = '`cache_id`'
|
||||
$sqlContent = "UPDATE $tableName SET $db_version=$db_version_content, $cache_id=$major LIMIT 1;"
|
||||
|
||||
# Write the content to the new SQL file
|
||||
$sqlContent | Set-Content -Path $newFilePath
|
||||
|
||||
Write-Host "SQL file created: $newFilePath"
|
||||
Write-Host "SQL content: $sqlContent"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Version Updater completed."
|
||||
Write-Host "Have a nice day :)"
|
||||
53
apps/VersionUpdater/versionupdater.md
Normal file
53
apps/VersionUpdater/versionupdater.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# The AzerothCore Version Updater for Database Squashes
|
||||
|
||||
> [!CAUTION]
|
||||
> These steps are only for project maintainers who intend to update base files.
|
||||
|
||||
## Description of the tool
|
||||
|
||||
This tool updates the version in DB and acore.json automatically. Hence, it must run from this directory.
|
||||
|
||||
This is how it works step-by-step:
|
||||
|
||||
1. Check that all paths look correct.
|
||||
2. Accept to continue using the tool.
|
||||
3. The tool will update the acore.json file and increment it by 1.
|
||||
4. The tool will create a file with the proper UPDATE for world database in `..\..\data\sql\updates\db_world`.
|
||||
|
||||
## Run the tool
|
||||
|
||||
> [!IMPORTANT]
|
||||
> This tool CAN NOT be moved outside this directory. If you do it will create files in the wrong places.
|
||||
|
||||
1. If you haven't run PowerShell scripts before, you'll need to adjust the execution policy.
|
||||
|
||||
- Open PowerShell as an Administrator.
|
||||
- Run the following command to allow running scripts:
|
||||
```ps
|
||||
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
```
|
||||
- This allows scripts to run on your system, but they need to be locally created or downloaded from trusted sources.
|
||||
|
||||
2. Open PowerShell (PS)
|
||||
|
||||
- Press Win + X and select Windows PowerShell (Admin) / Terminal (Admin)
|
||||
|
||||
3. Navigate to the script
|
||||
|
||||
- In PS, use the `cd` command to change the directory
|
||||
```ps
|
||||
cd "C:\AzerothCore\apps\VersionUpdater"
|
||||
```
|
||||
|
||||
4. Run the script
|
||||
|
||||
- In PS, run the script
|
||||
```ps
|
||||
.\VersionUpdater.ps1
|
||||
```
|
||||
|
||||
5. Follow the instructions given by the tool.
|
||||
|
||||
6. Now refer back to the database-squash.md instructions. (Located in ..\..\data\sql\base\)
|
||||
|
||||
Completed :)
|
||||
Reference in New Issue
Block a user