Skip to content

Latest commit

 

History

History
207 lines (154 loc) · 5.46 KB

File metadata and controls

207 lines (154 loc) · 5.46 KB

SCMD PostgreSQL Upgrade Summary

What Was Changed

Your SCMD project has been successfully upgraded from SQLite (tardigrade.db) to PostgreSQL!

Files Modified

  1. go.mod - Added PostgreSQL dependencies:

    • github.com/lib/pq - PostgreSQL driver
    • github.com/joho/godotenv - Environment variable management
  2. database.go (NEW) - PostgreSQL database layer:

    • InitDB() - Initializes PostgreSQL connection from .env
    • CloseDB() - Closes database connection
    • SearchCommands() - Searches commands with pattern matching
    • AddCommand() - Adds new commands to database
    • CheckCommandExists() - Checks for duplicate commands
  3. search.go - Updated CLI search:

    • Removed tardigrade-mod dependency
    • Now uses PostgreSQL SearchCommands()
    • Maintains same output format
  4. savecmd.go - Updated CLI save:

    • Removed tardigrade-mod dependency
    • Now uses PostgreSQL AddCommand()
    • Improved error handling
  5. server.go - Updated web interface:

    • Removed tardigrade-mod dependency
    • HomePage() now uses PostgreSQL for searches
    • AddPage() now uses PostgreSQL for saving commands
    • Database connection initialized at server startup
  6. tools.go - Updated utility functions:

    • Removed tardigrade-mod dependency
    • copyDB() now shows pg_dump instructions
  7. download.go - Updated download function:

    • Now shows migration instructions instead of downloading tardigrade.db

Files Created

  1. .env.example - Template for database configuration
  2. POSTGRESQL_MIGRATION.md - Detailed migration guide
  3. UPGRADE_SUMMARY.md - This file
  4. test_connection.go - Connection test utility
  5. interactive.go - NEW Interactive CLI mode with natural language support
  6. INTERACTIVE_MODE.md - Interactive mode documentation
  7. QUICKSTART.md - Quick start guide

Files Updated

  1. README.md - Updated with PostgreSQL information

How to Use

1. Verify Your .env File

Make sure your .env file has the correct PostgreSQL credentials:

DB_HOST=192.168.1.4
DB_PORT=5432
DB_USER=user_name
DB_PASS=password
DB_NAME=database_name
TB_NAME=scmd

2. Test the Connection

You can test the PostgreSQL connection with:

go run test_connection.go database.go

3. Use the Application

NEW: Interactive Mode

Start an interactive CLI session:

scmd.exe --interactive
# or
scmd.exe -i

Then use natural language or commands:

scmd> provide me with postgresql replication example
scmd> /search docker,kubernetes
scmd> /add docker ps -a | List all containers
scmd> /list
scmd> exit

See INTERACTIVE_MODE.md for full documentation.

Traditional CLI

All existing commands work the same:

CLI Search:

scmd.exe --search "docker"
scmd.exe --search "docker,kubernetes"

CLI Save:

scmd.exe --save "docker ps -a" "List all containers"

Web Interface:

scmd.exe --web
scmd.exe --web -port 8080
scmd.exe --web -port 8080 -block

Database Schema

Your PostgreSQL table should have this structure:

CREATE TABLE scmd (
    id SERIAL PRIMARY KEY,
    key TEXT NOT NULL,
    data TEXT NOT NULL
);

Optional indexes for better performance:

CREATE INDEX idx_scmd_key ON scmd USING gin(to_tsvector('english', key));
CREATE INDEX idx_scmd_data ON scmd USING gin(to_tsvector('english', data));

Key Features

Case-insensitive search - Uses PostgreSQL ILIKE ✓ Multiple pattern search - Comma-separated patterns ✓ Duplicate detection - Checks before inserting ✓ Connection pooling - Efficient database connections ✓ Error handling - Proper error logging ✓ Environment-based config - Easy deployment

Migration Checklist

  • Update dependencies in go.mod
  • Create PostgreSQL database layer
  • Update CLI search functionality
  • Update CLI save functionality
  • Update web interface
  • Remove tardigrade-mod dependencies
  • Create configuration templates
  • Update documentation
  • Build and test compilation

Next Steps

  1. Test the connection - Run test_connection.go
  2. Test CLI search - Try searching for existing commands
  3. Test CLI save - Try adding a new command
  4. Test web interface - Start the web server and test search/add
  5. Monitor logs - Check scmdweb.log for any issues

Troubleshooting

"Failed to connect to database"

  • Verify PostgreSQL is running
  • Check .env credentials
  • Test with: psql -h DB_HOST -p DB_PORT -U DB_USER -d DB_NAME

"Table does not exist"

  • Verify table name in .env matches your PostgreSQL table
  • Check table exists: \dt in psql

"No results found"

  • Verify data was imported from tardigrade.db
  • Check table has data: SELECT COUNT(*) FROM scmd;

Benefits of PostgreSQL

  1. Scalability - Handle millions of commands
  2. Concurrent access - Multiple users simultaneously
  3. Full-text search - Better search capabilities
  4. Backup/restore - Enterprise-grade tools
  5. Remote access - Access from anywhere
  6. ACID compliance - Data integrity guaranteed

Backward Compatibility

The old tardigrade.db file is no longer used. All functionality remains the same from a user perspective - only the backend storage has changed.

Support

For issues or questions:

  1. Check POSTGRESQL_MIGRATION.md for detailed migration info
  2. Review the .env.example for configuration reference
  3. Test connection with test_connection.go
  4. Check PostgreSQL logs for database errors