Package tk.airshipcraft.commonlib.db
Interface ITableConfiguration
public interface ITableConfiguration
The ITableConfiguration interface specifies the methods that must be implemented
to define the SQL table creation and migration commands for a plugin. It allows
for dynamic table management and supports database schema evolution over time.
Implementations of this interface should provide SQL statements required to create the initial tables and to migrate them to newer versions as the plugin evolves.
Use cases include:
- Initializing fresh installations with the necessary database tables.
- Providing migration paths for existing installations when the database schema changes.
- Allowing for a systematic approach to managing database versions and updates.
Works in conjunction with TableManager
which calls these methods
to actually apply the SQL commands to the database.
- Since:
- 2023-12-27
- Version:
- 1.0.0
- Author:
- notzune
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns the latest version number of the database schema as defined by the plugin.getMigrationCommands
(int currentVersion) Provides a list of SQL commands for migrating the existing tables to a new version.Provides a list of SQL commands for creating the necessary tables for a plugin if they do not exist.
-
Method Details
-
getTableCreationCommands
Provides a list of SQL commands for creating the necessary tables for a plugin if they do not exist. This method is typically called during the plugin startup to ensure that all required tables are present.- Returns:
- a List of SQL command strings for table creation.
-
getMigrationCommands
Provides a list of SQL commands for migrating the existing tables to a new version. This method supports upgrading the database schema without losing data.The migrations should be incremental and idempotent, ensuring they can be run multiple times without causing errors or duplications.
- Parameters:
currentVersion
- the current version of the database schema.- Returns:
- a List of SQL command strings to migrate the database to the latest version.
-
getLatestVersion
int getLatestVersion()Returns the latest version number of the database schema as defined by the plugin. This version number is used in conjunction with migration commands to determine if a migration is necessary.- Returns:
- the latest schema version number.
-