acoustid / mbdata

MusicBrainz SQLAlchemy Models
MIT License
97 stars 23 forks source link

Are the environment variables set correctly? #61

Open Leiyiliro opened 1 year ago

Leiyiliro commented 1 year ago

I don't really understand python but it seems to me that the application tries to read the environment variable MBSLAVE_DB_DB for the db name and not MBSLAVE_DB_NAME as it is stated in the documentation.

https://github.com/acoustid/mbdata/blob/ea0e7e2af55096b221b54f3c1e59154f9c03583b/mbdata/replication.py#L103 https://github.com/acoustid/mbdata/blob/ea0e7e2af55096b221b54f3c1e59154f9c03583b/mbdata/replication.py#L197

I tried to add MBSLAVE_DB_DB as an environment variable but still for some reason I am getting an error.

The issue I am facing is that although I am setting up the environment variables like this (in a k8s yml file):

containers:
      - name: musicbrainz-db-mirror
        image: leiyiliro/mbslave:1.0  # Specific version of the Docker image
        env:
        - name: MBSLAVE_DB_HOST
          value: musicbrainz-db
        - name: MBSLAVE_DB_PORT
          value: "5432"
        - name: MBSLAVE_DB_NAME
          value: musicbrainz
        - name: MBSLAVE_DB_DB
          value: musicbrainz
          # Used for read and write operations on the MusicBrainz database          
        - name: MBSLAVE_DB_USER
          value: $(POSTGRES_USER)
          # PostgreSQL database password for the general user
        - name: MBSLAVE_DB_PASSWORD
          value: $(POSTGRES_PASSWORD)
          # Used for creating and managing the mbslave database, schema updates, and replication
        - name: MBSLAVE_DB_ADMIN_USER
          value: $(POSTGRES_USER)
          # MusicBrainz Slave admin password for the admin user
        - name: MBSLAVE_DB_ADMIN_PASSWORD
          value: $(POSTGRES_PASSWORD)
        - name: MBSLAVE_MUSICBRAINZ_TOKEN
          value: $(MBSLAVE_MUSICBRAINZ_TOKEN)
        ports:
        - containerPort: 80

The code seems to look for a database with the name of my env variable $(POSTGRES_USER) ,which is "xxxxxx".

Traceback (most recent call last):
2023-04-18 00:30:10   File "/usr/local/bin/mbslave", line 8, in <module>
2023-04-18 00:30:10     sys.exit(main())
2023-04-18 00:30:10              ^^^^^^
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 803, in main
2023-04-18 00:30:10     args.func(config, args)
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 622, in mbslave_init_main
2023-04-18 00:30:10     create_user(config)
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 576, in create_user
2023-04-18 00:30:10     db = connect_db(config, superuser=True, no_db=True)
2023-04-18 00:30:10          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 209, in connect_db
2023-04-18 00:30:10     return cfg.connect_db(set_search_path=set_search_path, superuser=superuser, no_db=no_db)
2023-04-18 00:30:10            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 202, in connect_db
2023-04-18 00:30:10     db = psycopg2.connect(**self.database.create_psycopg2_kwargs(superuser=superuser, no_db=no_db))
2023-04-18 00:30:10          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
2023-04-18 00:30:10     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2023-04-18 00:30:10            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-04-18 00:30:10 psycopg2.OperationalError: FATAL:  database "xxxxxx" does not exist
2023-04-18 00:30:10 
2023-04-18 00:30:10 Traceback (most recent call last):
2023-04-18 00:30:10   File "/usr/local/bin/mbslave", line 8, in <module>
2023-04-18 00:30:10     sys.exit(main())
2023-04-18 00:30:10              ^^^^^^
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 803, in main
2023-04-18 00:30:10     args.func(config, args)
2023-04-18 00:30:10   File "/usr/local/lib/python3.11/site-packages/mbdata/replication.py", line 513, in mbslave_sync_main
2023-04-18 00:30:10     cursor.execute("SELECT current_schema_sequence, current_replication_sequence FROM %s.replication_control" % config.schemas.name('musicbrainz'))
2023-04-18 00:30:10 psycopg2.errors.UndefinedTable: relation "musicbrainz.replication_control" does not exist
2023-04-18 00:30:10 LINE 1: ...chema_sequence, current_replication_sequence FROM musicbrain...