Skip to main content

OLX database models and migrations

Project description

OLX Database Package

A Python package for OLX database models and migrations.

Installation

pip install olx-db-wonsky

For development installation:

# Install package in development mode
pip install -e .

# Install development dependencies (including Alembic for migrations)
pip install -r requirements-dev.txt

Configuration

The package uses environment variables for configuration:

  • OLX_DB_URL: Database URL (required)
  • OLX_DEFAULT_SENDING_FREQUENCY_MINUTES: Default sending frequency in minutes (default: 60)
  • OLX_DEFAULT_LAST_MINUTES_GETTING: Default last minutes for getting items (default: 30)

You can set these environment variables directly or use a .env file.

Usage

Database Models

from olx_db.db import get_db, MonitoringTask, ItemRecord

# Use the database session
with next(get_db()) as db:
    tasks = db.query(MonitoringTask).all()
    # ...

Migrations

Local Development

For local development, use the provided script:

# Create a new migration
python scripts/run_migrations.py makemigrations "migration message"

# Apply migrations
python scripts/run_migrations.py migrate

Docker

To run migrations in Docker:

# Start the database and run migrations
docker-compose up migrations

# Or build and run locally
./scripts/build_and_run_local.sh

Building and Publishing Docker Image

To build and push the migrations Docker image to Docker Hub:

# Build and push for multiple architectures (amd64, arm64)
./scripts/build_and_push.sh

Project Structure

├── alembic/                 # Alembic migrations
│   └── versions/            # Migration versions
├── olx_db/                  # Main package
│   └── db/                  # Database models and functions
├── scripts/                 # Utility scripts
│   ├── run_migrations.py    # Script to run migrations
│   ├── build_and_push.sh    # Script to build and push Docker image
│   └── build_and_run_local.sh # Script to build and run locally
├── alembic.ini              # Alembic configuration
├── docker-compose.yml       # Docker Compose configuration
├── migrations.Dockerfile    # Dockerfile for migrations
└── pyproject.toml           # Package configuration

Docker Support

Example docker-compose.yml:

version: '3'

services:
  db:
    image: postgres:13
    environment:
      - POSTGRES_USER=myuser
      - POSTGRES_PASSWORD=mypassword
      - POSTGRES_DB=mydatabase
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  migrations:
    build:
      context: .
      dockerfile: migrations.Dockerfile
    environment:
      - OLX_DB_URL=postgresql://myuser:mypassword@db:5432/mydatabase
    depends_on:
      - db
    command: python /app/scripts/run_migrations.py migrate

volumes:
  postgres_data:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

olx_db_wonsky-1.1.6.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

olx_db_wonsky-1.1.6-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file olx_db_wonsky-1.1.6.tar.gz.

File metadata

  • Download URL: olx_db_wonsky-1.1.6.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for olx_db_wonsky-1.1.6.tar.gz
Algorithm Hash digest
SHA256 cd12b09c7eda2a7e2582ceed15b61252a31be719d306361fa50fd282d2beccd4
MD5 de2400be48d0d7a1472c9cab8d6aaf1a
BLAKE2b-256 a92a06e4ff940697f3ac7dce278c6404fe40e88fe3a9d947ae2436b9dde08c2c

See more details on using hashes here.

File details

Details for the file olx_db_wonsky-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: olx_db_wonsky-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for olx_db_wonsky-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 222542fdb3c2cdc305b07aa4ef49ac0897c127e728cd96c027c76959dc1d83ab
MD5 72d9f6f2d08d6d12887e796e6612aefd
BLAKE2b-256 07780c6a5bdde3cf3f4bf87af45acbdd412f82856c75dd032cbd8613f9243a53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page