A Django app that connects to a replica of the MusicBrainz database.
Project description
Django MusicBrainz Connector
The Django MusicBrainz Connector is a Django app that connects to a replica of the MusicBrainz database.
Installation
-
Using the Django MusicBrainz Connector requires that you have a replica of the MusicBrainz database. You can create one by following the installation steps in the MusicBrainz Server.
-
Install this module from code:
git clone git@github.com:marios-zindilis/django-musicbrainz-connector.git cd django-musicbrainz-connector python setup.py sdist python -m pip install dist/django-musicbrainz-connector-0.0.1.tar.gz
-
Append the app to your Django project's
settings.py
list ofINSTALLED_APPS
, for example:INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_musicbrainz_connector', # <-- ]
-
Create a read-only user in the MusicBrainz Postgresql replica database. This step is not required, but it is highly recommended. Example commands:
\c musicbrainz_db CREATE USER django_musicbrainz_connector WITH PASSWORD 'sUp3rSecr3t'; GRANT CONNECT ON DATABASE musicbrainz_db TO django_musicbrainz_connector; GRANT USAGE ON SCHEMA musicbrainz TO django_musicbrainz_connector; GRANT SELECT ON ALL TABLES IN SCHEMA musicbrainz TO django_musicbrainz_connector; ALTER USER django_musicbrainz_connector SET SEARCH_PATH TO musicbrainz;
You can confirm this with something like:
SELECT grantee, privilege_type FROM information_schema.role_table_grants WHERE table_name='area_type';
The output should include the user you just created:
grantee | privilege_type ------------------------------+---------------- musicbrainz | INSERT musicbrainz | SELECT musicbrainz | UPDATE musicbrainz | DELETE musicbrainz | TRUNCATE musicbrainz | REFERENCES musicbrainz | TRIGGER django_musicbrainz_connector | SELECT
You can also connect to the database with
psql
:psql -d musicbrainz_db -U django_musicbrainz_connector SELECT * FROM musicbrainz.area_type;
-
Add the MusicBrainz database to your Django project's
settings.py
list ofDATABASES
. You shouldn't use the MusicBrainz database as the Django default database, because this app is only meant to have read access. For example:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', }, 'musicbrainz_db': { 'NAME': "musicbrainz_db", "ENGINE": "django.db.backends.postgresql", "USER": "django_musicbrainz_connector", "PASSWORD": "sUp3rSecr3t", }, }
-
Add the database router to your Django project's
settings.py
list ofDATABASE_ROUTERS
, for example:DATABASE_ROUTERS = [ "django_musicbrainz_connector.routers.DjangoMusicBrainzConnectorDatabaseRouter", ]
-
Apply the migrations. This doesn't make any changes to the MusicBrainz database:
python manage.py migrate
-
Include the URLs in your Django project's
urls.py
, for example:urlpatterns = [ path("admin/", admin.site.urls), path("mb/", include("django_musicbrainz_connector.urls")), # <-- # other stuff here ]
Notes on Read-Only Access
This app provides read-only connectivity to the database, because it assumes that you maintain a replica of the MusicBrainz Postgresql database, and therefore it makes no sense to be able to write to it. This is done in several ways:
-
It is recommended that you create a read-only user in Postgresql, and use that user for this app. The installation documentation includes step-by-step instructions for this.
-
All models have
Meta.managed
set toFalse
. -
For models registered in the Django Admin, methods
has_add_permission
,has_change_permission
andhas_delete_permission
are always set toFalse
. -
All classes that inherit from Django REST Framework's
ViewSet
havehttp_method_names
set to["get"]
only.
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
Hashes for django-musicbrainz-connector-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3804f33ea46e87182350beda1506babd4b889ba797a0647b9fe8f877a33f8d6d |
|
MD5 | 4f490b4df732d28de376187ed2b6bd2b |
|
BLAKE2b-256 | bb7fabe24b0c63135a861a0c9ee1309b6051243b0b9e443395eb19b8209697bc |
Hashes for django_musicbrainz_connector-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef0485359ce74108892278a377c54ef9ea9c619c3423c9c7f5a9be1bbe220e0 |
|
MD5 | d712f4e36ffe762a07416a52a1ba2569 |
|
BLAKE2b-256 | c04267ac2e5f2552578c93436eef861c4f42f06e4b858590b9be89a5b6b70286 |