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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file olx_db_wonsky-1.1.7.tar.gz.
File metadata
- Download URL: olx_db_wonsky-1.1.7.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6e45cc095b67ef327ff5b679774451651827f93402533e86e367856f8dada74
|
|
| MD5 |
ba1001e05b7ea1ecf8afd930b68ebd08
|
|
| BLAKE2b-256 |
25fe21cdcd72e91b5ef305289f5a8e70f99107b8eee05fa4772832d9b9bc0581
|
File details
Details for the file olx_db_wonsky-1.1.7-py3-none-any.whl.
File metadata
- Download URL: olx_db_wonsky-1.1.7-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
321b535aedd8691a3b75b50fbc478bb7d3ad60a8e12ff4aeac5383087e2c2613
|
|
| MD5 |
912c58ccabae25704f96d9e01bda54cc
|
|
| BLAKE2b-256 |
8f0f19fadacfe1402ee1a4f244cd3161455131f29b065259483817823aebdcde
|