Skip to main content

Vinyl DB Setup

Project description

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

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

vinyl_models-0.5.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vinyl_models-0.5.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file vinyl_models-0.5.0.tar.gz.

File metadata

  • Download URL: vinyl_models-0.5.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for vinyl_models-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4d9d05411b93152dc02cf4040cc896299d4bd254779f015d2c34466916fd788b
MD5 d57d61869607d7ef84122ce462305c67
BLAKE2b-256 c4ca15c3cb71cfffd2c4e8b0d8ed0e51e70e3a6a16244e321191b2dc434ba8ab

See more details on using hashes here.

File details

Details for the file vinyl_models-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: vinyl_models-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for vinyl_models-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b98db37395e1601d84f3b2d837a4b2562b843c12b9e19af748726cbd3d517588
MD5 d32cf00ba989d62d9bfcfbd9a089d8fb
BLAKE2b-256 af3b1dec24774e93e40ec56ee54cf79346ac83810d68150fe252caa772d071af

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