aboutsummaryrefslogtreecommitdiffstats
path: root/backend/scripts
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswa Kalyan Bhuyan <biswa@surgot.in> 2025-04-24 08:18:27 +0530
committerLibravatarLibravatar Biswa Kalyan Bhuyan <biswa@surgot.in> 2025-04-24 08:18:27 +0530
commit50d5e6534f5e593297a09323e683c7c8b850117b (patch)
tree339d6e8b123c5d4caa4129971e2cb1b960b12a89 /backend/scripts
parent76066679b5bdab53419492066c4e80d2ed3be518 (diff)
downloadfinance-50d5e6534f5e593297a09323e683c7c8b850117b.tar.gz
finance-50d5e6534f5e593297a09323e683c7c8b850117b.tar.bz2
finance-50d5e6534f5e593297a09323e683c7c8b850117b.zip
feat: added basic backend features to it
- Set up API framework (Gin Gonic) - Set up ORM/DB library (GORM) - Design database schema (Users, Accounts, Transactions, Loans, Goals) - Set up database connection and migrations
Diffstat (limited to 'backend/scripts')
-rwxr-xr-xbackend/scripts/setup_db.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/backend/scripts/setup_db.sh b/backend/scripts/setup_db.sh
new file mode 100755
index 0000000..7388015
--- /dev/null
+++ b/backend/scripts/setup_db.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Script to set up the PostgreSQL database for the finance application
+
+# Prompt for PostgreSQL user to use
+read -p "Enter PostgreSQL admin username [postgres]: " PG_USER
+PG_USER=${PG_USER:-postgres}
+
+# Prompt for PostgreSQL password
+read -s -p "Enter PostgreSQL password for $PG_USER: " PG_PASSWORD
+echo
+
+# Check if database exists
+echo "Checking if database exists..."
+if PGPASSWORD="$PG_PASSWORD" psql -U "$PG_USER" -h localhost -lqt | cut -d \| -f 1 | grep -qw finance; then
+ echo "Database 'finance' already exists"
+else
+ echo "Creating database 'finance'..."
+ PGPASSWORD="$PG_PASSWORD" createdb -U "$PG_USER" -h localhost finance
+ if [ $? -ne 0 ]; then
+ echo "Failed to create database. Please check your credentials."
+ exit 1
+ fi
+ echo "Database 'finance' created successfully"
+fi
+
+# Create .env file with database connection details
+echo "Creating .env file with database connection info..."
+cat > .env <<EOF
+# Database Connection
+DATABASE_DSN=host=localhost user=$PG_USER password=$PG_PASSWORD dbname=finance port=5432 sslmode=disable TimeZone=UTC
+
+# JWT Secret (for user authentication)
+JWT_SECRET=$(openssl rand -hex 32)
+EOF
+
+echo ".env file created with your database connection details."
+echo "You can now run the application with 'go run cmd/api/main.go'" \ No newline at end of file