PostgreSQL backup tool with Point-In-Time-Recovery and restore verification
TypeScript backupbackupsdatabasedatabase-backupdevopsdockergolangkubernetesmariadbmongodbmysqlpgpostgrespostgresqls3self-hostedsystem-administrationtoolsweb-ui
REFACTOR (envs): Move docker-compose and env to root directory
Rostislav Dugin082f8f9c1b8a
diff --git a/.dockerignore b/.dockerignoreindex e91595a0..975fa610 100644--- a/.dockerignore+++ b/.dockerignore@@ -20,7 +20,6 @@ backend/*.exe# Scripts and data directoriesscripts-postgresus-datadatabasus-data# IDE and editor filesdiff --git a/backend/.env.development.example b/.env.examplesimilarity index 63%rename from backend/.env.development.examplerename to .env.exampleindex 81df3595..a36b5079 100644--- a/backend/.env.development.example+++ b/.env.example@@ -1,83 +1,102 @@-# docker-compose.yml-DEV_DB_NAME=databasus-DEV_DB_USERNAME=postgres-DEV_DB_PASSWORD=Q1234567-# app-ENV_MODE=development-# logging-SHOW_DB_INSTALLATION_VERIFICATION_LOGS=true-VICTORIA_LOGS_URL=http://localhost:9428-VICTORIA_LOGS_PASSWORD=devpassword-# tests-TEST_LOCALHOST=localhost-# cloudflare turnstile-CLOUDFLARE_TURNSTILE_SITE_KEY=-CLOUDFLARE_TURNSTILE_SECRET_KEY=-# db-DATABASE_DSN=host=dev-db user=postgres password=Q1234567 dbname=databasus port=5437 sslmode=disable-DATABASE_URL=postgres://postgres:Q1234567@dev-db:5437/databasus?sslmode=disable-# migrations-GOOSE_DRIVER=postgres-GOOSE_DBSTRING=postgres://postgres:Q1234567@dev-db:5437/databasus?sslmode=disable-GOOSE_MIGRATION_DIR=./migrations-# valkey-VALKEY_HOST=127.0.0.1-VALKEY_PORT=6379-VALKEY_USERNAME=-VALKEY_PASSWORD=-VALKEY_IS_SSL=false-# billing-PRICE_PER_GB_CENTS=-IS_PADDLE_SANDBOX=true-PADDLE_API_KEY=-PADDLE_WEBHOOK_SECRET=-PADDLE_PRICE_ID=-PADDLE_CLIENT_TOKEN=-# testing-# to get Google Drive env variables: add storage in UI and copy data from added storage here-TEST_GOOGLE_DRIVE_CLIENT_ID=-TEST_GOOGLE_DRIVE_CLIENT_SECRET=-TEST_GOOGLE_DRIVE_TOKEN_JSON="{\"access_token\":\"ya29..."-# testing DBs-TEST_POSTGRES_12_PORT=5000-TEST_POSTGRES_13_PORT=5001-TEST_POSTGRES_14_PORT=5002-TEST_POSTGRES_15_PORT=5003-TEST_POSTGRES_16_PORT=5004-TEST_POSTGRES_17_PORT=5005-TEST_POSTGRES_18_PORT=5006-# testing S3-TEST_MINIO_PORT=9000-TEST_MINIO_CONSOLE_PORT=9001-# testing NAS-TEST_NAS_PORT=7006-# testing Azure Blob Storage-TEST_AZURITE_BLOB_PORT=10000-# FTP-TEST_FTP_PORT=7007-# SFTP-TEST_SFTP_PORT=7008-# MySQL Test Ports-TEST_MYSQL_57_PORT=33057-TEST_MYSQL_80_PORT=33080-TEST_MYSQL_84_PORT=33084-# testing MariaDB-TEST_MARIADB_55_PORT=33055-TEST_MARIADB_101_PORT=33101-TEST_MARIADB_102_PORT=33102-TEST_MARIADB_103_PORT=33103-TEST_MARIADB_104_PORT=33104-TEST_MARIADB_105_PORT=33105-TEST_MARIADB_106_PORT=33106-TEST_MARIADB_1011_PORT=33111-TEST_MARIADB_114_PORT=33114-TEST_MARIADB_118_PORT=33118-TEST_MARIADB_120_PORT=33120-# testing MongoDB-TEST_MONGODB_40_PORT=27040-TEST_MONGODB_42_PORT=27042-TEST_MONGODB_44_PORT=27044-TEST_MONGODB_50_PORT=27050-TEST_MONGODB_60_PORT=27060-TEST_MONGODB_70_PORT=27070-TEST_MONGODB_82_PORT=27082\ No newline at end of file+# app+ENV_MODE=development+IS_CLOUD=false+SHOW_DB_INSTALLATION_VERIFICATION_LOGS=true++# dev DB (used by docker-compose.yml and backend)+DEV_DB_NAME=databasus+DEV_DB_USERNAME=postgres+DEV_DB_PASSWORD=Q1234567+DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=databasus port=5437 sslmode=disable+DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/databasus?sslmode=disable++# migrations+GOOSE_DRIVER=postgres+GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/databasus?sslmode=disable++# valkey+VALKEY_HOST=127.0.0.1+VALKEY_PORT=6379+VALKEY_USERNAME=+VALKEY_PASSWORD=+VALKEY_IS_SSL=false++# logging+VICTORIA_LOGS_URL=http://localhost:9428+VICTORIA_LOGS_PASSWORD=devpassword++# tests+TEST_LOCALHOST=localhost+TEST_POSTGRES_12_PORT=5000+TEST_POSTGRES_13_PORT=5001+TEST_POSTGRES_14_PORT=5002+TEST_POSTGRES_15_PORT=5003+TEST_POSTGRES_16_PORT=5004+TEST_POSTGRES_17_PORT=5005+TEST_POSTGRES_18_PORT=5006+TEST_MINIO_PORT=9000+TEST_MINIO_CONSOLE_PORT=9001+TEST_AZURITE_BLOB_PORT=10000+TEST_NAS_PORT=7006+TEST_FTP_PORT=7007+TEST_SFTP_PORT=7008+TEST_MYSQL_57_PORT=33057+TEST_MYSQL_80_PORT=33080+TEST_MYSQL_84_PORT=33084+TEST_MYSQL_90_PORT=33090+TEST_MARIADB_55_PORT=33055+TEST_MARIADB_101_PORT=33101+TEST_MARIADB_102_PORT=33102+TEST_MARIADB_103_PORT=33103+TEST_MARIADB_104_PORT=33104+TEST_MARIADB_105_PORT=33105+TEST_MARIADB_106_PORT=33106+TEST_MARIADB_1011_PORT=33111+TEST_MARIADB_114_PORT=33114+TEST_MARIADB_118_PORT=33118+TEST_MARIADB_120_PORT=33120+TEST_MONGODB_40_PORT=27040+TEST_MONGODB_42_PORT=27042+TEST_MONGODB_44_PORT=27044+TEST_MONGODB_50_PORT=27050+TEST_MONGODB_60_PORT=27060+TEST_MONGODB_70_PORT=27070+TEST_MONGODB_82_PORT=27082++# oauth+GITHUB_CLIENT_ID=+GITHUB_CLIENT_SECRET=+GOOGLE_CLIENT_ID=+GOOGLE_CLIENT_SECRET=++# cloudflare turnstile+CLOUDFLARE_TURNSTILE_SITE_KEY=+CLOUDFLARE_TURNSTILE_SECRET_KEY=++# billing (paddle)+PRICE_PER_GB_CENTS=+IS_PADDLE_SANDBOX=true+PADDLE_API_KEY=+PADDLE_WEBHOOK_SECRET=+PADDLE_PRICE_ID=+PADDLE_CLIENT_TOKEN=++# smtp+SMTP_HOST=+SMTP_PORT=+SMTP_USER=+SMTP_PASSWORD=+SMTP_FROM=++# domain (used in email links)+DATABASUS_URL=++# frontend (vite)+VITE_GITHUB_CLIENT_ID=+VITE_GOOGLE_CLIENT_ID=+VITE_IS_EMAIL_CONFIGURED=false+VITE_CLOUDFLARE_TURNSTILE_SITE_KEY=+VITE_IS_CLOUD=false+VITE_CLOUD_PRICE_PER_GB=+VITE_CLOUD_PADDLE_CLIENT_TOKEN=+VITE_CLOUD_IS_PADDLE_SANDBOX=truediff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.ymlindex f6ddd2ef..a335af8b 100644--- a/.github/workflows/ci-release.yml+++ b/.github/workflows/ci-release.yml@@ -246,100 +246,29 @@ jobs:- name: Create .env file for testingrun: |- cd backend- cat > .env << EOF- # docker-compose.yml- DEV_DB_NAME=databasus- DEV_DB_USERNAME=postgres- DEV_DB_PASSWORD=Q1234567- #app- ENV_MODE=development- # db - using 172.17.0.1 to access host from container+ cp .env.example .env+ cat >> .env << EOF+ # CI overrides — host=172.17.0.1 reaches host from containerDATABASE_DSN=host=172.17.0.1 user=postgres password=Q1234567 dbname=databasus port=5437 sslmode=disableDATABASE_URL=postgres://postgres:[email protected]:5437/databasus?sslmode=disable- # migrations- GOOSE_DRIVER=postgresGOOSE_DBSTRING=postgres://postgres:[email protected]:5437/databasus?sslmode=disable- GOOSE_MIGRATION_DIR=./migrations- # testingTEST_LOCALHOST=172.17.0.1- # to get Google Drive env variables: add storage in UI and copy data from added storage here- TEST_GOOGLE_DRIVE_CLIENT_ID=${{ secrets.TEST_GOOGLE_DRIVE_CLIENT_ID }}- TEST_GOOGLE_DRIVE_CLIENT_SECRET=${{ secrets.TEST_GOOGLE_DRIVE_CLIENT_SECRET }}- TEST_GOOGLE_DRIVE_TOKEN_JSON=${{ secrets.TEST_GOOGLE_DRIVE_TOKEN_JSON }}- # testing DBs- TEST_POSTGRES_12_PORT=5000- TEST_POSTGRES_13_PORT=5001- TEST_POSTGRES_14_PORT=5002- TEST_POSTGRES_15_PORT=5003- TEST_POSTGRES_16_PORT=5004- TEST_POSTGRES_17_PORT=5005- TEST_POSTGRES_18_PORT=5006- # testing S3- TEST_MINIO_PORT=9000- TEST_MINIO_CONSOLE_PORT=9001- # testing Azure Blob- TEST_AZURITE_BLOB_PORT=10000- # testing NAS- TEST_NAS_PORT=7006- # testing FTP- TEST_FTP_PORT=7007- # testing SFTP- TEST_SFTP_PORT=7008- # testing MySQL- TEST_MYSQL_57_PORT=33057- TEST_MYSQL_80_PORT=33080- TEST_MYSQL_84_PORT=33084- TEST_MYSQL_90_PORT=33090- # testing MariaDB- TEST_MARIADB_55_PORT=33055- TEST_MARIADB_101_PORT=33101- TEST_MARIADB_102_PORT=33102- TEST_MARIADB_103_PORT=33103- TEST_MARIADB_104_PORT=33104- TEST_MARIADB_105_PORT=33105- TEST_MARIADB_106_PORT=33106- TEST_MARIADB_1011_PORT=33111- TEST_MARIADB_114_PORT=33114- TEST_MARIADB_118_PORT=33118- TEST_MARIADB_120_PORT=33120- # supabase- TEST_SUPABASE_HOST=${{ secrets.TEST_SUPABASE_HOST }}- TEST_SUPABASE_PORT=${{ secrets.TEST_SUPABASE_PORT }}- TEST_SUPABASE_USERNAME=${{ secrets.TEST_SUPABASE_USERNAME }}- TEST_SUPABASE_PASSWORD=${{ secrets.TEST_SUPABASE_PASSWORD }}- TEST_SUPABASE_DATABASE=${{ secrets.TEST_SUPABASE_DATABASE }}- # testing MongoDB- TEST_MONGODB_40_PORT=27040- TEST_MONGODB_42_PORT=27042- TEST_MONGODB_44_PORT=27044- TEST_MONGODB_50_PORT=27050- TEST_MONGODB_60_PORT=27060- TEST_MONGODB_70_PORT=27070- TEST_MONGODB_82_PORT=27082- # Valkey (cache) - using 172.17.0.1- VALKEY_HOST=172.17.0.1- VALKEY_PORT=6379- VALKEY_USERNAME=- VALKEY_PASSWORD=- VALKEY_IS_SSL=false- # Host for test databases (container -> host)TEST_DB_HOST=172.17.0.1+ VALKEY_HOST=172.17.0.1EOF- name: Start test containersrun: |- cd backend- docker compose -f docker-compose.yml.example up -d+ docker compose -f docker-compose.example.yml up -d- name: Wait for containers to be readyrun: |# Wait for main dev database- timeout 60 bash -c 'until docker exec dev-db pg_isready -h localhost -p 5437 -U postgres; do sleep 2; done'+ timeout 60 bash -c 'until docker exec backend-db pg_isready -h localhost -p 5437 -U postgres; do sleep 2; done'# Wait for Valkey (cache)echo "Waiting for Valkey..."- timeout 60 bash -c 'until docker exec dev-valkey valkey-cli ping 2>/dev/null | grep -q PONG; do sleep 2; done'+ timeout 60 bash -c 'until docker exec backend-valkey valkey-cli ping 2>/dev/null | grep -q PONG; do sleep 2; done'echo "Valkey is ready!"# Wait for test databases (using 172.17.0.1 from container)@@ -512,7 +441,7 @@ jobs:run: |cd backendgo install github.com/pressly/goose/v3/cmd/[email protected]- goose up+ goose -dir ./migrations up- name: Run Go testsrun: |@@ -522,9 +451,8 @@ jobs:- name: Stop test containersif: always()run: |- cd backend# Stop and remove containers (keeping images for next run)- docker compose -f docker-compose.yml.example down -v+ docker compose -f docker-compose.example.yml down -v# Clean up all data directories created by docker-composeecho "Cleaning up data directories..."@@ -532,13 +460,10 @@ jobs:rm -rf valkey-data || truerm -rf mysqldata || truerm -rf mariadbdata || true+ rm -rf wal-queue || truerm -rf temp/nas || truerm -rf databasus-data || true- # Also clean root-level databasus-data if exists- cd ..- rm -rf databasus-data || true-echo "Cleanup complete"build-and-push-dev:diff --git a/.gitignore b/.gitignoreindex 96f9c69c..8628ddf5 100644--- a/.gitignore+++ b/.gitignore@@ -1,16 +1,20 @@-ansible/-postgresus_data/-postgresus-data/-databasus-data/-.env-pgdata/-docker-compose.yml-!agent/e2e/docker-compose.yml-node_modules/-.idea-/articles--.DS_Store-/scripts-.vscode/settings.json-.claude\ No newline at end of file+ansible/+databasus-data/+.env+pgdata/+mysqldata/+mariadbdata/+valkey-data/+victoria-logs-data/+wal-queue/+temp/+docker-compose.yml+!agent/e2e/docker-compose.yml+node_modules/+.idea+/articles++.DS_Store+/scripts+.vscode/settings.json+.claudediff --git a/AGENTS.md b/AGENTS.mdindex efec22e3..656d9a9b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -1577,4 +1577,4 @@ Always use `ClipboardHelper` (`shared/lib/ClipboardHelper.ts`) for clipboard ope## Summary-This document consolidates all project rules and guidelines. These standards should be followed consistently across all code in the Postgresus project to maintain code quality, readability, and maintainability.+This document consolidates all project rules and guidelines. These standards should be followed consistently across all code in the Databasus project to maintain code quality, readability, and maintainability.diff --git a/agent/.env.example b/agent/.env.exampledeleted file mode 100644index 8471e741..00000000--- a/agent/.env.example+++ /dev/null@@ -1,3 +0,0 @@-ENV_MODE=development-AGENT_DB_ID=your-database-id-AGENT_TOKEN=your-agent-tokendiff --git a/agent/.gitignore b/agent/.gitignoreindex d827ac7c..c4b0e0cc 100644--- a/agent/.gitignore+++ b/agent/.gitignore@@ -1,27 +1,17 @@-main-.env-docker-compose.yml-!e2e/docker-compose.yml-pgdata-pgdata_test/-mysqldata/-mariadbdata/-main.exe-swagger/-swagger/*-swagger/docs.go-swagger/swagger.json-swagger/swagger.yaml-postgresus-backend.exe-databasus-backend.exe-ui/build/*-pgdata-for-restore/-temp/-cmd.exe-temp/-valkey-data/-victoria-logs-data/-databasus.json-.test-tmp/-databasus.log-wal-queue/\ No newline at end of file+main+.env+main.exe+swagger/+swagger/*+swagger/docs.go+swagger/swagger.json+swagger/swagger.yaml+databasus-backend.exe+ui/build/*+pgdata-for-restore/+temp/+cmd.exe+temp/+databasus.json+.test-tmp/+databasus.logdiff --git a/agent/Makefile b/agent/Makefileindex a90d4be9..fe95ee81 100644--- a/agent/Makefile+++ b/agent/Makefile@@ -1,4 +1,4 @@-.PHONY: run build test lint e2e e2e-clean e2e-backup-restore e2e-backup-restore-clean+.PHONY: run build test lint wal-generator e2e e2e-clean e2e-backup-restore e2e-backup-restore-clean-include .envexport@@ -13,10 +13,13 @@ run:--pg-user devuser \--pg-password devpassword \--pg-type docker \- --pg-docker-container-name dev-postgres \- --pg-wal-dir ./wal-queue \+ --pg-docker-container-name agent-db \+ --pg-wal-dir ../wal-queue \--skip-update+wal-generator:+ go run cmd/wal-generator/main.go+build:CGO_ENABLED=0 go build -ldflags "-X main.Version=$(VERSION)" -o databasus-agent ./cmd/main.godiff --git a/agent/cmd/wal-generator/main.go b/agent/cmd/wal-generator/main.gonew file mode 100644index 00000000..4ec82ab0--- /dev/null+++ b/agent/cmd/wal-generator/main.go@@ -0,0 +1,149 @@+package main++import (+ "context"+ "flag"+ "fmt"+ "log/slog"+ "os"+ "os/signal"+ "syscall"+ "time"++ "github.com/jackc/pgx/v5"+)++func main() {+ log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))++ if err := run(log); err != nil {+ log.Error("wal generator exited with error", "error", err)+ os.Exit(1)+ }++ log.Info("shutting down")+}++func run(log *slog.Logger) error {+ pgHost := flag.String("pg-host", "127.0.0.1", "Postgres host")+ pgPort := flag.Int("pg-port", 7433, "Postgres port")+ pgUser := flag.String("pg-user", "devuser", "Postgres user")+ pgPassword := flag.String("pg-password", "devpassword", "Postgres password")+ pgDatabase := flag.String("pg-database", "devdb", "Postgres database")+ rowCount := flag.Int("row-count", 2500, "Rows inserted per cycle (~50MB at default size)")+ cycleSleep := flag.Duration("cycle-sleep", 5*time.Second, "Sleep between cycles")+ tableName := flag.String("table-name", "wal_generator", "Table used for WAL traffic")+ flag.Parse()++ ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)+ defer stop()++ dsn := fmt.Sprintf(+ "host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",+ *pgHost, *pgPort, *pgUser, *pgPassword, *pgDatabase,+ )++ conn, err := connectWithRetry(ctx, log, dsn)+ if err != nil {+ return fmt.Errorf("connect to postgres: %w", err)+ }+ defer func() {+ if closeErr := conn.Close(context.Background()); closeErr != nil {+ log.Warn("failed to close postgres connection", "error", closeErr)+ }+ }()++ if err := prepareTable(ctx, conn, *tableName); err != nil {+ return fmt.Errorf("prepare table %q: %w", *tableName, err)+ }++ log.Info(+ fmt.Sprintf("starting wal generation: %d rows per cycle, sleep %s", *rowCount, *cycleSleep),+ "table_name", *tableName,+ )++ return runLoop(ctx, log, conn, *tableName, *rowCount, *cycleSleep)+}++func connectWithRetry(ctx context.Context, log *slog.Logger, dsn string) (*pgx.Conn, error) {+ const retryInterval = 1 * time.Second++ for attempt := 1; ; attempt++ {+ if ctx.Err() != nil {+ return nil, ctx.Err()+ }++ conn, err := pgx.Connect(ctx, dsn)+ if err == nil {+ log.Info(fmt.Sprintf("connected to postgres after %d attempt(s)", attempt))+ return conn, nil+ }++ log.Info(fmt.Sprintf("postgres not ready (attempt %d): %v", attempt, err))++ select {+ case <-ctx.Done():+ return nil, ctx.Err()+ case <-time.After(retryInterval):+ }+ }+}++func prepareTable(ctx context.Context, conn *pgx.Conn, tableName string) error {+ dropSQL := fmt.Sprintf("DROP TABLE IF EXISTS %s", pgx.Identifier{tableName}.Sanitize())+ if _, err := conn.Exec(ctx, dropSQL); err != nil {+ return fmt.Errorf("drop table: %w", err)+ }++ createSQL := fmt.Sprintf(+ "CREATE TABLE %s (id SERIAL PRIMARY KEY, data TEXT NOT NULL)",+ pgx.Identifier{tableName}.Sanitize(),+ )+ if _, err := conn.Exec(ctx, createSQL); err != nil {+ return fmt.Errorf("create table: %w", err)+ }++ return nil+}++func runLoop(+ ctx context.Context,+ log *slog.Logger,+ conn *pgx.Conn,+ tableName string,+ rowCount int,+ cycleSleep time.Duration,+) error {+ insertSQL := fmt.Sprintf(+ "INSERT INTO %s (data) SELECT repeat(md5(random()::text), 640) FROM generate_series(1, $1)",+ pgx.Identifier{tableName}.Sanitize(),+ )+ deleteSQL := fmt.Sprintf("DELETE FROM %s", pgx.Identifier{tableName}.Sanitize())++ for cycle := 1; ; cycle++ {+ if ctx.Err() != nil {+ return nil+ }++ startedAt := time.Now().UTC()++ if _, err := conn.Exec(ctx, insertSQL, rowCount); err != nil {+ return fmt.Errorf("insert cycle %d: %w", cycle, err)+ }++ if _, err := conn.Exec(ctx, deleteSQL); err != nil {+ return fmt.Errorf("delete cycle %d: %w", cycle, err)+ }++ log.Info(+ fmt.Sprintf("cycle %d completed in %s", cycle, time.Since(startedAt).Round(time.Millisecond)),+ "started_at", startedAt,+ )++ select {+ case <-ctx.Done():+ return nil+ case <-time.After(cycleSleep):+ }+ }+}diff --git a/agent/docker-compose.yml.example b/agent/docker-compose.yml.exampledeleted file mode 100644index 4e3fd284..00000000--- a/agent/docker-compose.yml.example+++ /dev/null@@ -1,58 +0,0 @@-services:- dev-postgres:- image: postgres:17- container_name: dev-postgres- environment:- POSTGRES_DB: devdb- POSTGRES_USER: devuser- POSTGRES_PASSWORD: devpassword- ports:- - "7433:5432"- command:- - bash- - -c- - |- mkdir -p /wal-queue && chown postgres:postgres /wal-queue- exec docker-entrypoint.sh postgres \- -c wal_level=replica \- -c max_wal_senders=3 \- -c archive_mode=on \- -c "archive_command=cp %p /wal-queue/%f"- volumes:- - ./wal-queue:/wal-queue- healthcheck:- test: ["CMD-SHELL", "pg_isready -U devuser -d devdb"]- interval: 2s- timeout: 5s- retries: 30-- db-writer:- image: postgres:17- container_name: dev-db-writer- depends_on:- dev-postgres:- condition: service_healthy- environment:- PGHOST: dev-postgres- PGPORT: "5432"- PGUSER: devuser- PGPASSWORD: devpassword- PGDATABASE: devdb- command:- - bash- - -c- - |- echo "Waiting for postgres..."- until pg_isready -h dev-postgres -U devuser -d devdb; do sleep 1; done-- psql -c "DROP TABLE IF EXISTS wal_generator;"- psql -c "CREATE TABLE wal_generator (id SERIAL PRIMARY KEY, data TEXT NOT NULL);"- echo "Starting WAL generation loop..."- while true; do- echo "Inserting ~50MB of data..."- psql -c "INSERT INTO wal_generator (data) SELECT repeat(md5(random()::text), 640) FROM generate_series(1, 2500);"- echo "Deleting data..."- psql -c "DELETE FROM wal_generator;"- echo "Cycle complete, sleeping 5s..."- sleep 5- donediff --git a/backend/.env.production.example b/backend/.env.production.exampledeleted file mode 100644index 9de43e78..00000000--- a/backend/.env.production.example+++ /dev/null@@ -1,19 +0,0 @@-# docker-compose.yml-DEV_DB_NAME=databasus-DEV_DB_USERNAME=postgres-DEV_DB_PASSWORD=Q1234567-#app-ENV_MODE=production-# db-DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=databasus port=5437 sslmode=disable-DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/databasus?sslmode=disable-# migrations-GOOSE_DRIVER=postgres-GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/databasus?sslmode=disable-GOOSE_MIGRATION_DIR=./migrations-# valkey-VALKEY_HOST=127.0.0.1-VALKEY_PORT=6379-VALKEY_USERNAME=-VALKEY_PASSWORD=-VALKEY_IS_SSL=false\ No newline at end of filediff --git a/backend/.gitignore b/backend/.gitignoreindex da0b84b0..38235c26 100644--- a/backend/.gitignore+++ b/backend/.gitignore@@ -1,22 +1,15 @@-main-.env-docker-compose.yml-pgdata-pgdata_test/-mysqldata/-mariadbdata/-main.exe-swagger/-swagger/*-swagger/docs.go-swagger/swagger.json-swagger/swagger.yaml-postgresus-backend.exe-databasus-backend.exe-ui/build/*-pgdata-for-restore/-temp/-cmd.exe-temp/-valkey-data/-victoria-logs-data/\ No newline at end of file+main+.env+pgdata_test/+main.exe+swagger/+swagger/*+swagger/docs.go+swagger/swagger.json+swagger/swagger.yaml+databasus-backend.exe+ui/build/*+pgdata-for-restore/+temp/+cmd.exe+temp/diff --git a/backend/Makefile b/backend/Makefileindex 8793f969..b3762b48 100644--- a/backend/Makefile+++ b/backend/Makefile@@ -1,3 +1,5 @@+-include ../.env+run:go run cmd/main.go@@ -8,13 +10,13 @@ lint:golangci-lint fmt ./cmd/... ./internal/... && golangci-lint run ./cmd/... ./internal/...migration-create:- goose create $(name) sql+ goose -dir ./migrations create $(name) sqlmigration-up:- goose up+ goose -dir ./migrations postgres "$(GOOSE_DBSTRING)" upmigration-down:- goose down+ goose -dir ./migrations postgres "$(GOOSE_DBSTRING)" downswagger:swag init -g ./cmd/main.go -o swaggerdiff --git a/backend/README.md b/backend/README.mdindex 145fc918..b7f4b022 100644--- a/backend/README.md+++ b/backend/README.md@@ -1,10 +1,10 @@# Before run-Keep in mind: you need to use dev-db from docker-compose.yml in this folder-instead of databasus-db from docker-compose.yml in the root folder.+Keep in mind: you need to use `backend-db` from the root `docker-compose.yml`+instead of `databasus-db` from production deployments.-> Copy .env.example to .env-> Copy docker-compose.yml.example to docker-compose.yml (for development only)+> Copy .env.example to .env in the repo root (single source for backend, frontend, and docker compose)+> Copy docker-compose.example.yml to docker-compose.yml in the repo root (for development only)> Go to tools folder and install Postgres versions# Rundiff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex 19e77db2..4cb860a0 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -70,10 +70,6 @@ type EnvVariables struct {PaddlePriceID string `env:"PADDLE_PRICE_ID"`PaddleClientToken string `env:"PADDLE_CLIENT_TOKEN"`- TestGoogleDriveClientID string `env:"TEST_GOOGLE_DRIVE_CLIENT_ID"`- TestGoogleDriveClientSecret string `env:"TEST_GOOGLE_DRIVE_CLIENT_SECRET"`- TestGoogleDriveTokenJSON string `env:"TEST_GOOGLE_DRIVE_TOKEN_JSON"`-TestPostgres12Port string `env:"TEST_POSTGRES_12_PORT"`TestPostgres13Port string `env:"TEST_POSTGRES_13_PORT"`TestPostgres14Port string `env:"TEST_POSTGRES_14_PORT"`@@ -126,13 +122,6 @@ type EnvVariables struct {CloudflareTurnstileSecretKey string `env:"CLOUDFLARE_TURNSTILE_SECRET_KEY"`CloudflareTurnstileSiteKey string `env:"CLOUDFLARE_TURNSTILE_SITE_KEY"`- // testing Supabase- TestSupabaseHost string `env:"TEST_SUPABASE_HOST"`- TestSupabasePort string `env:"TEST_SUPABASE_PORT"`- TestSupabaseUsername string `env:"TEST_SUPABASE_USERNAME"`- TestSupabasePassword string `env:"TEST_SUPABASE_PASSWORD"`- TestSupabaseDatabase string `env:"TEST_SUPABASE_DATABASE"`-// SMTP configuration (optional)SMTPHost string `env:"SMTP_HOST"`SMTPPort int `env:"SMTP_PORT"`@@ -154,7 +143,6 @@ func GetEnv() *EnvVariables {}func loadEnvVariables() {- // Get current working directorycwd, err := os.Getwd()if err != nil {log.Warn("could not get current working directory", "error", err)@@ -175,25 +163,14 @@ func loadEnvVariables() {backendRoot = parent}- envPaths := []string{- filepath.Join(cwd, ".env"),- filepath.Join(backendRoot, ".env"),- }-- var loaded bool- for _, path := range envPaths {- log.Info("Trying to load .env", "path", path)- if err := godotenv.Load(path); err == nil {- log.Info("Successfully loaded .env", "path", path)- loaded = true- break- }- }+ envPath := filepath.Join(filepath.Dir(backendRoot), ".env")- if !loaded {- log.Error("Error loading .env file: could not find .env in any location")+ log.Info("Trying to load .env", "path", envPath)+ if err := godotenv.Load(envPath); err != nil {+ log.Error("Error loading .env file from repo root", "path", envPath, "error", err)os.Exit(1)}+ log.Info("Successfully loaded .env", "path", envPath)err = cleanenv.ReadEnv(&env)if err != nil {diff --git a/backend/internal/features/telemetry/client.go b/backend/internal/features/telemetry/client.goindex 523c68c5..23a541bb 100644--- a/backend/internal/features/telemetry/client.go+++ b/backend/internal/features/telemetry/client.go@@ -42,7 +42,7 @@ func (s *HTTPTelemetrySender) Send(ctx context.Context, req *CollectRequest) err}httpReq.Header.Set("Content-Type", "application/json")- httpReq.Header.Set("User-Agent", "Postgresus-Telemetry/"+s.appVersion)+ httpReq.Header.Set("User-Agent", "Databasus-Telemetry/"+s.appVersion)resp, err := s.httpClient.Do(httpReq)if err != nil {diff --git a/backend/internal/features/telemetry/client_test.go b/backend/internal/features/telemetry/client_test.goindex f619efee..f98e0afd 100644--- a/backend/internal/features/telemetry/client_test.go+++ b/backend/internal/features/telemetry/client_test.go@@ -49,7 +49,7 @@ func Test_Send_PostsCorrectBodyAndHeaders(t *testing.T) {assert.Equal(t, http.MethodPost, captureMethod)assert.Equal(t, "application/json", captureContentType)- assert.True(t, strings.HasPrefix(captureUserAgent, "Postgresus-Telemetry/"))+ assert.True(t, strings.HasPrefix(captureUserAgent, "Databasus-Telemetry/"))assert.Contains(t, captureUserAgent, "9.9.9")assert.Equal(t, *req, captured)}diff --git a/backend/internal/util/logger/logger.go b/backend/internal/util/logger/logger.goindex b0ff8e1c..ad7f94dd 100644--- a/backend/internal/util/logger/logger.go+++ b/backend/internal/util/logger/logger.go@@ -79,14 +79,12 @@ func tryInitVictoriaLogs() *VictoriaLogsWriter {}var ensureEnvLoaded = sync.OnceFunc(func() {- // Get current working directorycwd, err := os.Getwd()if err != nil {fmt.Printf("Warning: could not get current working directory: %v\n", err)cwd = "."}- // Find backend root by looking for go.modbackendRoot := cwdfor {if _, err := os.Stat(filepath.Join(backendRoot, "go.mod")); err == nil {@@ -101,20 +99,14 @@ var ensureEnvLoaded = sync.OnceFunc(func() {backendRoot = parent}- // Try to load .env from various locations- envPaths := []string{- filepath.Join(cwd, ".env"),- filepath.Join(backendRoot, ".env"),- }+ envPath := filepath.Join(filepath.Dir(backendRoot), ".env")- for _, path := range envPaths {- if err := godotenv.Load(path); err == nil {- fmt.Printf("Logger: loaded .env from %s\n", path)- return- }+ if err := godotenv.Load(envPath); err == nil {+ fmt.Printf("Logger: loaded .env from %s\n", envPath)+ return}- fmt.Println("Logger: .env file not found, using existing environment variables")+ fmt.Println("Logger: .env file not found at repo root, using existing environment variables")})func getVictoriaLogsURL() string {diff --git a/backend/docker-compose.yml.example b/docker-compose.example.ymlsimilarity index 85%rename from backend/docker-compose.yml.examplerename to docker-compose.example.ymlindex e7e3b24e..e8f71026 100644--- a/backend/docker-compose.yml.example+++ b/docker-compose.example.yml@@ -1,11 +1,11 @@-version: "3"-services:+ # ================================================================+ # Backend dev services+ # ================================================================+# For development only, because this DB- # exposes it's port to the public- dev-db:- env_file:- - .env+ # exposes its port to the public+ backend-db:image: postgres:17ports:- "5437:5437"@@ -15,18 +15,18 @@ services:- POSTGRES_PASSWORD=${DEV_DB_PASSWORD}volumes:- ./pgdata:/var/lib/postgresql/data- container_name: dev-db+ container_name: backend-dbcommand: -p 5437shm_size: 10gb# Valkey for caching- dev-valkey:+ backend-valkey:image: valkey/valkey:9.0.1-alpineports:- - "${VALKEY_PORT:-6379}:6379"+ - "${VALKEY_PORT}:6379"volumes:- ./valkey-data:/data- container_name: dev-valkey+ container_name: backend-valkeyhealthcheck:test: ["CMD", "valkey-cli", "ping"]interval: 10s@@ -35,9 +35,9 @@ services:start_period: 20s# VictoriaLogs for external logging- victoria-logs:+ backend-victoria-logs:image: victoriametrics/victoria-logs:latest- container_name: victoria-logs+ container_name: backend-victoria-logsports:- "9428:9428"command:@@ -48,12 +48,47 @@ services:- ./victoria-logs-data:/victoria-logs-datarestart: unless-stopped+ # ================================================================+ # Agent dev services+ # ================================================================++ agent-db:+ image: postgres:17+ container_name: agent-db+ environment:+ POSTGRES_DB: devdb+ POSTGRES_USER: devuser+ POSTGRES_PASSWORD: devpassword+ ports:+ - "7433:5432"+ command:+ - bash+ - -c+ - |+ mkdir -p /wal-queue && chown postgres:postgres /wal-queue+ exec docker-entrypoint.sh postgres \+ -c wal_level=replica \+ -c max_wal_senders=3 \+ -c archive_mode=on \+ -c "archive_command=cp %p /wal-queue/%f"+ volumes:+ - ./wal-queue:/wal-queue+ healthcheck:+ test: ["CMD-SHELL", "pg_isready -U devuser -d devdb"]+ interval: 2s+ timeout: 5s+ retries: 30++ # ================================================================+ # Test containers+ # ================================================================+# Test MinIO containertest-minio:image: minio/minio:latestports:- - "${TEST_MINIO_PORT:-9000}:9000"- - "${TEST_MINIO_CONSOLE_PORT:-9001}:9001"+ - "${TEST_MINIO_PORT}:9000"+ - "${TEST_MINIO_CONSOLE_PORT}:9001"environment:- MINIO_ROOT_USER=testuser- MINIO_ROOT_PASSWORD=testpassword@@ -142,7 +177,7 @@ services:test-azurite:image: mcr.microsoft.com/azure-storage/azuriteports:- - "${TEST_AZURITE_BLOB_PORT:-10000}:10000"+ - "${TEST_AZURITE_BLOB_PORT}:10000"container_name: test-azuritecommand: azurite-blob --blobHost 0.0.0.0@@ -150,7 +185,7 @@ services:test-nas:image: dperson/samba:latestports:- - "${TEST_NAS_PORT:-445}:445"+ - "${TEST_NAS_PORT}:445"environment:- USERID=1000- GROUPID=1000@@ -166,7 +201,7 @@ services:test-ftp:image: stilliard/pure-ftpd:latestports:- - "${TEST_FTP_PORT:-21}:21"+ - "${TEST_FTP_PORT}:21"- "30000-30009:30000-30009"environment:- PUBLICHOST=localhost@@ -180,7 +215,7 @@ services:test-sftp:image: atmoz/sftp:latestports:- - "${TEST_SFTP_PORT:-7008}:22"+ - "${TEST_SFTP_PORT}:22"command: testuser:testpassword:1001::uploadcontainer_name: test-sftp@@ -188,7 +223,7 @@ services:test-mysql-57:image: mysql:5.7ports:- - "${TEST_MYSQL_57_PORT:-33057}:3306"+ - "${TEST_MYSQL_57_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -207,7 +242,7 @@ services:test-mysql-80:image: mysql:8.0ports:- - "${TEST_MYSQL_80_PORT:-33080}:3306"+ - "${TEST_MYSQL_80_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -226,7 +261,7 @@ services:test-mysql-84:image: mysql:8.4ports:- - "${TEST_MYSQL_84_PORT:-33084}:3306"+ - "${TEST_MYSQL_84_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -245,7 +280,7 @@ services:test-mysql-90:image: mysql:9.5ports:- - "${TEST_MYSQL_90_PORT:-33090}:3306"+ - "${TEST_MYSQL_90_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -265,7 +300,7 @@ services:test-mariadb-55:image: mariadb:5.5ports:- - "${TEST_MARIADB_55_PORT:-33055}:3306"+ - "${TEST_MARIADB_55_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -284,7 +319,7 @@ services:test-mariadb-101:image: mariadb:10.1ports:- - "${TEST_MARIADB_101_PORT:-33101}:3306"+ - "${TEST_MARIADB_101_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -303,7 +338,7 @@ services:test-mariadb-102:image: mariadb:10.2ports:- - "${TEST_MARIADB_102_PORT:-33102}:3306"+ - "${TEST_MARIADB_102_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -322,7 +357,7 @@ services:test-mariadb-103:image: mariadb:10.3ports:- - "${TEST_MARIADB_103_PORT:-33103}:3306"+ - "${TEST_MARIADB_103_PORT}:3306"environment:- MYSQL_ROOT_PASSWORD=rootpassword- MYSQL_DATABASE=testdb@@ -341,7 +376,7 @@ services:test-mariadb-104:image: mariadb:10.4ports:- - "${TEST_MARIADB_104_PORT:-33104}:3306"+ - "${TEST_MARIADB_104_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -360,7 +395,7 @@ services:test-mariadb-105:image: mariadb:10.5ports:- - "${TEST_MARIADB_105_PORT:-33105}:3306"+ - "${TEST_MARIADB_105_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -379,7 +414,7 @@ services:test-mariadb-106:image: mariadb:10.6ports:- - "${TEST_MARIADB_106_PORT:-33106}:3306"+ - "${TEST_MARIADB_106_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -398,7 +433,7 @@ services:test-mariadb-1011:image: mariadb:10.11ports:- - "${TEST_MARIADB_1011_PORT:-33111}:3306"+ - "${TEST_MARIADB_1011_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -417,7 +452,7 @@ services:test-mariadb-114:image: mariadb:11.4ports:- - "${TEST_MARIADB_114_PORT:-33114}:3306"+ - "${TEST_MARIADB_114_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -436,7 +471,7 @@ services:test-mariadb-118:image: mariadb:11.8ports:- - "${TEST_MARIADB_118_PORT:-33118}:3306"+ - "${TEST_MARIADB_118_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -455,7 +490,7 @@ services:test-mariadb-120:image: mariadb:12.0ports:- - "${TEST_MARIADB_120_PORT:-33120}:3306"+ - "${TEST_MARIADB_120_PORT}:3306"environment:- MARIADB_ROOT_PASSWORD=rootpassword- MARIADB_DATABASE=testdb@@ -476,7 +511,7 @@ services:image: mongo:4.0container_name: test-mongodb-40ports:- - "${TEST_MONGODB_40_PORT:-27040}:27017"+ - "${TEST_MONGODB_40_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -492,7 +527,7 @@ services:image: mongo:4.2container_name: test-mongodb-42ports:- - "${TEST_MONGODB_42_PORT:-27042}:27017"+ - "${TEST_MONGODB_42_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -508,7 +543,7 @@ services:image: mongo:4.4container_name: test-mongodb-44ports:- - "${TEST_MONGODB_44_PORT:-27044}:27017"+ - "${TEST_MONGODB_44_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -524,7 +559,7 @@ services:image: mongo:5.0container_name: test-mongodb-50ports:- - "${TEST_MONGODB_50_PORT:-27050}:27017"+ - "${TEST_MONGODB_50_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -540,7 +575,7 @@ services:image: mongo:6.0container_name: test-mongodb-60ports:- - "${TEST_MONGODB_60_PORT:-27060}:27017"+ - "${TEST_MONGODB_60_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -556,7 +591,7 @@ services:image: mongo:7.0container_name: test-mongodb-70ports:- - "${TEST_MONGODB_70_PORT:-27070}:27017"+ - "${TEST_MONGODB_70_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassword@@ -572,7 +607,7 @@ services:image: mongo:8.2.3-noblecontainer_name: test-mongodb-82ports:- - "${TEST_MONGODB_82_PORT:-27082}:27017"+ - "${TEST_MONGODB_82_PORT}:27017"environment:MONGO_INITDB_ROOT_USERNAME: rootMONGO_INITDB_ROOT_PASSWORD: rootpassworddiff --git a/docker-compose.yml.example b/docker-compose.image.example.ymlsimilarity index 100%rename from docker-compose.yml.examplerename to docker-compose.image.example.ymldiff --git a/frontend/.env.development.example b/frontend/.env.development.exampledeleted file mode 100644index 40a40173..00000000--- a/frontend/.env.development.example+++ /dev/null@@ -1,9 +0,0 @@-MODE=development-VITE_GITHUB_CLIENT_ID=-VITE_GOOGLE_CLIENT_ID=-VITE_IS_EMAIL_CONFIGURED=false-VITE_CLOUDFLARE_TURNSTILE_SITE_KEY=-VITE_IS_CLOUD=false-VITE_CLOUD_PRICE_PER_GB=-VITE_CLOUD_PADDLE_CLIENT_TOKEN=-VITE_CLOUD_IS_PADDLE_SANDBOX=true\ No newline at end of filediff --git a/frontend/.env.production.example b/frontend/.env.production.exampledeleted file mode 100644index 923c1a23..00000000--- a/frontend/.env.production.example+++ /dev/null@@ -1 +0,0 @@-MODE=production\ No newline at end of filediff --git a/frontend/vite.config.ts b/frontend/vite.config.tsindex 05b56b74..315a077a 100644--- a/frontend/vite.config.ts+++ b/frontend/vite.config.ts@@ -4,5 +4,6 @@ import { defineConfig } from 'vite';// https://vite.dev/config/export default defineConfig({+ envDir: '../',plugins: [react(), tailwindcss()],});