Skip to content

Commit a783277

Browse files
committed
Seed initial admin user
1 parent 938b090 commit a783277

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpList\Core\Migrations;
6+
7+
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
8+
use Doctrine\DBAL\Schema\Schema;
9+
use Doctrine\Migrations\AbstractMigration;
10+
11+
final class Version20251103SeedInitialAdmin extends AbstractMigration
12+
{
13+
public function getDescription(): string
14+
{
15+
return 'Seed initial admin user';
16+
}
17+
18+
public function up(Schema $schema): void
19+
{
20+
$platform = $this->connection->getDatabasePlatform();
21+
$this->skipIf(!$platform instanceof PostgreSQLPlatform, sprintf(
22+
'Unsupported platform for this migration: %s',
23+
get_class($platform)
24+
));
25+
26+
$this->addSql(<<<'SQL'
27+
INSERT INTO phplist_admin (id, created, modified, loginname, namelc, email, password, passwordchanged, disabled, superuser, privileges)
28+
VALUES (1, NOW(), NOW(), 'admin', 'admin', '[email protected]', :hash, CURRENT_DATE, FALSE, TRUE, :privileges)
29+
ON CONFLICT (id) DO UPDATE
30+
SET
31+
modified = EXCLUDED.modified,
32+
privileges = EXCLUDED.privileges
33+
SQL, [
34+
'hash' => hash('sha256', 'password'),
35+
'privileges' => 'a:4:{s:11:"subscribers";b:1;s:9:"campaigns";b:1;s:10:"statistics";b:1;s:8:"settings";b:1;}',
36+
]);
37+
}
38+
39+
public function down(Schema $schema): void
40+
{
41+
$platform = $this->connection->getDatabasePlatform();
42+
$this->skipIf(!$platform instanceof PostgreSQLPlatform, sprintf(
43+
'Unsupported platform for this migration: %s',
44+
get_class($platform)
45+
));
46+
47+
$this->addSql('DELETE FROM phplist_admin WHERE id = 1');
48+
}
49+
}

0 commit comments

Comments
 (0)