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.8.tar.gz (12.1 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.8-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.8.tar.gz
  • Upload date:
  • Size: 12.1 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.8.tar.gz
Algorithm Hash digest
SHA256 52d12ac01aba65252475e0c1f4b8c2b56669372f8a7b3f8a15b729dc6fda5cd2
MD5 442d91a5bc1b2c445bb131030577ea53
BLAKE2b-256 cdd1b0fda6ab29d84f9f11751d045e097ac0dc216cc50c21507ad517e93e5fc2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.8-py3-none-any.whl
  • Upload date:
  • Size: 12.4 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5f67f8c31c06f82948d9dbb73174d7ddb5d9abcb2f5da31557d6f8fc2a3deb73
MD5 ada7463ef387e0f7ac2778c281c9cdb8
BLAKE2b-256 aa52ee54abfb6b94b570b34b2a1fa3817ae85742a1f4a81c7b968d1c0db01c38

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