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.5.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.5-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 4cef8cb0bace61aa8d1a8f65ea5c607755a85cd87a32315cf926e022d45e49c0
MD5 6186632037335d89e1da27fec8081beb
BLAKE2b-256 0c7b063c6ef96bd8242d14900fd87411b349ce19a4c7edb85658ecfc35af9a9f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.5-py3-none-any.whl
  • Upload date:
  • Size: 17.9 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 2319c411a8e21aeafc09528c2588916bee96ccdf37cb3fe6fbd7357bdf7834e5
MD5 3843d5dba177fb1045db6fc2e879d5ef
BLAKE2b-256 ebde37a4f5a5c17c1e104360d7a6c3198dd84e9171b61bf2acde68a38d79156c

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