diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0f4fa..8ed95ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard. +## [3.1.3] 2025-10-08 + +* Fix - Fix the `get_current_schema` method to cache the schema of each implementation. + +[3.1.3]: https://github.com/stellarwp/schema/releases/tag/3.1.3 + ## [3.1.2] 2025-10-02 * Fix - Fix the `update_many` method to properly check if the transaction was successful. diff --git a/src/Schema/Tables/Contracts/Table.php b/src/Schema/Tables/Contracts/Table.php index b030dd7..1a1ca0e 100644 --- a/src/Schema/Tables/Contracts/Table.php +++ b/src/Schema/Tables/Contracts/Table.php @@ -157,10 +157,10 @@ public static function get_searchable_columns(): Column_Collection { * @throws RuntimeException If the current schema version is not found in the schema history. */ public static function get_current_schema(): Table_Schema_Interface { - static $current_schema = null; + static $current_schema = []; - if ( null !== $current_schema ) { - return $current_schema; + if ( ! empty( $current_schema[ static::class ] ) ) { + return $current_schema[ static::class ]; } $history = static::get_schema_history(); @@ -169,9 +169,9 @@ public static function get_current_schema(): Table_Schema_Interface { throw new RuntimeException( 'The current schema version is not found in the schema history.' ); } - $current_schema = $history[ static::SCHEMA_VERSION ](); + $current_schema[ static::class ] = $history[ static::SCHEMA_VERSION ](); - return $current_schema; + return $current_schema[ static::class ]; } /**