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

Uploaded Python 3

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 e3c62b06a2eabf64ad36402ebb73c34b6137f38086c4d235c74125b01e888392
MD5 f86e597cabfeca8b22b54cdb5a4a6393
BLAKE2b-256 fa73c338f9b42946339b96ca9ec8f2565200d935ec9552fadb10e7699f8a400f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: olx_db_wonsky-1.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a3773b369624d6f77e3d5885f2ac585775f8fee3848147d789da2ec05ec66f1
MD5 58cae01e8e7b2dcd29287527b3c98d33
BLAKE2b-256 c5a8b33193f02145a7a5f0abdf4800e1d19ae31d7a380fbf3d565a3d6492704d

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