Skip to content

Commit

Permalink
enable automatic database updates (#16)
Browse files Browse the repository at this point in the history
* fix auth database updater

* update genrev

* fix worldserver database updates
  • Loading branch information
jasongdove authored Sep 22, 2024
1 parent 56d191d commit 70cc49e
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 110 deletions.
110 changes: 53 additions & 57 deletions cmake/genrev.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2008-2012 Trinity <http://www.trinitycore.org/>
# This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
Expand All @@ -8,75 +8,71 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

include(${CMAKE_SOURCE_DIR}/cmake/macros/EnsureVersion.cmake)
# User has manually chosen to ignore the git-tests, so throw them a warning.
# This is done EACH compile so they can be alerted about the consequences.

set(_REQUIRED_GIT_VERSION "1.7")

find_program(_GIT_EXEC
NAMES
git git.cmd
HINTS
ENV PATH
DOC "git installation path"
)

if(_GIT_EXEC)
execute_process(
COMMAND "${_GIT_EXEC}" --version
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE _GIT_VERSION
ERROR_QUIET
)

# make sure we're using minimum the required version of git, so the "dirty-testing" will work properly
ensure_version( "${_REQUIRED_GIT_VERSION}" "${_GIT_VERSION}" _GIT_VERSION_OK)
if(NOT BUILDDIR)
# Workaround for funny MSVC behaviour - this segment is only used when using cmake gui
set(BUILDDIR ${CMAKE_BINARY_DIR})
endif()

if(_GIT_VERSION_OK)
execute_process(
COMMAND "${_GIT_EXEC}" describe --tags --dirty --long --abbrev=10
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE rev_info
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
execute_process(
COMMAND "${_GIT_EXEC}" show -s --format=%ci
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE rev_date
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(WITHOUT_GIT)
set(rev_date "1970-01-01 00:00:00 +0000")
set(rev_hash "unknown")
set(rev_branch "Archived")
else()
message("")
message(STATUS "WARNING - Missing or outdated git - did you forget to install a recent version?")
message(STATUS "WARNING - Observe that for revision hash/date to work you need at least version ${_REQUIRED_GIT_VERSION}")
endif()
if(GIT_EXECUTABLE)
# Create a revision-string that we can use
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --long --match init --dirty=+ --abbrev=12
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE rev_info
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)

# Last minute check - ensure that we have a proper revision
# If everything above fails (means the user has erased the git revision control directory or removed the origin/HEAD tag)
if(NOT rev_info)
# No valid ways available to find/set the revision/hash, so let's force some defaults
message(STATUS "WARNING - Missing repository tags - you may need to pull tags with git fetch -t")
message(STATUS "WARNING - Continuing anyway - note that the versionstring will be set to 0000-00-00 00:00:00 (Archived)")
set(rev_date "0000-00-00 00:00:00 +0000")
set(rev_hash "Archived")
else()
# Extract information required to build a proper versionstring
string(REGEX REPLACE init-|[0-9]+-g "" rev_hash ${rev_info})
endif()
# And grab the commits timestamp
execute_process(
COMMAND "${GIT_EXECUTABLE}" show -s --format=%ci
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE rev_date
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)

# Its not set during initial run
if(NOT BUILDDIR)
set(BUILDDIR ${CMAKE_BINARY_DIR})
# Also retrieve branch name
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE rev_branch
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()

# Last minute check - ensure that we have a proper revision
# If everything above fails (means the user has erased the git revision control directory or removed the origin/HEAD tag)
if(NOT rev_info)
# No valid ways available to find/set the revision/hash, so let's force some defaults
message(STATUS "
Could not find a proper repository signature (hash) - you may need to pull tags with git fetch -t
Continuing anyway - note that the versionstring will be set to \"unknown 1970-01-01 00:00:00 (Archived)\"")
set(rev_date "1970-01-01 00:00:00 +0000")
set(rev_hash "unknown")
set(rev_branch "Archived")
else()
# Extract information required to build a proper versionstring
string(REGEX REPLACE init-|[0-9]+-g "" rev_hash ${rev_info})
endif()
endif()

# Create the actual revision_data.h file from the above params
if(NOT "${rev_hash_cached}" MATCHES "${rev_hash}")
if(NOT "${rev_hash_cached}" MATCHES "${rev_hash}" OR NOT "${rev_branch_cached}" MATCHES "${rev_branch}" OR NOT EXISTS "${BUILDDIR}/revision_data.h")
configure_file(
"${CMAKE_SOURCE_DIR}/revision_data.h.in.cmake"
"${BUILDDIR}/revision_data.h"
@ONLY
)
set(rev_hash_cached "${rev_hash}" CACHE INTERNAL "Cached commit-hash")
set(rev_branch_cached "${rev_branch}" CACHE INTERNAL "Cached branch name")
endif()
14 changes: 8 additions & 6 deletions cmake/macros/FindMySQL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ if( UNIX )
if( MYSQL_CONFIG )
message(STATUS "Using mysql-config: ${MYSQL_CONFIG}")
# set INCLUDE_DIR
exec_program(${MYSQL_CONFIG}
ARGS --include
OUTPUT_VARIABLE MY_TMP
execute_process(
COMMAND "${MYSQL_CONFIG}" --include
OUTPUT_VARIABLE MY_TMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)

string(REGEX REPLACE "-I([^ ]*)( .*)?" "\\1" MY_TMP "${MY_TMP}")
set(MYSQL_ADD_INCLUDE_PATH ${MY_TMP} CACHE FILEPATH INTERNAL)
#message("[DEBUG] MYSQL ADD_INCLUDE_PATH : ${MYSQL_ADD_INCLUDE_PATH}")
# set LIBRARY_DIR
exec_program(${MYSQL_CONFIG}
ARGS --libs_r
OUTPUT_VARIABLE MY_TMP
execute_process(
COMMAND "${MYSQL_CONFIG}" --libs_r
OUTPUT_VARIABLE MY_TMP
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(MYSQL_ADD_LIBRARIES "")
string(REGEX MATCHALL "-l[^ ]*" MYSQL_LIB_LIST "${MY_TMP}")
Expand Down
8 changes: 4 additions & 4 deletions revision_data.h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#define _SOURCE_DIRECTORY R"(@CMAKE_SOURCE_DIR@)"
#define _BUILD_DIRECTORY R"(@BUILDDIR@)"
#define _MYSQL_EXECUTABLE R"(@MYSQL_EXECUTABLE@)"
#define _FULL_DATABASE "LegionCore_world"
#define _HOTFIXES_DATABASE "LegionCore_hotfixes"
#define _FULL_DATABASE "LegionCore_world_735.26972_2020_04_25.sql"
#define _HOTFIXES_DATABASE "LegionCore_hotfixes_735.26972_2020_04_03.sql"
#define VER_COMPANYNAME_STR "LegionCore"
#define VER_LEGALCOPYRIGHT_STR "(c)2020 LegionCore"
#define VER_LEGALCOPYRIGHT_STR "(c)2024 LegionCore"
#define VER_FILEVERSION 0,0,0
#define VER_FILEVERSION_STR "LegionCore 2020-04-25"
#define VER_FILEVERSION_STR "LegionCore 2024-09-22"
#define VER_PRODUCTVERSION VER_FILEVERSION
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
#endif // __REVISION_DATA_H__
131 changes: 88 additions & 43 deletions sql/base/auth_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -524,36 +524,36 @@ DROP TABLE IF EXISTS `store_category_locales`;

CREATE TABLE `store_category_locales` (
`category` int(11) NOT NULL DEFAULT '0',
`name_us` varchar(255) NOT NULL DEFAULT '',
`name_gb` varchar(255) NOT NULL DEFAULT '',
`name_kr` varchar(255) NOT NULL DEFAULT '',
`name_fr` varchar(255) NOT NULL DEFAULT '',
`name_de` varchar(255) NOT NULL DEFAULT '',
`name_cn` varchar(255) NOT NULL DEFAULT '',
`name_tw` varchar(255) NOT NULL DEFAULT '',
`name_es` varchar(255) NOT NULL DEFAULT '',
`name_mx` varchar(255) NOT NULL DEFAULT '',
`name_ru` varchar(255) NOT NULL DEFAULT '',
`name_pt` varchar(255) NOT NULL DEFAULT '',
`name_br` varchar(255) NOT NULL DEFAULT '',
`name_it` varchar(255) NOT NULL DEFAULT '',
`name_ua` varchar(255) NOT NULL DEFAULT '',
`description_us` varchar(255) NOT NULL DEFAULT '',
`description_gb` varchar(255) NOT NULL DEFAULT '',
`description_kr` varchar(255) NOT NULL DEFAULT '',
`description_fr` varchar(255) NOT NULL DEFAULT '',
`description_de` varchar(255) NOT NULL DEFAULT '',
`description_cn` varchar(255) NOT NULL DEFAULT '',
`description_tw` varchar(255) NOT NULL DEFAULT '',
`description_es` varchar(255) NOT NULL DEFAULT '',
`description_mx` varchar(255) NOT NULL DEFAULT '',
`description_ru` varchar(255) NOT NULL DEFAULT '',
`description_pt` varchar(255) NOT NULL DEFAULT '',
`description_br` varchar(255) NOT NULL DEFAULT '',
`description_it` varchar(255) NOT NULL DEFAULT '',
`description_ua` varchar(255) NOT NULL DEFAULT '',
`name_us` varchar(32) NOT NULL DEFAULT '',
`name_gb` varchar(32) NOT NULL DEFAULT '',
`name_kr` varchar(32) NOT NULL DEFAULT '',
`name_fr` varchar(32) NOT NULL DEFAULT '',
`name_de` varchar(32) NOT NULL DEFAULT '',
`name_cn` varchar(32) NOT NULL DEFAULT '',
`name_tw` varchar(32) NOT NULL DEFAULT '',
`name_es` varchar(32) NOT NULL DEFAULT '',
`name_mx` varchar(32) NOT NULL DEFAULT '',
`name_ru` varchar(32) NOT NULL DEFAULT '',
`name_pt` varchar(32) NOT NULL DEFAULT '',
`name_br` varchar(32) NOT NULL DEFAULT '',
`name_it` varchar(32) NOT NULL DEFAULT '',
`name_ua` varchar(32) NOT NULL DEFAULT '',
`description_us` varchar(128) NOT NULL DEFAULT '',
`description_gb` varchar(128) NOT NULL DEFAULT '',
`description_kr` varchar(128) NOT NULL DEFAULT '',
`description_fr` varchar(128) NOT NULL DEFAULT '',
`description_de` varchar(128) NOT NULL DEFAULT '',
`description_cn` varchar(128) NOT NULL DEFAULT '',
`description_tw` varchar(128) NOT NULL DEFAULT '',
`description_es` varchar(128) NOT NULL DEFAULT '',
`description_mx` varchar(128) NOT NULL DEFAULT '',
`description_ru` varchar(128) NOT NULL DEFAULT '',
`description_pt` varchar(128) NOT NULL DEFAULT '',
`description_br` varchar(128) NOT NULL DEFAULT '',
`description_it` varchar(128) NOT NULL DEFAULT '',
`description_ua` varchar(128) NOT NULL DEFAULT '',
PRIMARY KEY (`category`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT ;

/*Data for the table `store_category_locales` */

Expand Down Expand Up @@ -654,20 +654,20 @@ DROP TABLE IF EXISTS `store_product_locales`;
CREATE TABLE `store_product_locales` (
`product` int(11) NOT NULL DEFAULT '0',
`type` smallint(10) NOT NULL DEFAULT '0',
`us` varchar(255) NOT NULL DEFAULT '',
`gb` varchar(255) NOT NULL DEFAULT '',
`kr` varchar(255) NOT NULL DEFAULT '',
`fr` varchar(255) NOT NULL DEFAULT '',
`de` varchar(255) NOT NULL DEFAULT '',
`cn` varchar(255) NOT NULL DEFAULT '',
`tw` varchar(255) NOT NULL DEFAULT '',
`es` varchar(255) NOT NULL DEFAULT '',
`mx` varchar(255) NOT NULL DEFAULT '',
`ru` varchar(255) NOT NULL DEFAULT '',
`pt` varchar(255) NOT NULL DEFAULT '',
`br` varchar(255) NOT NULL DEFAULT '',
`it` varchar(255) NOT NULL DEFAULT '',
`ua` varchar(255) NOT NULL DEFAULT '',
`us` varchar(128) NOT NULL DEFAULT '',
`gb` varchar(128) NOT NULL DEFAULT '',
`kr` varchar(128) NOT NULL DEFAULT '',
`fr` varchar(128) NOT NULL DEFAULT '',
`de` varchar(128) NOT NULL DEFAULT '',
`cn` varchar(128) NOT NULL DEFAULT '',
`tw` varchar(128) NOT NULL DEFAULT '',
`es` varchar(128) NOT NULL DEFAULT '',
`mx` varchar(128) NOT NULL DEFAULT '',
`ru` varchar(128) NOT NULL DEFAULT '',
`pt` varchar(128) NOT NULL DEFAULT '',
`br` varchar(128) NOT NULL DEFAULT '',
`it` varchar(128) NOT NULL DEFAULT '',
`ua` varchar(128) NOT NULL DEFAULT '',
PRIMARY KEY (`product`,`type`) USING BTREE,
UNIQUE KEY `unique` (`product`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
Expand Down Expand Up @@ -825,6 +825,51 @@ CREATE TABLE `transferts_logs` (

/*Data for the table `transferts_logs` */

--
-- Table structure for table `updates`
--

DROP TABLE IF EXISTS `updates`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `updates` (
`name` varchar(200) NOT NULL COMMENT 'filename with extension of the update.',
`hash` char(40) DEFAULT '' COMMENT 'sha1 hash of the sql file.',
`state` enum('RELEASED','ARCHIVED') NOT NULL DEFAULT 'RELEASED' COMMENT 'defines if an update is released or archived.',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp when the query was applied.',
`speed` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'time the query takes to apply in ms.',
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of all applied updates in this database.';
/*!40101 SET character_set_client = @saved_cs_client */;

--

--
-- Table structure for table `updates_include`
--

DROP TABLE IF EXISTS `updates_include`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `updates_include` (
`path` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'directory to include. $ means relative to the source directory.',
`state` enum('RELEASED','ARCHIVED') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'RELEASED' COMMENT 'defines if the directory contains released or archived updates.',
PRIMARY KEY (`path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='List of directories where we want to include sql updates.';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `updates_include`
--

LOCK TABLES `updates_include` WRITE;
/*!40000 ALTER TABLE `updates_include` DISABLE KEYS */;
INSERT INTO `updates_include` VALUES
('$/sql/old/auth','ARCHIVED'),
('$/sql/updates/auth','RELEASED');
/*!40000 ALTER TABLE `updates_include` ENABLE KEYS */;
UNLOCK TABLES;

/*Table structure for table `uptime` */

DROP TABLE IF EXISTS `uptime`;
Expand Down
45 changes: 45 additions & 0 deletions sql/base/characters_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,51 @@ CREATE TABLE `reserved_name` (

/*Data for the table `reserved_name` */

--
-- Table structure for table `updates`
--

DROP TABLE IF EXISTS `updates`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `updates` (
`name` varchar(200) NOT NULL COMMENT 'filename with extension of the update.',
`hash` char(40) DEFAULT '' COMMENT 'sha1 hash of the sql file.',
`state` enum('RELEASED','ARCHIVED') NOT NULL DEFAULT 'RELEASED' COMMENT 'defines if an update is released or archived.',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp when the query was applied.',
`speed` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'time the query takes to apply in ms.',
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='List of all applied updates in this database.';
/*!40101 SET character_set_client = @saved_cs_client */;

--

--
-- Table structure for table `updates_include`
--

DROP TABLE IF EXISTS `updates_include`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `updates_include` (
`path` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'directory to include. $ means relative to the source directory.',
`state` enum('RELEASED','ARCHIVED') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'RELEASED' COMMENT 'defines if the directory contains released or archived updates.',
PRIMARY KEY (`path`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='List of directories where we want to include sql updates.';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `updates_include`
--

LOCK TABLES `updates_include` WRITE;
/*!40000 ALTER TABLE `updates_include` DISABLE KEYS */;
INSERT INTO `updates_include` VALUES
('$/sql/old/characters','ARCHIVED'),
('$/sql/updates/characters','RELEASED');
/*!40000 ALTER TABLE `updates_include` ENABLE KEYS */;
UNLOCK TABLES;

/*Table structure for table `version` */

DROP TABLE IF EXISTS `version`;
Expand Down
Empty file added sql/old/.gitkeep
Empty file.
Empty file added sql/old/auth/.gitkeep
Empty file.
Empty file added sql/old/characters/.gitkeep
Empty file.
Empty file added sql/old/hotfixes/.gitkeep
Empty file.
Empty file added sql/old/world/.gitkeep
Empty file.
Loading

0 comments on commit 70cc49e

Please sign in to comment.