From 491b311cb4454bf15741e88e76fb1c0b54c3fef1 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 17 Sep 2024 23:37:56 -0400 Subject: [PATCH 1/2] Start to add Migrations versions of base interfaces These are important interfaces for userland code. All of the current migrations extend from phinx base classes. I'd like to try updating migrations internals by doing the following changes - [ ] Add SeedInterface and MigrationInterface. - [ ] Add decorator that adapts between phinx and migrations. Manager::getSeeds(), getMigrations() - [ ] Move phinx shims into adapter/decorator - [ ] Update the internals to use migrations interfaces. - [ ] Introduce a new base class that is all migrations - [ ] Provide upgrade tool to update migration classes. If all goes well, we'll have an opt-in path for applications to upgrade to the new namespaces and code before a breaking change where phinx compatibility is removed. --- src/MigrationsInterface.php | 319 ++++++++++++++++++++++++++++++++++++ src/SeedInterface.php | 190 +++++++++++++++++++++ 2 files changed, 509 insertions(+) create mode 100644 src/MigrationsInterface.php create mode 100644 src/SeedInterface.php diff --git a/src/MigrationsInterface.php b/src/MigrationsInterface.php new file mode 100644 index 00000000..046a54db --- /dev/null +++ b/src/MigrationsInterface.php @@ -0,0 +1,319 @@ + $options Options + * @return void + */ + public function createDatabase(string $name, array $options): void; + + /** + * Drop a database. + * + * @param string $name Database Name + * @return void + */ + public function dropDatabase(string $name): void; + + /** + * Creates schema. + * + * This will thrown an error for adapters that do not support schemas. + * + * @param string $name Schema name + * @return void + * @throws \BadMethodCallException + */ + public function createSchema(string $name): void; + + /** + * Drops schema. + * + * This will thrown an error for adapters that do not support schemas. + * + * @param string $name Schema name + * @return void + * @throws \BadMethodCallException + */ + public function dropSchema(string $name): void; + + /** + * Checks to see if a table exists. + * + * @param string $tableName Table name + * @return bool + */ + public function hasTable(string $tableName): bool; + + /** + * Returns an instance of the \Table class. + * + * You can use this class to create and manipulate tables. + * + * @param string $tableName Table name + * @param array $options Options + * @return \Migrations\Db\Table + */ + public function table(string $tableName, array $options): Table; + + /** + * Perform checks on the migration, printing a warning + * if there are potential problems. + * + * @return void + */ + public function preFlightCheck(): void; + + /** + * Perform checks on the migration after completion + * + * Right now, the only check is whether all changes were committed + * + * @return void + */ + public function postFlightCheck(): void; + + /** + * Checks to see if the migration should be executed. + * + * Returns true by default. + * + * You can use this to prevent a migration from executing. + * + * @return bool + */ + public function shouldExecute(): bool; +} diff --git a/src/SeedInterface.php b/src/SeedInterface.php new file mode 100644 index 00000000..f4bb8d1c --- /dev/null +++ b/src/SeedInterface.php @@ -0,0 +1,190 @@ +\Table class. + * + * You can use this class to create and manipulate tables. + * + * @param string $tableName Table name + * @param array $options Options + * @return \Migrations\Db\Table + */ + public function table(string $tableName, array $options): Table; + + /** + * Checks to see if the seed should be executed. + * + * Returns true by default. + * + * You can use this to prevent a seed from executing. + * + * @return bool + */ + public function shouldExecute(): bool; +} From fe677f45082118690b698ae574a22cad2d067ab2 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 18 Sep 2024 10:08:13 -0400 Subject: [PATCH 2/2] Fix file name --- src/{MigrationsInterface.php => MigrationInterface.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{MigrationsInterface.php => MigrationInterface.php} (100%) diff --git a/src/MigrationsInterface.php b/src/MigrationInterface.php similarity index 100% rename from src/MigrationsInterface.php rename to src/MigrationInterface.php