Squelette Symfony, entités Server et Action
This commit is contained in:
commit
52ecb4204c
46 changed files with 4308 additions and 0 deletions
86
migrations/Version20260417000001.php
Normal file
86
migrations/Version20260417000001.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260417000001 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Initial schema: app_user, server, service, action_log tables';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE TABLE app_user (
|
||||
user_id SERIAL NOT NULL,
|
||||
email VARCHAR(180) NOT NULL,
|
||||
pseudo VARCHAR(50) NOT NULL,
|
||||
roles JSON NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
reset_token VARCHAR(100) DEFAULT NULL,
|
||||
reset_token_expires_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
|
||||
PRIMARY KEY(user_id)
|
||||
)');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_app_user_email ON app_user (email)');
|
||||
$this->addSql('COMMENT ON COLUMN app_user.created_at IS \'(DC2Type:datetime_immutable)\'');
|
||||
$this->addSql('COMMENT ON COLUMN app_user.reset_token_expires_at IS \'(DC2Type:datetime_immutable)\'');
|
||||
|
||||
$this->addSql('CREATE TABLE server (
|
||||
server_id SERIAL NOT NULL,
|
||||
owner_id INT NOT NULL,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
ip_address VARCHAR(45) NOT NULL,
|
||||
ssh_port SMALLINT NOT NULL DEFAULT 22,
|
||||
ssh_user VARCHAR(50) NOT NULL,
|
||||
ssh_password TEXT NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
last_status VARCHAR(10) NOT NULL DEFAULT \'unknown\',
|
||||
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
PRIMARY KEY(server_id)
|
||||
)');
|
||||
$this->addSql('COMMENT ON COLUMN server.created_at IS \'(DC2Type:datetime_immutable)\'');
|
||||
$this->addSql('ALTER TABLE server ADD CONSTRAINT FK_server_owner FOREIGN KEY (owner_id) REFERENCES app_user (user_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
$this->addSql('CREATE TABLE service (
|
||||
service_id SERIAL NOT NULL,
|
||||
server_id INT NOT NULL,
|
||||
name VARCHAR(50) NOT NULL,
|
||||
display_name VARCHAR(100) NOT NULL,
|
||||
PRIMARY KEY(service_id)
|
||||
)');
|
||||
$this->addSql('ALTER TABLE service ADD CONSTRAINT FK_service_server FOREIGN KEY (server_id) REFERENCES server (server_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
|
||||
$this->addSql('CREATE TABLE action_log (
|
||||
log_id SERIAL NOT NULL,
|
||||
user_id INT DEFAULT NULL,
|
||||
server_id INT NOT NULL,
|
||||
action_type VARCHAR(20) NOT NULL,
|
||||
status VARCHAR(10) NOT NULL,
|
||||
output TEXT DEFAULT NULL,
|
||||
executed_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
|
||||
PRIMARY KEY(log_id)
|
||||
)');
|
||||
$this->addSql('COMMENT ON COLUMN action_log.executed_at IS \'(DC2Type:datetime_immutable)\'');
|
||||
$this->addSql('ALTER TABLE action_log ADD CONSTRAINT FK_log_user FOREIGN KEY (user_id) REFERENCES app_user (user_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('ALTER TABLE action_log ADD CONSTRAINT FK_log_server FOREIGN KEY (server_id) REFERENCES server (server_id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE action_log DROP CONSTRAINT FK_log_user');
|
||||
$this->addSql('ALTER TABLE action_log DROP CONSTRAINT FK_log_server');
|
||||
$this->addSql('ALTER TABLE service DROP CONSTRAINT FK_service_server');
|
||||
$this->addSql('ALTER TABLE server DROP CONSTRAINT FK_server_owner');
|
||||
$this->addSql('DROP TABLE action_log');
|
||||
$this->addSql('DROP TABLE service');
|
||||
$this->addSql('DROP TABLE server');
|
||||
$this->addSql('DROP TABLE app_user');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue