Skip to content

Conversation

@sukhman-sukh
Copy link
Contributor

Currently, DB was not being created if not exist, so we had to manually init it before setting up beast for first time. Added a check for db existence and then db creation if not exist

Copilot AI review requested due to automatic review settings December 8, 2025 21:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds automatic database creation functionality to the ConnectDatabase() function, eliminating the need for manual database initialization before first-time setup. The implementation checks for database existence using PostgreSQL CLI commands and creates the database if it doesn't exist.

Key changes:

  • Added checkDatabaseExists() function to query PostgreSQL for database existence
  • Added createDatabase() function to create the database via psql command
  • Modified ConnectDatabase() to automatically create the database if not found

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"-p", dbConfig.PsqlConf.Port,
"-d", "postgres",
"-tAc",
fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s';", dbConfig.PsqlConf.Dbname),
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQL injection vulnerability: the database name is directly interpolated into the SQL query without proper escaping. A malicious database name in the config could be used to execute arbitrary SQL commands. Use parameterized queries or properly escape the database name using PostgreSQL's quote_ident function.

Suggested change
fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = '%s';", dbConfig.PsqlConf.Dbname),
fmt.Sprintf("SELECT 1 FROM pg_database WHERE datname = quote_ident('%s');", dbConfig.PsqlConf.Dbname),

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this for now as the databsae name is provided by admin only

@sukhman-sukh sukhman-sukh requested a review from v1bh475u January 7, 2026 20:57
@v1bh475u
Copy link
Contributor

Why not use postgres gorm for this instead of raw commands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants