Skip to content

Commit 53b1378

Browse files
TatevikGrtatevikg1
andauthored
Check for existing phpList schema before applying migration (#383)
* Check for existing phpList schema before applying migration * Add inverse relationships to ORM mappings for AdminAttributeValue and SubscriberList * Add schema validation to the CI workflow --------- Co-authored-by: Tatevik <tatevikg1@gmail.com>
1 parent 428f65f commit 53b1378

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ jobs:
5858
run: composer validate --no-check-all --no-check-lock --strict;
5959
- name: Linting all php files
6060
run: find src/ tests/ public/ -name ''*.php'' -print0 | xargs -0 -n 1 -P 4 php -l; php -l bin/*;
61+
- name: Validate Doctrine schema
62+
run: |
63+
export PHPLIST_DATABASE_NAME=${{ env.DB_DATABASE }}
64+
export PHPLIST_DATABASE_USER=${{ env.DB_USERNAME }}
65+
export PHPLIST_DATABASE_PASSWORD=${{ env.DB_PASSWORD }}
66+
export PHPLIST_DATABASE_PORT=${{ job.services.mysql.ports['3306'] }}
67+
export PHPLIST_DATABASE_HOST=127.0.0.1
68+
php bin/console doctrine:schema:validate --skip-sync
6169
- name: Run units tests with phpunit
6270
run: vendor/bin/phpunit tests/Unit/ --testdox
6371
- name: Run integration tests with phpunit

src/Domain/Identity/Model/AdminAttributeValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class AdminAttributeValue implements DomainModel
1515
{
1616
#[ORM\Id]
17-
#[ORM\ManyToOne(targetEntity: AdminAttributeDefinition::class)]
17+
#[ORM\ManyToOne(targetEntity: AdminAttributeDefinition::class, inversedBy: 'attributeValues')]
1818
#[ORM\JoinColumn(name: 'adminattributeid', referencedColumnName: 'id')]
1919
private AdminAttributeDefinition $attributeDefinition;
2020

src/Domain/Subscription/Model/SubscriberList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SubscriberList implements DomainModel, Identity, CreationDate, Modificatio
6363
#[ORM\Column]
6464
private ?string $category = '';
6565

66-
#[ORM\ManyToOne(targetEntity: Administrator::class)]
66+
#[ORM\ManyToOne(targetEntity: Administrator::class, inversedBy: 'ownedLists')]
6767
#[ORM\JoinColumn(name: 'owner')]
6868
private ?Administrator $owner = null;
6969

src/Migrations/Version20251028092901MySqlInit.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public function up(Schema $schema): void
2828
get_class($platform)
2929
)
3030
);
31+
32+
$schemaManager = $this->connection->createSchemaManager();
33+
$tables = $schemaManager->listTableNames();
34+
$hasUserStats = array_filter(
35+
$tables,
36+
static fn (string $table): bool =>
37+
str_ends_with($table, 'userstats')
38+
);
39+
$this->skipIf(
40+
!empty($hasUserStats),
41+
'phpList schema already exists.'
42+
);
43+
3144
// this up() migration is auto-generated, please modify it to your needs
3245
$this->addSql(file_get_contents(__DIR__.'/initial_schema.sql'));
3346
}

0 commit comments

Comments
 (0)