• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fluxoft / migrant / a187a2a2-6433-4fb5-a535-77163f6e2eec

22 Jan 2025 04:18AM UTC coverage: 0.0%. Remained the same
a187a2a2-6433-4fb5-a535-77163f6e2eec

push

circleci

web-flow
Merge pull request #7 from fluxoft/bugfix/revisions-should-be-returned-as-associate-array-keyed-by-revision

fix bug introduced by last release in MigrationDbTable

0 of 10 new or added lines in 1 file covered. (0.0%)

15 existing lines in 1 file now uncovered.

0 of 356 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/MigrationDbTable.php
1
<?php
2

3
namespace Fluxoft\Migrant;
4

5
use PDO;
6
use PDOException;
7

8
class MigrationDbTable {
9
        private readonly PDO $connection;
10
        private readonly string $tableName;
11

12
        public function __construct(PDO $connection, string $tableName = 'migrant_log') {
UNCOV
13
                $this->connection = $connection;
×
NEW
14
                $this->tableName  = $tableName;
×
UNCOV
15
                $this->init();
×
16
        }
17

18
        public function GetExecutedMigrations(): array {
NEW
19
                $sql  = "SELECT revision, migration_start, migration_end FROM {$this->tableName} ORDER BY revision";
×
20
                $stmt = $this->connection->prepare($sql);
×
21
                $stmt->execute();
×
NEW
22
                $data = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
×
23

NEW
24
                $hash = [];
×
NEW
25
                foreach ($data as $row) {
×
NEW
26
                        $hash[$row['revision']] = $row;
×
27
                }
28

NEW
29
                return $hash;
×
30
        }
31

32
        public function AddMigration(int $revision, \DateTime $startTime, \DateTime $endTime): void {
NEW
33
                $sql  = "INSERT INTO {$this->tableName} (revision, migration_start, migration_end)
×
UNCOV
34
                        VALUES (:revision, :migrationStart, :migrationEnd)";
×
35
                $stmt = $this->connection->prepare($sql);
×
36
                $stmt->execute([
×
37
                        'revision' => $revision,
×
38
                        'migrationStart' => $startTime->format('Y-m-d H:i:s'),
×
39
                        'migrationEnd' => $endTime->format('Y-m-d H:i:s')
×
40
                ]);
×
41
        }
42

43
        public function RemoveMigration(int $revision): void {
NEW
44
                $sql  = "DELETE FROM {$this->tableName} WHERE revision = :revision";
×
UNCOV
45
                $stmt = $this->connection->prepare($sql);
×
46
                $stmt->execute(['revision' => $revision]);
×
47
        }
48

49
        protected function init(): void {
50
                if (!$this->doesTableExist()) {
×
UNCOV
51
                        $this->createMigrationTable();
×
52
                }
53
        }
54

55
        protected function doesTableExist(): bool {
56
                try {
57
                        $this->connection->query("SELECT 1 FROM {$this->tableName} LIMIT 1");
×
58
                        return true;
×
59
                } catch (PDOException $e) {
×
UNCOV
60
                        return false;
×
61
                }
62
        }
63

64
        protected function createMigrationTable(): void {
NEW
65
                $dbType       = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
×
UNCOV
66
                $datetimeType = match ($dbType) {
×
UNCOV
67
                        'pgsql' => 'TIMESTAMP',
×
UNCOV
68
                        'mysql' => 'DATETIME',
×
69
                        'sqlite' => 'TEXT',
×
70
                        default => 'TIMESTAMP',
×
UNCOV
71
                };
×
72

UNCOV
73
                $sql = "CREATE TABLE {$this->tableName} (
×
74
                        revision BIGINT NOT NULL PRIMARY KEY,
UNCOV
75
                        migration_start {$datetimeType} NOT NULL,
×
UNCOV
76
                        migration_end {$datetimeType} NOT NULL
×
UNCOV
77
                )";
×
UNCOV
78
                $this->connection->exec($sql);
×
79
        }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc