Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 31.0.0
==============

- Schema change 31.

Version 30.0.0
==============

- Schema change 30.

Version 29.1.0
==============

Expand Down
30 changes: 27 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MusicBrainz Database Mirror
:target: https://badge.fury.io/py/mbslave

This repository now contains a collection of scripts for managing a
replica of the MusicBrainz database.
replica of the MusicBrainz database.

The main motivation for these scripts is to be able to customize
your database. If you don't need such customizations, it might be
Expand Down Expand Up @@ -36,7 +36,7 @@ There are two ways to configure the application.

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

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

export MBSLAVE_DB_HOST=127.0.0.1
export MBSLAVE_DB_PORT=5432
Expand All @@ -46,6 +46,14 @@ There are two ways to configure the application.
export MBSLAVE_DB_ADMIN_USER=postgres
export MBSLAVE_DB_ADMIN_PASSWORD=XXX

Be aware, that configuring a different value for `db.user` or `schemas.musicbrainz` might require to configure a
custom `search_path` for the user (or database): By default, postgres sets the search_path to `"$user", public`.
If both is `musicbrainz` everything works, if they differ, you might run into errors when running `mbslave sync` as
triggers can't lookup functions properly. One way to solve this is to set the search path for your custom user to the
schema configured for musicbrainz::

ALTER USER myuser SET search_path TO musicbrainz, public;

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

Expand All @@ -66,7 +74,7 @@ you are doing.
Database Replication
====================

You can also keep the database up-to-date by applying incrementa changes.
You can also keep the database up-to-date by applying incremental 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.
Expand All @@ -82,6 +90,22 @@ 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 2026-05-11 (31)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

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

Release 2025-05-19 (30)
~~~~~~~~~~~~~~~~~~~~~~~

Run the upgrade scripts::

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

Release 2024-05-13 (29)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion mbslave/__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__ = "29.1.0"
__version__ = "31.0.0"
2 changes: 1 addition & 1 deletion mbslave/replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def mbslave_init_main(config: Config, args: argparse.Namespace) -> None:

# replication
('musicbrainz', 'ReplicationSetup.sql'),
('dbmirror2', 'dbmirror2/ReplicationSetup.sql'),
('dbmirror2', 'dbmirror2/dbmirror2.sql'),

]

Expand Down
7 changes: 7 additions & 0 deletions mbslave/sql/CreateAllReplicationTriggers2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Helper script to create all dbmirror2 replication triggers.
\ir CreateReplicationTriggers2.sql
\ir caa/CreateReplicationTriggers2.sql
\ir documentation/CreateReplicationTriggers2.sql
\ir statistics/CreateReplicationTriggers2.sql
\ir eaa/CreateReplicationTriggers2.sql
\ir wikidocs/CreateReplicationTriggers2.sql
Comment on lines +2 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

CreateAllReplicationTriggers2.sql doesn’t include custom trigger creation.

Line 2 starts the “all triggers” include chain, but custom triggers are not included. That can leave dbmirror2 trigger setup incomplete when this helper is used as the entrypoint.

Suggested patch
 -- Helper script to create all dbmirror2 replication triggers.
 \ir CreateReplicationTriggers2.sql
+\ir CreateCustomReplicationTriggers2.sql
 \ir caa/CreateReplicationTriggers2.sql
 \ir documentation/CreateReplicationTriggers2.sql
 \ir statistics/CreateReplicationTriggers2.sql
 \ir eaa/CreateReplicationTriggers2.sql
 \ir wikidocs/CreateReplicationTriggers2.sql
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
\ir CreateReplicationTriggers2.sql
\ir caa/CreateReplicationTriggers2.sql
\ir documentation/CreateReplicationTriggers2.sql
\ir statistics/CreateReplicationTriggers2.sql
\ir eaa/CreateReplicationTriggers2.sql
\ir wikidocs/CreateReplicationTriggers2.sql
\ir CreateReplicationTriggers2.sql
\ir CreateCustomReplicationTriggers2.sql
\ir caa/CreateReplicationTriggers2.sql
\ir documentation/CreateReplicationTriggers2.sql
\ir statistics/CreateReplicationTriggers2.sql
\ir eaa/CreateReplicationTriggers2.sql
\ir wikidocs/CreateReplicationTriggers2.sql
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mbslave/sql/CreateAllReplicationTriggers2.sql` around lines 2 - 7,
CreateAllReplicationTriggers2.sql's include list omits the custom triggers file,
so when used as the entrypoint dbmirror2's custom trigger setup is skipped; add
an include for the custom triggers (e.g., a line referencing
custom/CreateReplicationTriggers2.sql or the appropriate custom triggers file
name) into the include chain alongside the existing \ir entries
(CreateReplicationTriggers2.sql, caa/..., documentation/..., statistics/...,
eaa/..., wikidocs/...) so the custom triggers are loaded when
CreateAllReplicationTriggers2.sql is executed.

10 changes: 10 additions & 0 deletions mbslave/sql/CreateConstraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ ALTER TABLE series_type ADD CONSTRAINT allowed_series_entity_type
'recording',
'release',
'release_group',
'series',
'work'
)
);
Expand Down Expand Up @@ -173,6 +174,15 @@ ADD CONSTRAINT group_type_implies_null_gender CHECK (
ALTER TABLE release_label
ADD CHECK (catalog_number IS NOT NULL OR label IS NOT NULL);

ALTER TABLE release_label
ADD CONSTRAINT no_empty_string_catalog_number
CHECK (catalog_number != '');

ALTER TABLE release_label
ADD CONSTRAINT release_label_uniq
UNIQUE NULLS NOT DISTINCT (release, label, catalog_number)
DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE artist ADD CONSTRAINT artist_va_check
CHECK (id <> 1 OR
(type = 3 AND
Expand Down
10 changes: 10 additions & 0 deletions mbslave/sql/CreateCustomReplicationTriggers2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\set ON_ERROR_STOP 1

BEGIN;

CREATE TRIGGER sanitize_dbmirror2_editor_data
BEFORE INSERT ON dbmirror2.pending_data
FOR EACH ROW WHEN (NEW.tablename = 'musicbrainz.editor')
EXECUTE PROCEDURE sanitize_dbmirror2_editor_data();

COMMIT;
5 changes: 5 additions & 0 deletions mbslave/sql/CreateFKConstraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3006,6 +3006,11 @@ ALTER TABLE medium_format
FOREIGN KEY (parent)
REFERENCES medium_format(id);

ALTER TABLE medium_gid_redirect
ADD CONSTRAINT medium_gid_redirect_fk_new_id
FOREIGN KEY (new_id)
REFERENCES medium(id);

ALTER TABLE medium_index
ADD CONSTRAINT medium_index_fk_medium
FOREIGN KEY (medium)
Expand Down
Loading