diff --git a/.env.dist b/.env.dist index db3041d..e191c6e 100644 --- a/.env.dist +++ b/.env.dist @@ -1,4 +1,4 @@ -ENV=dev +APP_ENV=develope USERMAP_UID=1000 USERMAP_GID=984 MYSQL_USER=dev diff --git a/bin/migrations.php b/bin/migrations.php old mode 100644 new mode 100755 index 45a1f6c..bea2a60 --- a/bin/migrations.php +++ b/bin/migrations.php @@ -1,5 +1,5 @@ #!/usr/bin/env php -setCustomTemplate(__DIR__ . '/../config/migrations/migrations.template.tpl'); +$configuration->setCustomTemplate(__DIR__ . '/../config/migrations.template.tpl'); $configuration->addMigrationsDirectory('Migrations', $config['migrations_paths']['Migrations']); $configuration->setAllOrNothing($config['all_or_nothing']); @@ -27,6 +31,7 @@ $configuration->setTransactional($config['transactional']); $configuration->setMigrationOrganization($config['organize_migrations']); + $storageConfiguration = new TableMetadataStorageConfiguration(); $storageConfiguration->setTableName($config['table_storage']['table_name']); $storageConfiguration->setVersionColumnName($config['table_storage']['version_column_name']); @@ -34,6 +39,7 @@ $storageConfiguration->setExecutedAtColumnName($config['table_storage']['executed_at_column_name']); $storageConfiguration->setExecutionTimeColumnName($config['table_storage']['execution_time_column_name']); + $configuration->setMetadataStorageConfiguration($storageConfiguration); $container = require_once __DIR__ . '/../config/container.php'; diff --git a/config/autoload/database.develope.php b/config/autoload/database.develope.php new file mode 100644 index 0000000..fd89376 --- /dev/null +++ b/config/autoload/database.develope.php @@ -0,0 +1,20 @@ + [ + 'driver' => 'mysql', + 'host' => 'stormannsgal-mariadb', + 'port' => '3306', + 'user' => 'dev', + 'password' => 'dev', + 'dbname' => 'db', + 'charset' => 'utf8mb4', + 'defaultTableOptions' => [ + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_general_ci', + 'engine' => 'InnoDB', + ], + 'error' => PDO::ERRMODE_EXCEPTION, + 'emulate_prepares' => false, + ] +]; diff --git a/config/autoload/database.global.php.dist b/config/autoload/database.global.php.dist index f7f54d6..1152a4f 100644 --- a/config/autoload/database.global.php.dist +++ b/config/autoload/database.global.php.dist @@ -2,11 +2,18 @@ return [ 'database' => [ - 'host' => 'mariadb', - 'port' => '3306', - 'user' => 'dev', - 'password' => 'dev', - 'dbname' => 'db', + 'driver' => 'driver', + 'host' => 'host', + 'port' => 'port', + 'user' => 'user', + 'password' => 'password', + 'dbname' => 'dbname', + 'charset' => 'utf8mb4', + 'defaultTableOptions' => [ + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_general_ci', + 'engine' => 'InnoDB', + ], 'error' => PDO::ERRMODE_EXCEPTION, 'emulate_prepares' => false, ] diff --git a/config/autoload/migrations.develope.php b/config/autoload/migrations.develope.php new file mode 100644 index 0000000..0626d10 --- /dev/null +++ b/config/autoload/migrations.develope.php @@ -0,0 +1,22 @@ + [ + 'table_storage' => [ + 'table_name' => 'MigrationVersions', + 'version_column_name' => 'version', + 'version_column_length' => 192, + 'executed_at_column_name' => 'executedAt', + 'execution_time_column_name' => 'executionTime', + ], + + 'migrations_paths' => [ + 'Migrations' => __DIR__ . '/../../database/migrations', + ], + + 'all_or_nothing' => true, + 'transactional' => true, + 'check_database_platform' => true, + 'organize_migrations' => 'none', + ], +]; diff --git a/config/autoload/migrations.global.php b/config/autoload/migrations.global.php new file mode 100644 index 0000000..0626d10 --- /dev/null +++ b/config/autoload/migrations.global.php @@ -0,0 +1,22 @@ + [ + 'table_storage' => [ + 'table_name' => 'MigrationVersions', + 'version_column_name' => 'version', + 'version_column_length' => 192, + 'executed_at_column_name' => 'executedAt', + 'execution_time_column_name' => 'executionTime', + ], + + 'migrations_paths' => [ + 'Migrations' => __DIR__ . '/../../database/migrations', + ], + + 'all_or_nothing' => true, + 'transactional' => true, + 'check_database_platform' => true, + 'organize_migrations' => 'none', + ], +]; diff --git a/config/config.php b/config/config.php index bf009a7..cc80184 100644 --- a/config/config.php +++ b/config/config.php @@ -14,6 +14,7 @@ ]; $aggregator = new ConfigAggregator([ + \Laminas\Log\ConfigProvider::class, \Mezzio\Tooling\ConfigProvider::class, \Mezzio\Helper\ConfigProvider::class, \Mezzio\Router\FastRouteRouter\ConfigProvider::class, @@ -41,9 +42,12 @@ class_exists(\Mezzio\Swoole\ConfigProvider::class) // - `*.global.php` // - `local.php` // - `*.local.php` - new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php.dist'), - - new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'), + new PhpFileProvider( + realpath(__DIR__) . sprintf( + '/autoload/{,*.}{global,local,%s}.php', + getenv('APP_ENV') ?: 'production' + ) + ), // Load development config if it exists new PhpFileProvider(realpath(__DIR__) . '/development.config.php'), diff --git a/config/migrations/migrations.template.tpl b/config/migrations.template.tpl similarity index 100% rename from config/migrations/migrations.template.tpl rename to config/migrations.template.tpl diff --git a/config/migrations/migrations.db.php b/config/migrations/migrations.db.php deleted file mode 100644 index 58092ea..0000000 --- a/config/migrations/migrations.db.php +++ /dev/null @@ -1,16 +0,0 @@ - $db['dbname'], - 'user' => $db['user'], - 'password' => $db['password'], - 'host' => $db['host'], - 'driver' => 'pdo_mysql', - 'charset' => 'utf8mb4', -]; diff --git a/config/migrations/migrations.setting.php b/config/migrations/migrations.setting.php deleted file mode 100644 index 0987ab3..0000000 --- a/config/migrations/migrations.setting.php +++ /dev/null @@ -1,20 +0,0 @@ - [ - 'table_name' => 'MigrationVersions', - 'version_column_name' => 'version', - 'version_column_length' => 192, - 'executed_at_column_name' => 'executedAt', - 'execution_time_column_name' => 'executionTime', - ], - - 'migrations_paths' => [ - 'Migrations' => __DIR__ . '/../../database/migrations', - ], - - 'all_or_nothing' => true, - 'transactional' => true, - 'check_database_platform' => true, - 'organize_migrations' => 'none', -]; diff --git a/docker-compose.yml b/docker-compose.yml index 9172d30..a354488 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,13 +13,14 @@ services: container_name: php user: "${USERMAP_UID:-1000}:${USERMAP_GID:-1000}" image: "ghcr.io/ownhackathon/hackathon-api-php:latest" + env_file: ".env" volumes: - ./:/var/www/html - ./docker/php/php-ini-overrides.ini:/usr/local/etc/php/conf.d/extra.ini database: image: mariadb:${MARIADB_VERSION:-latest} - container_name: mariadb + container_name: stormannsgal-mariadb ports: - "${MYSQL_PUBLIC_PORT:-3306}:3306" environment: diff --git a/src/Core/Factory/DatabaseFactory.php b/src/Core/Factory/DatabaseFactory.php index 521fcf1..513561d 100644 --- a/src/Core/Factory/DatabaseFactory.php +++ b/src/Core/Factory/DatabaseFactory.php @@ -15,8 +15,7 @@ class DatabaseFactory */ public function __invoke(ContainerInterface $container): PDO { - $settings = $container->get('config'); - $settings = $settings['database']; + $settings = $container->get('config')['database']; $dsn = $settings['driver'] === 'mysql' ? 'mysql:dbname=' . $settings['dbname'] . ';host=' . $settings['host'] . ';port=' . $settings['port'] diff --git a/tests/CoreTest/Factory/DatabaseFactoryTest.php b/tests/CoreTest/Factory/DatabaseFactoryTest.php index 82655a2..5e89a1c 100644 --- a/tests/CoreTest/Factory/DatabaseFactoryTest.php +++ b/tests/CoreTest/Factory/DatabaseFactoryTest.php @@ -22,6 +22,7 @@ public function testThrowPDOException(): void $config = [ 'database' => [ + 'driver' => 'mysql', 'user' => 'testUser', 'password' => 'testPassword', 'host' => 'https//example.com',