TracLine supports both PostgreSQL and SQLite databases. This guide explains how to configure databases and switch between different database types.
TracLine is configured to use PostgreSQL by default. The standard configuration is as follows:
database:
type: postgresql
host: localhost
port: 5432
database: tracline
user: postgres
password: postgres # Use environment variables in productionYou can change the database type by editing the tracline.yaml configuration file.
PostgreSQL Configuration Example:
database:
type: postgresql
host: localhost
port: 5432
database: tracline
user: postgres
password: postgresSQLite Configuration Example:
database:
type: sqlite
url: ~/.tracline/tracline.db # Path to database fileYou can set environment variables to override configuration file settings:
# Specify database type
export TRACLINE_DB_TYPE=sqlite
# Specify SQLite path (if needed)
export TRACLINE_DB_URL=~/.tracline/custom.db
# Or specify PostgreSQL credentials
export TRACLINE_DB_HOST=localhost
export TRACLINE_DB_PORT=5432
export TRACLINE_DB_NAME=tracline
export TRACLINE_DB_USER=postgres
export TRACLINE_DB_PASSWORD=your_password- Ensure PostgreSQL is installed
- Initialize the database with the following command:
python setup_postgres.pyOr use the web application startup script:
cd web
./start_postgres_app.shThis script automatically configures PostgreSQL and initializes the database as needed.
SQLite is automatically initialized. After editing the configuration file as shown below, simply start the application and the database file will be created automatically:
database:
type: sqlite
url: ~/.tracline/tracline.dbTo migrate data from SQLite to PostgreSQL, you can use the following script:
python sqlite_to_postgresql.py --source ~/.tracline/tracline.db-
Consistent Database Usage: Do not mix database types within the same application instance.
-
Proper Connection Management: Database connections are managed automatically, but for long-running scripts, consider explicitly calling
connect()anddisconnect(). -
Environment Variable Scope: Environment variables are only effective within the shell session scope. Use configuration files for persistent changes.
-
Password Security: In production environments, do not write database passwords directly in configuration files. Use environment variables (
TRACLINE_DB_PASSWORD) instead.