-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: create appsmith schema for postgres #36591
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
Changes from all commits
598ef61
62fb7d2
76e95c3
d89a596
1edfc6f
1413b1e
cb4a295
833832d
ca8d57a
65ea2db
d3bf74c
0254049
bca4afc
846a63b
43089a6
342e4d4
80da201
14a0f35
d38ca4d
32f91e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,54 @@ extract_postgres_db_params() { | |
| export PG_DB_NAME="$DB" | ||
| } | ||
|
|
||
| init_pg_db() { | ||
| # Create the appsmith schema | ||
| echo "Initializing PostgreSQL with schema..." | ||
|
|
||
| # Check if APPSMITH_DB_URL is a PostgreSQL URL | ||
| if [[ -n "$APPSMITH_DB_URL" && "$APPSMITH_DB_URL" == postgres*://* ]]; then | ||
| echo "APPSMITH_DB_URL is a valid PostgreSQL URL." | ||
|
|
||
| # Check if the DB_HOST is local (localhost or 127.0.0.1) | ||
| if [[ "$PG_DB_HOST" == "localhost" || "$PG_DB_HOST" == "127.0.0.1" ]]; then | ||
AnaghHegde marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+94
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Class, let's examine the URL validation and host determination. Good effort on validating the APPSMITH_DB_URL! However, we can improve this section:
Here's a suggested improvement: if [[ -n "$APPSMITH_DB_URL" && "$APPSMITH_DB_URL" =~ ^postgres(ql)?:// ]]; then
echo "APPSMITH_DB_URL is a valid PostgreSQL URL."
if [[ "$PG_DB_HOST" == "localhost" || "$PG_DB_HOST" == "127.0.0.1" || "$PG_DB_HOST" == "::1" ]]; then
echo "Local PostgreSQL instance detected."
else
echo "Remote PostgreSQL instance detected."
fi
else
echo "Invalid or missing PostgreSQL URL."
exit 1
fiThis change will catch more valid PostgreSQL URLs and include the IPv6 localhost address. Remember, students, attention to detail is crucial in database management! |
||
|
|
||
| # Check if the database exists | ||
| DB_CHECK=$(psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U postgres -d "postgres" -tAc "SELECT 1 FROM pg_database WHERE datname='$PG_DB_NAME'") | ||
|
|
||
| if [ "$DB_CHECK" != "1" ]; then | ||
| echo "Database $PG_DB_NAME does not exist. Creating database..." | ||
| psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U postgres -d "postgres" -c "CREATE DATABASE $PG_DB_NAME;" | ||
| else | ||
| echo "Database $PG_DB_NAME already exists." | ||
| fi | ||
AnaghHegde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Check if the schema exists | ||
| SCHEMA_CHECK=$(psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U postgres -d "$PG_DB_NAME" -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name='appsmith'") | ||
|
|
||
| # Create schema and user if not exists | ||
| if [ "$SCHEMA_CHECK" != "1" ]; then | ||
| echo "Creating user '$PG_DB_USER' with password " | ||
| psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U postgres -d "$PG_DB_NAME" -c "CREATE USER \"$PG_DB_USER\" WITH PASSWORD '$PG_DB_PASSWORD';" | ||
|
|
||
| echo "Schema 'appsmith' does not exist. Creating schema..." | ||
| psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U postgres -d "$PG_DB_NAME" -c "CREATE SCHEMA appsmith;" | ||
| fi | ||
|
Comment on lines
+101
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, let's turn our attention to the local database and schema creation, class. You've done a good job structuring the database and schema creation logic. However, there are a few points we need to address:
Remember, class, security and error handling are crucial in database management scripts! |
||
| else | ||
| echo "Remote PostgreSQL detected, running as current user." | ||
| PGPASSWORD=$PG_DB_PASSWORD psql -h "$PG_DB_HOST" -p "$PG_DB_PORT" -U "$PG_DB_USER" -d "$PG_DB_NAME" -c "CREATE SCHEMA IF NOT EXISTS appsmith;" | ||
| fi | ||
|
Comment on lines
+122
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Now, let's examine the remote host schema creation, students. While this section is concise, there are a few important points we need to address:
Remember, class, always think about error handling and timeouts when dealing with remote connections! |
||
|
|
||
| # Check if the schema creation was successful | ||
| if [ $? -eq 0 ]; then | ||
| echo "Schema 'appsmith' created or already exists." | ||
| else | ||
| echo "Failed to create schema 'appsmith'." | ||
| exit 1 | ||
| fi | ||
| echo "PostgreSQL initialization completed." | ||
| fi | ||
|
Comment on lines
+127
to
+135
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Finally, let's review the schema creation verification, class. This section shows good attention to error handling, but we can make it even better:
Remember, students, thorough verification and clear error messages are key to maintaining a robust system! |
||
| } | ||
|
|
||
| # Example usage of the functions | ||
| # waitForPostgresAvailability | ||
| # extract_postgres_db_params "postgresql://user:password@localhost:5432/dbname" | ||
| # extract_postgres_db_params "postgresql://user:password@localhost:5432/dbname" | ||
Uh oh!
There was an error while loading. Please reload this page.