Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: metabrainz/mbdata
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v27.1.0
Choose a base ref
...
head repository: metabrainz/mbdata
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v29.0.0
Choose a head ref
  • 14 commits
  • 62 files changed
  • 4 contributors

Commits on Dec 2, 2022

  1. Copy the full SHA
    fede8e9 View commit details
  2. More mypy typing

    lalinsky committed Dec 2, 2022
    Copy the full SHA
    bc2e240 View commit details
  3. Copy the full SHA
    a1a9117 View commit details
  4. Fix long options in mbslave

    Fixes #29
    lalinsky committed Dec 2, 2022
    Copy the full SHA
    0c5fc76 View commit details
  5. Copy the full SHA
    24c88dc View commit details
  6. Add note on PostreSQL auth

    lalinsky committed Dec 2, 2022
    Copy the full SHA
    229531e View commit details
  7. Add README

    lalinsky committed Dec 2, 2022
    Copy the full SHA
    466c2fb View commit details

Commits on Dec 3, 2022

  1. Fix the recent changes to mbslave sync

    Fixes #56
    lalinsky committed Dec 3, 2022
    1
    Copy the full SHA
    ea0e7e2 View commit details

Commits on May 5, 2023

  1. Fix typo (#65)

    reosarevok authored May 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2043c41 View commit details

Commits on May 6, 2023

  1. Bump sqlparse from 0.4.2 to 0.4.4 (#63)

    Bumps [sqlparse](https://github.com/andialbrecht/sqlparse) from 0.4.2 to 0.4.4.
    - [Release notes](https://github.com/andialbrecht/sqlparse/releases)
    - [Changelog](https://github.com/andialbrecht/sqlparse/blob/master/CHANGELOG)
    - [Commits](andialbrecht/sqlparse@0.4.2...0.4.4)
    
    ---
    updated-dependencies:
    - dependency-name: sqlparse
      dependency-type: direct:development
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored May 6, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    45345bb View commit details
  2. Remove mbslave

    lalinsky committed May 6, 2023
    Copy the full SHA
    9198e44 View commit details
  3. Copy the full SHA
    0406f63 View commit details

Commits on Jul 26, 2024

  1. Update python version list for CI testing

    Newer versions of poetry only support Python 3.8+.
    amCap1712 authored Jul 26, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    81ccd5f View commit details
  2. Update to MB DB Schema 29 - 2024 Q2

    amCap1712 committed Jul 26, 2024
    Copy the full SHA
    37d507a View commit details
Showing with 711 additions and 15,443 deletions.
  1. +0 −49 .github/workflows/build-mbslave-container-image.yml
  2. +1 −38 .github/workflows/test.yml
  3. +5 −0 CHANGELOG.rst
  4. +0 −22 Dockerfile.mbslave
  5. +0 −1 MANIFEST.in
  6. +3 −160 README.rst
  7. +0 −1 check.sh
  8. +1 −1 mbdata/__init__.py
  9. +48 −55 mbdata/models.py
  10. +0 −801 mbdata/replication.py
  11. +3 −2 mbdata/sql/CreateConstraints.sql
  12. +20 −40 mbdata/sql/CreateFKConstraints.sql
  13. +23 −20 mbdata/sql/CreateFunctions.sql
  14. +5 −1 mbdata/sql/CreateIndexes.sql
  15. +3 −4 mbdata/sql/CreatePrimaryKeys.sql
  16. +27 −29 mbdata/sql/CreateTables.sql
  17. +0 −3 mbdata/sql/CreateTriggers.sql
  18. +2 −0 mbdata/sql/CreateTypes.sql
  19. +4 −7 mbdata/sql/DropFKConstraints.sql
  20. +0 −1 mbdata/sql/DropFunctions.sql
  21. +2 −0 mbdata/sql/DropIndexes.sql
  22. +3 −4 mbdata/sql/DropPrimaryKeys.sql
  23. +3 −4 mbdata/sql/DropTables.sql
  24. +0 −1 mbdata/sql/DropTriggers.sql
  25. +1 −0 mbdata/sql/DropTypes.sql
  26. +21 −16 mbdata/sql/InsertTestData.sql
  27. +1 −0 mbdata/sql/SetSequences.sql
  28. +3 −4 mbdata/sql/TruncateTables.sql
  29. +0 −148 mbdata/sql/caa/CreateMQTriggers.sql
  30. +0 −19 mbdata/sql/caa/DropMQTriggers.sql
  31. +0 −13 mbdata/sql/dbmirror2/MasterSetup.sql
  32. +1 −1 mbdata/sql/dbmirror2/README
  33. +0 −161 mbdata/sql/eaa/CreateMQTriggers.sql
  34. +0 −21 mbdata/sql/eaa/DropMQTriggers.sql
  35. +3 −2 mbdata/sql/updates/20130309-migrate-transclusion-table.pl
  36. +2 −1 mbdata/sql/updates/20130313-bcrypt-passwords.pl
  37. +0 −16 mbdata/sql/updates/20130322-init-bundled-replication.pl
  38. +1 −1 mbdata/sql/updates/20130724-refresh-release_meta-asin.sql
  39. +2 −1 mbdata/sql/updates/20130906-materialise-recording-lengths.pl
  40. +0 −162 mbdata/sql/updates/20220207-mbs-12224-mirror.sql
  41. +162 −0 mbdata/sql/updates/20220207-mbs-12224-standalone.sql
  42. +0 −1,844 mbdata/sql/updates/schema-change/20.mirror.sql
  43. +0 −644 mbdata/sql/updates/schema-change/20.standalone.sql
  44. +0 −1,160 mbdata/sql/updates/schema-change/21.mirror.sql
  45. +0 −228 mbdata/sql/updates/schema-change/21.standalone.sql
  46. +0 −574 mbdata/sql/updates/schema-change/22.mirror.sql
  47. +0 −435 mbdata/sql/updates/schema-change/22.standalone.sql
  48. +0 −10 mbdata/sql/updates/schema-change/23.extensions.sql
  49. +0 −549 mbdata/sql/updates/schema-change/23.mirror.sql
  50. +0 −155 mbdata/sql/updates/schema-change/23.standalone.sql
  51. +0 −816 mbdata/sql/updates/schema-change/24.mirror.sql
  52. +0 −432 mbdata/sql/updates/schema-change/24.standalone.sql
  53. +0 −718 mbdata/sql/updates/schema-change/25.mirror.sql
  54. +0 −155 mbdata/sql/updates/schema-change/25.standalone.sql
  55. +0 −1,165 mbdata/sql/updates/schema-change/26.mirror.sql
  56. +0 −177 mbdata/sql/updates/schema-change/26.standalone.sql
  57. +0 −2,040 mbdata/sql/updates/schema-change/27.mirror.sql
  58. +0 −2,301 mbdata/sql/updates/schema-change/27.standalone.sql
  59. +0 −24 mbdata/tests/test_replication.py
  60. +0 −24 mbslave.conf.default
  61. +358 −175 poetry.lock
  62. +3 −7 pyproject.toml
49 changes: 0 additions & 49 deletions .github/workflows/build-mbslave-container-image.yml

This file was deleted.

39 changes: 1 addition & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: [ '3.7', '3.8', '3.9', '3.10' ]
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ]
steps:
- uses: actions/checkout@v2
- name: Install Python
@@ -22,40 +22,3 @@ jobs:
run: poetry install
- name: Run tests
run: ./check.sh

mbslave_initdb_test:
runs-on: ubuntu-latest
services:
postgresql:
image: postgres
ports:
- 5432/tcp
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: notapassword
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install application dependencies
run: poetry install
- name: Run `mbslave init`
run: poetry run mbslave init --create-user --create-database --empty
env:
MBSLAVE_DB_HOST: 127.0.0.1
MBSLAVE_DB_PORT: ${{ job.services.postgresql.ports['5432'] }}
MBSLAVE_DB_NAME: musicbrainz
MBSLAVE_DB_USER: musicbrainz
MBSLAVE_DB_PASSWORD: reallynotapassword
MBSLAVE_DB_ADMIN_USER: postgres
MBSLAVE_DB_ADMIN_PASSWORD: notapassword
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 29.0.0
==============

- Schema change 29.

Version 27.1.0
==============

22 changes: 0 additions & 22 deletions Dockerfile.mbslave

This file was deleted.

1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
recursive-include mbdata/web/static *
recursive-include mbdata/sql *
include mbslave.conf.default
163 changes: 3 additions & 160 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,169 +1,12 @@
##########################
MusicBrainz Database Tools
##########################
#############################
MusicBrainz SQLAlchemy Models
#############################

|pypi badge|

.. |pypi badge| image:: https://badge.fury.io/py/mbdata.svg
:target: https://badge.fury.io/py/mbdata

***************************
MusicBrainz Database Mirror
***************************

This repository now contains a collection of scripts for managing a
replica of the MusicBrainz database. These used to be called "mbslave",
but have been moved to this repository.

The main motivation for these scripts is to be able to customize
your database. If you don't need such customizations, it might be
easier to use the replication tools provided by MusicBrainz itself.

Installation
============

You need to have `Python 3.x <https://python.org/>`__ installed on your system.
You can use `pipx <https://pypa.github.io/pipx/>`__ to install this package::

sudo apt install python3 pipx
pipx install 'mbdata[replication]'

There are two ways to configure the application.

1. You can use a config file::

curl https://raw.githubusercontent.com/acoustid/mbdata/main/mbslave.conf.default -o mbslave.conf
vim mbslave.conf

By default, the ``mbslave`` script will look for the config file in the current directory.
If you want it to find it from anywhere, either save it to ``/etc/mbslave.conf`` or
set the ``MBSLAVE_CONFIG`` environment variable. For example:::

export MBSLAVE_CONFIG=/usr/local/etc/mbslave.conf

2. Alternativelly, you can use using environment variables::

export MBSLAVE_DB_HOST=127.0.0.1
export MBSLAVE_DB_PORT=5432
export MBSLAVE_DB_NAME=musicbrainz
export MBSLAVE_DB_USER=musicbrainz
export MBSLAVE_DB_PASSWORD=XXX
export MBSLAVE_DB_ADMIN_USER=postgres
export MBSLAVE_DB_ADMIN_PASSWORD=XXX

Database Setup
==============

If you are starting from scratch and want a full copy of the MusicBrainz database,
you can use the ``mbslave init`` command. This will create a new database and
populate it with the latest data from the MusicBrainz database::

mbslave init --create-user --create-database

The other option is to create the database manually and use the ``mbslave psql``
to apply the scripts from MusicBrainz. In this case you are expected to know what
you are doing.

Database Replication
====================

You can also keep the database up-to-date by applying incrementa changes.

You need get an API token from the `MetaBrainz website <https://metabrainz.org/supporters/account-type>`__ and you
need to either add it to `mbslave.conf` or set the ``MBSLAVE_MUSICBRAINZ_TOKEN`` environment variable.

After that, you can use the ``mbslave sync`` command to download the latest updates::

mbslave sync

Schema Upgrade
==============

When the MusicBrainz database schema changes, the replication will stop working.
This is usually announced on the `MusicBrainz blog <http://blog.musicbrainz.org/>`__.
When it happens, you need to upgrade the database.

Release 2022-05-16 (27)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

mbslave psql -f updates/schema-change/27.mirror.sql
echo 'UPDATE replication_control SET current_schema_sequence = 27;' | mbslave psql

Release 2021-05-17 (26)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

mbslave psql -f updates/schema-change/26.slave.sql
echo 'UPDATE replication_control SET current_schema_sequence = 26;' | mbslave psql

2020-05-18 Upgrade to PostgreSQL 12
-----------------------------------

These steps are recommended even if you were already running on Postgres 12 before MusicBrainz
moved to make PostgreSQL 12 the minimal supported version.

Run the pre-upgrade script::

mbslave psql -f updates/20200518-pg12-before-upgrade.sql

If not already on PostgreSQL 12, upgrade your cluster now (depending on your OS, using
`pg_upgradecluster` or `pg_upgrade`)

After upgrading, or if already on PostgreSQL 12, run::

mbslave psql -f updates/20200518-pg12-after-upgrade.sql

Release 2019-05-14 (25)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

mbslave psql -f updates/schema-change/25.slave.sql
echo 'UPDATE replication_control SET current_schema_sequence = 25;' | mbslave psql

Release 2017-05-25 (24)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

mbslave psql -f updates/schema-change/24.slave.sql
echo 'UPDATE replication_control SET current_schema_sequence = 24;' | mbslave psql

Tips and Tricks
===============

Single Database Schema
~~~~~~~~~~~~~~~~~~~~~~

MusicBrainz uses a number of schemas by default. If you are embedding the MusicBrainz database into
an existing database for your application, it's convenient to merge them all into a single schema.
That can be done by changing your config like this::

[schemas]
musicbrainz=musicbrainz
statistics=musicbrainz
cover_art_archive=musicbrainz
wikidocs=musicbrainz
documentation=musicbrainz

After this, you only need to create the "musicbrainz" schema and import all the tables there.

Full Import Schema Upgrade
~~~~~~~~~~~~~~~~~~~~~~~~~~

You can use the schema mapping feature to do zero-downtime upgrade of the database with full
data import. You can temporarily map all schemas to e.g. "musicbrainz_NEW", import your new
database there and then rename it::

echo 'BEGIN; ALTER SCHEMA musicbrainz RENAME TO musicbrainz_OLD; ALTER SCHEMA musicbrainz_NEW RENAME TO musicbrainz; COMMIT;' | mbslave psql -S

*****************
SQLAlchemy Models
*****************

If you are developing a Python application that needs access to the
`MusicBrainz <https://musicbrainz.org/>`__
`data <https://musicbrainz.org/doc/MusicBrainz_Database>`__, you can use
1 change: 0 additions & 1 deletion check.sh
Original file line number Diff line number Diff line change
@@ -6,5 +6,4 @@ set -eux
# poetry run black --check mbdata/

poetry run flake8 mbdata
poetry run mypy -p mbdata.replication
poetry run pytest -v
2 changes: 1 addition & 1 deletion mbdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 Lukas Lalinsky
# Distributed under the MIT license, see the LICENSE file for details.

__version__ = "27.1.0"
__version__ = "29.0.0"
Loading