Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Improve environnement management #334

Open
HugoRCD opened this issue Nov 25, 2024 · 0 comments · May be fixed by #335
Open

enhancement: Improve environnement management #334

HugoRCD opened this issue Nov 25, 2024 · 0 comments · May be fixed by #335
Assignees

Comments

@HugoRCD
Copy link
Owner

HugoRCD commented Nov 25, 2024

Overview

Improve environment management by transforming environment storage from concatenated strings to a proper array structure, enabling better environment handling and future custom environment support.

Current Behavior

  • Environments stored as concatenated strings ('production|preview' or 'production')
  • Limited flexibility for environment management
  • No support for custom environments
  • Complex string manipulation for multiple environments

Proposed Behavior

  • Store environments as proper arrays
  • Link environments to team settings
  • Support base environments (production, development, preview)
  • Foundation for custom environments
  • Cleaner environment management

Implementation Details

Database Schema Changes

// Current Schema
export const variables = pgTable('variables', {
  id: serial('id').primaryKey(),
  environment: text('environment').notNull(), // Currently: 'production|preview'
  // ... other fields
})

// New Schema
export const environments = pgTable('environments', {
  id: serial('id').primaryKey(),
  teamId: integer('team_id').references(() => teams.id),
  name: text('name').notNull(),
  type: text('type').notNull(), // 'base' or 'custom'
  createdAt: timestamp('created_at').defaultNow(),
})

export const variableEnvironments = pgTable('variable_environments', {
  id: serial('id').primaryKey(),
  variableId: integer('variable_id').references(() => variables.id),
  environmentId: integer('environment_id').references(() => environments.id),
})

Base Implementation

// Environment Types
export enum BaseEnvironment {
  PRODUCTION = 'production',
  DEVELOPMENT = 'development',
  PREVIEW = 'preview'
}

// Team Creation with Base Environments
export class TeamService {
  async createTeam(createTeamInput: CreateTeamInput): Promise<Team> {
    const team = await createTeam(createTeamInput)
    
    // Initialize base environments
    await Promise.all(
      Object.values(BaseEnvironment).map(env =>
        createEnvironment({
          teamId: team.id,
          name: env,
          type: 'base'
        })
      )
    )
    
    return team
  }
}
export class VariableService {
  async createVariable(input: CreateVariableInput): Promise<Variable> {
    const variable = await createVariable(input)
    
    // Link environments
    await Promise.all(
      input.environments.map(envId =>
        createVariableEnvironment({
          variableId: variable.id,
          environmentId: envId
        })
      )
    )
    
    return variable
  }
}

Future Possibilities

  1. Custom Environments
  • Team-specific environments
  • Environment templates
  • Environment hierarchies
  1. Enhanced Features
  • Environment-specific permissions
  • Environment cloning
  • Environment variables inheritance
  • Environment health monitoring
  1. Team Management
  • Environment access control
  • Environment sharing between teams
  • Environment audit logs

This is merely a proposal for implementation; the code may not be suitable for the project. This is intended solely to provide a clearer understanding of how the implementation might appear.

@HugoRCD HugoRCD self-assigned this Nov 25, 2024
@HugoRCD HugoRCD linked a pull request Nov 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant