Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied when creating schema for primary/replicas #9556

Closed
fmarchalemisys opened this issue Mar 2, 2022 · 6 comments · Fixed by #10516
Closed

Permission denied when creating schema for primary/replicas #9556

fmarchalemisys opened this issue Mar 2, 2022 · 6 comments · Fixed by #10516
Labels

Comments

@fmarchalemisys
Copy link

Bug Report

Q A
BC Break no
Version 2.11

Summary

Creating the schema from the command line fails if a primary/replica configuration is used.

php bin/console doctrine:schema:create

SQL commands are sent to the replica instead of the primary db.

The culprit is SchemaTool

It executes CREATE statements with executeQuery($sql) instead of executeStatement($sql).

Current behavior

Creating the schema fails due to CREATE statement being denied on replica. The replica is read only. The schema can't be created on the replica.

How to reproduce

Unless you have two db servers configured as master/slave, the setup can be replicated on a single db server. Create a R/W user to simulate the primary and a R/O user with SELECT permission to simulate the replica.

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: 'mariadb-10.3.11'
        charset: utf8mb4
        url: 'mysql://live_fred:[email protected]:3306/live_fred'
        replicas:
            replica1:
                url: 'mysql://live_fred_ro:[email protected]:3306/live_fred'

Run the command:

php bin/console doctrine:schema:create
In ToolsException.php line 19:
                                                                                                                                                                                                                                            
  Schema-Tool failed with Error 'An exception occurred while executing a query: SQLSTATE[42000]: Syntax error or access violation: 1142 CREATE command denied to user 'live_fred_ro'@'localhost' for table 'core_print_ticket_translation'  
  ' while executing DDL: CREATE TABLE core_print_ticket_translation … 

Expected behavior

SQL CREATE statements must be sent to the primary.

CREATE statements are not queries. SchemaTool must call executeStatement($sql).

@derrabus derrabus added the Bug label Mar 2, 2022
@leuchtdiode
Copy link

leuchtdiode commented Apr 4, 2022

Experienced this issue as well. Schema tool is trying to execute statements on replicas (which are in read-only mode in my setup). It should only be executed on primary only.

@eichie
Copy link

eichie commented Apr 11, 2022

+1

@elpoutro
Copy link

Same issue with "php bin/console doctrine:schema:update" since update form doctrine 2.3 to 2.8.

@pich
Copy link

pich commented Apr 12, 2023

+1

@greg0ire greg0ire linked a pull request Apr 12, 2023 that will close this issue
@greg0ire
Copy link
Member

Fixed in https://github.com/doctrine/orm/releases/tag/2.14.2

@pich
Copy link

pich commented Apr 13, 2023

Thanks. Great job @simPod & @greg0ire . I owe you guys a beer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants