- Added owner and team members relationships to the Project entity. - Updated ProjectRepository to find projects based on user ownership or team membership. - Enhanced ProjectVoter to manage view, edit, and delete permissions based on ownership and team membership. - Created ProjectAccessExtension to filter projects based on user access. - Updated ProjectManagement.vue to include owner and team member selection in the UI. - Implemented API endpoints for managing Git repositories with proper access control. - Added migration to update the database schema for project ownership and team members.
82 lines
4.6 KiB
PHP
82 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
/**
|
|
* Add owner and team members to projects
|
|
*/
|
|
final class Version20251114102103 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add owner (ManyToOne) and team_members (ManyToMany) relationships to projects table';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
// Check if owner_id already exists
|
|
$this->addSql('SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "projects" AND COLUMN_NAME = "owner_id")');
|
|
$this->addSql('SET @sql = IF(@col_exists = 0, "ALTER TABLE projects ADD owner_id INT DEFAULT NULL", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
|
|
// Set first user as owner for existing projects
|
|
$this->addSql('UPDATE projects SET owner_id = (SELECT id FROM users ORDER BY id LIMIT 1) WHERE owner_id IS NULL');
|
|
|
|
// Make owner_id NOT NULL
|
|
$this->addSql('SET @sql = IF(@col_exists = 0, "ALTER TABLE projects MODIFY owner_id INT NOT NULL", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
|
|
// Add foreign key if not exists
|
|
$this->addSql('SET @fk_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "projects" AND CONSTRAINT_NAME = "FK_5C93B3A47E3C61F9")');
|
|
$this->addSql('SET @sql = IF(@fk_exists = 0, "ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A47E3C61F9 FOREIGN KEY (owner_id) REFERENCES users (id) ON DELETE CASCADE", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
|
|
// Add index if not exists
|
|
$this->addSql('SET @idx_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "projects" AND INDEX_NAME = "IDX_5C93B3A47E3C61F9")');
|
|
$this->addSql('SET @sql = IF(@idx_exists = 0, "CREATE INDEX IDX_5C93B3A47E3C61F9 ON projects (owner_id)", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
|
|
// Create junction table for team members if not exists
|
|
$this->addSql('CREATE TABLE IF NOT EXISTS project_team_members (project_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_8A3C5F7D166D1F9C (project_id), INDEX IDX_8A3C5F7DA76ED395 (user_id), PRIMARY KEY(project_id, user_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
|
|
|
|
// Add foreign keys for junction table if not exists
|
|
$this->addSql('SET @fk1_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "project_team_members" AND CONSTRAINT_NAME = "FK_8A3C5F7D166D1F9C")');
|
|
$this->addSql('SET @sql = IF(@fk1_exists = 0, "ALTER TABLE project_team_members ADD CONSTRAINT FK_8A3C5F7D166D1F9C FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
|
|
$this->addSql('SET @fk2_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "project_team_members" AND CONSTRAINT_NAME = "FK_8A3C5F7DA76ED395")');
|
|
$this->addSql('SET @sql = IF(@fk2_exists = 0, "ALTER TABLE project_team_members ADD CONSTRAINT FK_8A3C5F7DA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE", "SELECT 1")');
|
|
$this->addSql('PREPARE stmt FROM @sql');
|
|
$this->addSql('EXECUTE stmt');
|
|
$this->addSql('DEALLOCATE PREPARE stmt');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
// Drop junction table
|
|
$this->addSql('ALTER TABLE project_team_members DROP FOREIGN KEY FK_8A3C5F7D166D1F9C');
|
|
$this->addSql('ALTER TABLE project_team_members DROP FOREIGN KEY FK_8A3C5F7DA76ED395');
|
|
$this->addSql('DROP TABLE project_team_members');
|
|
|
|
// Remove owner_id from projects
|
|
$this->addSql('ALTER TABLE projects DROP FOREIGN KEY FK_5C93B3A47E3C61F9');
|
|
$this->addSql('DROP INDEX IDX_5C93B3A47E3C61F9 ON projects');
|
|
$this->addSql('ALTER TABLE projects DROP owner_id');
|
|
}
|
|
}
|