Skip to main content

Vinyl Models


Project for my learning purposes only. If you stumbled here looking for meaning of life, I'm afraid you're in the wrong place. (I have it on good authority that it's 42.)

Technical Aim

  • To create a database and host it on a cloud
    • To learn SQL migrations
    • To learn local testing via docker
  • To create pythonic ORM (SQLAlchemy) models that will allow easier interaction with the database
  • To write tests to validate both the DB setup as well as the models
  • To enable CI/CD pipeline for the project
  • To learn what exacltly is RESTful API and apply it here

Non-Technical Aim?

This is the first repo in series of Vinyl Value Vault project. This is the backend of the project providing database of vinyl records in my collection along with pricing information and market information. It adds API on top to allow for easy interaction with the data.

Database


Platform of choice is Supabase. It's a PostgreSQL database with a free tier that's easy to set up and has a nice UI. It masks a lot of the complexity and provides a nice CLI tool with which you can interact quite easily both locally and on GitHub CI pipeline.

SQL Migrations

Those are managed by Supabase directly. In a project repo:

supabase migration new "migration_name"

Upon local or remote DB update Supabase keeps tracks of already applied migrations and only applies new ones. Neat! For human readbility I have adopted VX.X.X versioning style on top of datetime enforced by Supabase.

Good docs on migrations are here

ORM Models

For that I have chosen SQLAlchemy, since I already know it a little from work. This is a fairly simple tool to use, but it is somewhat frustrating that it requires you to double yur DB definition - once in SQL migrations and then to be reproduced in python models. Here is an idea for a future project...

Tests


Using pytest. Only 'obstacle' here was testing with docker for the first time. Supabase does provide its own CLI tool for testing - however that only tests the DB setup itself. It basically executes SQL queries on seeded data and checks for the output. This is handy indeed... Good unit tests.

I am lazy and don't want to first test the SQL and then Python. I am just doing it all at once and reading the error message, likely it will have good info to tell you if its your SQL or Python that it broken.

Again, when deploying migrations locally, supabase seeds the DB with your script as well so the data is available for pytest to pick up. Then using a few fixtures I am connecting to the local DB running in a docker container and I am querying it using my SQLAlchemy models. Two birds one stone.

CI/CD


Now that was tricky. I have three GitHub Actions workflows:

  • one for basic validation on the Pull Request
    • check dependencies are all valid
    • check version in __init__.py
    • lint python and SQL
    • run tests
    • build
    • deploy to test.pypi
  • one for Supabase migrations to remote when merging
  • one for package deployment to pypi when merging

God bless DevOps engineerings for making this easier in a workplace. The setup I have is very crude, and I fear the day when I will have to open up new repo and run the setup again. Another proejct idea for the future: create template repos for future projects...

RESTful API


WiP

Metadata

Release files for vinyl-models 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vinyl-models 0.5.0
File Size Uploaded
vinyl_models-0.5.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vinyl-models 0.5.0
File Interpreter ABI Platform
vinyl_models-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / vinyl_models-0.5.0.tar.gz

Download URL vinyl_models-0.5.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4d9d05411b93152dc02cf4040cc896299d4bd254779f015d2c34466916fd788b
BLAKE2b-256 checksum
How to use checksums
c4ca15c3cb71cfffd2c4e8b0d8ed0e51e70e3a6a16244e321191b2dc434ba8ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release files / vinyl_models-0.5.0-py3-none-any.whl

Download URL vinyl_models-0.5.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b98db37395e1601d84f3b2d837a4b2562b843c12b9e19af748726cbd3d517588
BLAKE2b-256 checksum
How to use checksums
af3b1dec24774e93e40ec56ee54cf79346ac83810d68150fe252caa772d071af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.17

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page