feat: M2 database migration runner with Phinx and initial schema
This commit is contained in:
1 parent
d3e8cf8fae
commit
93d991703c
20 files changed
+2000
-14
No files matched your search
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MeshVault\Tests\Integration;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MigrationTest extends TestCase
|
||||
{
|
||||
/** @var \PDO|null */
|
||||
private static ?\PDO $pdo = null;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$host = getenv('MESHVAULT_DB_HOST') ?: 'db';
|
||||
$port = (int) (getenv('MESHVAULT_DB_PORT') ?: 5432);
|
||||
$name = getenv('MESHVAULT_DB_NAME') ?: 'meshvault';
|
||||
$user = getenv('MESHVAULT_DB_USER') ?: 'meshvault';
|
||||
$pass = getenv('MESHVAULT_DB_PASSWORD') ?: '';
|
||||
|
||||
if ($pass === '') {
|
||||
self::markTestSkipped('Database password not configured; skipping integration tests.');
|
||||
}
|
||||
|
||||
$dsn = sprintf('pgsql:host=%s;port=%d;dbname=%s', $host, $port, $name);
|
||||
try {
|
||||
self::$pdo = new \PDO($dsn, $user, $pass, [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
]);
|
||||
} catch (\PDOException $e) {
|
||||
self::markTestSkipped('Database connection failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testMigrationTablesExist(): void
|
||||
{
|
||||
if (self::$pdo === null) {
|
||||
$this->markTestSkipped('Database connection not available.');
|
||||
}
|
||||
|
||||
$expectedTables = [
|
||||
'categories',
|
||||
'files',
|
||||
'folders',
|
||||
'import_items',
|
||||
'import_jobs',
|
||||
'model_tags',
|
||||
'models',
|
||||
'tags',
|
||||
'thumbnails',
|
||||
'phinxlog',
|
||||
];
|
||||
|
||||
foreach ($expectedTables as $table) {
|
||||
$stmt = self::$pdo->query(
|
||||
"SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '{$table}'"
|
||||
);
|
||||
$this->assertNotFalse($stmt, "Query failed for table {$table}");
|
||||
$this->assertNotEmpty($stmt->fetch(), "Table {$table} does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeedDataExists(): void
|
||||
{
|
||||
if (self::$pdo === null) {
|
||||
$this->markTestSkipped('Database connection not available.');
|
||||
}
|
||||
|
||||
$categories = self::$pdo->query("SELECT name FROM categories ORDER BY name")->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$this->assertContains('Aircraft', $categories);
|
||||
$this->assertContains('Automotive', $categories);
|
||||
$this->assertContains('Tools', $categories);
|
||||
|
||||
$tags = self::$pdo->query("SELECT name FROM tags ORDER BY name")->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$this->assertContains('wip', $tags);
|
||||
$this->assertContains('completed', $tags);
|
||||
$this->assertContains('print-ready', $tags);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user