Skip to content

Commit d47ebaa

Browse files
tjholmjyecusch
andauthored
chore(cli): remove unnecessary comments
Co-authored-by: Jye Cusch <jye.cusch@gmail.com>
1 parent bdfba8a commit d47ebaa

File tree

3 files changed

+1
-23
lines changed

3 files changed

+1
-23
lines changed

cli/internal/simulation/database/database.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,19 @@ type DatabaseInfo struct {
4848
func NewDatabaseManager(projectName, dataDir string) (*DatabaseManager, error) {
4949
ctx := context.Background()
5050

51-
// Create Docker client
5251
dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
5352
if err != nil {
5453
return nil, fmt.Errorf("failed to create Docker client: %w", err)
5554
}
5655

57-
// Try to use standard PostgreSQL port (5432), fall back to random if unavailable
5856
port, err := netx.ReservePort(5432)
5957
if err != nil {
60-
// Port 5432 is taken, get a random available port
61-
port, err = netx.GetNextPort(netx.MinPort(5432), netx.MaxPort(6000))
58+
port, err = netx.GetNextPort(netx.MinPort(5433), netx.MaxPort(6000))
6259
if err != nil {
6360
return nil, fmt.Errorf("failed to allocate port for PostgreSQL: %w", err)
6461
}
6562
}
6663

67-
// Generate a consistent volume name for this project
68-
// Sanitize project name for Docker volume naming (alphanumeric, hyphens, underscores only)
6964
sanitizedName := sanitizeVolumeName(projectName)
7065
volumeName := fmt.Sprintf("suga-%s-postgres-data", sanitizedName)
7166

@@ -80,10 +75,8 @@ func NewDatabaseManager(projectName, dataDir string) (*DatabaseManager, error) {
8075

8176
// Start initializes and starts the PostgreSQL Docker container
8277
func (m *DatabaseManager) Start() error {
83-
// Create or verify the Docker volume exists
8478
_, err := m.dockerClient.VolumeInspect(m.ctx, m.volumeName)
8579
if err != nil {
86-
// Volume doesn't exist, create it
8780
_, err = m.dockerClient.VolumeCreate(m.ctx, volume.CreateOptions{
8881
Name: m.volumeName,
8982
Labels: map[string]string{
@@ -96,7 +89,6 @@ func (m *DatabaseManager) Start() error {
9689
}
9790
}
9891

99-
// Pull the PostgreSQL image
10092
fmt.Printf("Pulling PostgreSQL image %s (this may take some time on first run)...\n\n",
10193
style.Cyan(postgresImage))
10294
reader, err := m.dockerClient.ImagePull(m.ctx, postgresImage, image.PullOptions{})
@@ -108,7 +100,6 @@ func (m *DatabaseManager) Start() error {
108100
// Wait for image pull to complete
109101
_, _ = io.Copy(io.Discard, reader)
110102

111-
// Create container configuration
112103
containerConfig := &container.Config{
113104
Image: postgresImage,
114105
Env: []string{
@@ -140,7 +131,6 @@ func (m *DatabaseManager) Start() error {
140131
AutoRemove: true,
141132
}
142133

143-
// Create the container
144134
resp, err := m.dockerClient.ContainerCreate(
145135
m.ctx,
146136
containerConfig,
@@ -155,12 +145,10 @@ func (m *DatabaseManager) Start() error {
155145

156146
m.containerID = resp.ID
157147

158-
// Start the container
159148
if err := m.dockerClient.ContainerStart(m.ctx, m.containerID, container.StartOptions{}); err != nil {
160149
return fmt.Errorf("failed to start PostgreSQL container: %w", err)
161150
}
162151

163-
// Wait for PostgreSQL to be ready
164152
if err := m.waitForPostgres(); err != nil {
165153
return fmt.Errorf("PostgreSQL failed to become ready: %w", err)
166154
}
@@ -196,7 +184,6 @@ func (m *DatabaseManager) waitForPostgres() error {
196184

197185
// CreateDatabase creates a new database in the PostgreSQL instance if it doesn't exist
198186
func (m *DatabaseManager) CreateDatabase(name string, intent schema.DatabaseIntent) error {
199-
// Connect to the default postgres database
200187
connStr := fmt.Sprintf("host=localhost port=%d user=%s password=%s dbname=%s sslmode=disable",
201188
m.port, postgresUser, postgresPassword, postgresDB)
202189

@@ -219,7 +206,6 @@ func (m *DatabaseManager) CreateDatabase(name string, intent schema.DatabaseInte
219206
// Database already exists, continue
220207
}
221208

222-
// Store database info
223209
m.databases[name] = &DatabaseInfo{
224210
name: name,
225211
intent: intent,
@@ -286,19 +272,15 @@ func (m *DatabaseManager) GetDatabases() []string {
286272
// sanitizeVolumeName sanitizes a project name for use in Docker volume names
287273
// Docker volume names must match: [a-zA-Z0-9][a-zA-Z0-9_.-]+
288274
func sanitizeVolumeName(name string) string {
289-
// Convert to lowercase
290275
result := strings.ToLower(name)
291276

292-
// Replace invalid characters with hyphens
293277
invalidChars := regexp.MustCompile(`[^a-z0-9_.-]`)
294278
result = invalidChars.ReplaceAllString(result, "-")
295279

296-
// Ensure it doesn't start with a hyphen or dot
297280
if len(result) > 0 && (result[0] == '-' || result[0] == '.') {
298281
result = "app" + result
299282
}
300283

301-
// Fallback if empty
302284
if result == "" {
303285
result = "app"
304286
}

cli/internal/simulation/simulation.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ func (s *SimulationServer) startDatabases(output io.Writer) error {
116116

117117
fmt.Fprintf(output, "%s\n\n", style.Purple("Databases"))
118118

119-
// Create all databases in the PostgreSQL instance
120119
for dbName, dbIntent := range databaseIntents {
121120
err = dbManager.CreateDatabase(dbName, *dbIntent)
122121
if err != nil {
@@ -292,7 +291,6 @@ func (s *SimulationServer) startServices(output io.Writer) (<-chan service.Servi
292291
// Inject database connection strings for databases this service has access to
293292
if s.databaseManager != nil {
294293
for dbName, dbIntent := range s.appSpec.DatabaseIntents {
295-
// Check if this service has access to this database
296294
if dbIntent.Access != nil {
297295
if _, hasAccess := dbIntent.Access[serviceName]; hasAccess {
298296
envKey := s.databaseManager.GetEnvVarKey(dbName)
@@ -469,7 +467,6 @@ func (s *SimulationServer) Stop() error {
469467
}
470468
}
471469

472-
// Wait for all service goroutines to complete
473470
s.servicesWg.Wait()
474471

475472
// Stop the database manager after services have shut down

cli/pkg/app/suga.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ func Dev() error {
672672
errChan <- simserver.Start(os.Stdout)
673673
}()
674674

675-
// Wait for either completion or interrupt signal
676675
select {
677676
case err = <-errChan:
678677
return err

0 commit comments

Comments
 (0)