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

sqitch tries to lock the registry DB before it has been created #700

Open
neilmayhew opened this issue Jan 6, 2023 · 6 comments
Open

sqitch tries to lock the registry DB before it has been created #700

neilmayhew opened this issue Jan 6, 2023 · 6 comments
Assignees
Labels
bug engine waiting Waiting on feedback

Comments

@neilmayhew
Copy link

Since #589 was merged, sqitch now requires the registry database to exist before it can deploy.

I believe the problem lies in lib/App/Sqitch/Engine.pm at lines 191 and 229.

I think this problem isn't detected in unit tests because the information_schema database is used and this always exists.

However, it's a problem for our application and we've had to add CREATE DATABASE IF NOT EXISTS sqitch to our pre-sqitch initialization.

@theory
Copy link
Collaborator

theory commented Jan 7, 2023

Sqitch has always required that a database exist before deploying. Are you experiencing an error? What database engine are you using?

@neilmayhew
Copy link
Author

I'm using the mysql backend. I realize that the target database has to exist, but the registry database doesn't, and sqitch is locking the registry DB not the target DB. We used to create the app DB in our initialization but now we have to create a DB called sqitch as well.

@neilmayhew
Copy link
Author

neilmayhew commented Jan 7, 2023

Running with -VVV to get a stack backtrace, I can see that the 'DB does not exist' exception is coming from line 191 in Engine.pm. The DB isn't created until line 229.

@neilmayhew
Copy link
Author

neilmayhew commented Jan 7, 2023

Here's the output:

    DBI 1.643-ithread default trace level set to 0x0/1 (pid 1249849 pi 9012a0) at DBIEngine.pm line 27 via (eval 640) line 16
    -> DBI->connect(dbi:mysql:host=127.0.0.1;port=3307;database=sqitch, root, ****, HASH(0x35c08b8))
    -> DBI->install_driver(mysql) for linux perl=5.036000 pid=1249849 ruid=1000 euid=1000
       install_driver: DBD::mysql version 4.050 loaded from /nix/store/0dncx1l88zdyf0l7scpx8a0xd01fgqdp-perl5.36.0-DBD-mysql-4.050/lib/perl5/site_perl/5.36.0/x86_64-linux-thread-multi/DBD/mysql.pm
    <- install_driver= DBI::dr=HASH(0x36291a0)
    !! The warn '0' was CLEARED by call to connect method
       ERROR: 1049 'Unknown database 'sqitch'' (err#0)
    <- DESTROY(DBI::db=HASH(0x3667bd8))= ( undef ) [1 items] at mysql.pm line 163
    !! ERROR: 1049 'Unknown database 'sqitch'' (err#0)
    <- connect('host=127.0.0.1;port=3307;database=sqitch', 'root', ...)= ( undef ) [1 items] at DBI.pm line 679
    <- $DBI::errstr= 'Unknown database 'sqitch''
       DBI connect('host=127.0.0.1;port=3307;database=sqitch','root',...) failed: Unknown database 'sqitch'
       ERROR: 1049 'Unknown database 'sqitch'' (err#0)
    <- state= ( '42000' ) [1 items] at mysql.pm line 85
       ERROR: 1049 'Unknown database 'sqitch'' (err#0)
    <- errstr= ( 'Unknown database 'sqitch'' ) [1 items] at mysql.pm line 85
Unknown database 'sqitch'
trace: Trace begun at /nix/store/vih7n0nx0j7lbq7bxfs4vzv6dmmfy86y-perl5.36.0-DBI-1.643/lib/perl5/site_perl/5.36.0/x86_64-linux-thread-multi/DBI.pm line 691
trace: DBI::__ANON__(undef, undef) called at /nix/store/vih7n0nx0j7lbq7bxfs4vzv6dmmfy86y-perl5.36.0-DBI-1.643/lib/perl5/site_perl/5.36.0/x86_64-linux-thread-multi/DBI.pm line 748
trace: DBI::connect('DBI', 'dbi:mysql:host=127.0.0.1;port=3307;database=sqitch', 'root', 'XXXX', 'HASH(0x35c08b8)') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch/Engine/mysql.pm line 119
trace: App::Sqitch::Engine::mysql::__ANON__('App::Sqitch::Engine::mysql=HASH(0x35f2e00)') called at (eval 636) line 52
trace: App::Sqitch::Engine::mysql::dbh('App::Sqitch::Engine::mysql=HASH(0x35f2e00)') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch/Engine/mysql.pm line 310
trace: App::Sqitch::Engine::mysql::try_lock('App::Sqitch::Engine::mysql=HASH(0x35f2e00)') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch/Engine.pm line 1033
trace: App::Sqitch::Engine::lock_destination('App::Sqitch::Engine::mysql=HASH(0x35f2e00)') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch/Engine.pm line 191
trace: App::Sqitch::Engine::deploy('App::Sqitch::Engine::mysql=HASH(0x35f2e00)', undef, 'all') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch/Command/deploy.pm line 135
trace: App::Sqitch::Command::deploy::execute(undef, 'db:mysql://root:XXXX@127.0.0.1:3307/presta') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch.pm line 207
trace: App::Sqitch::try {...}  at /nix/store/75a0hixkg1np25sksd6qslx6v7x5w8jm-perl5.36.0-Try-Tiny-0.30/lib/perl5/site_perl/5.36.0/Try/Tiny.pm line 100
trace: eval {...} at /nix/store/75a0hixkg1np25sksd6qslx6v7x5w8jm-perl5.36.0-Try-Tiny-0.30/lib/perl5/site_perl/5.36.0/Try/Tiny.pm line 93
trace: Try::Tiny::try('CODE(0x2202800)', 'Try::Tiny::Catch=REF(0x1ee8290)') called at /nix/store/sdr7j8xy6lp99qx23jn1727fq8cb7l2h-perl5.36.0-App-Sqitch-1.1.0/lib/perl5/site_perl/5.36.0/App/Sqitch.pm line 227
trace: App::Sqitch::go('App::Sqitch') called at /nix/store/x63w6yrl071vb76vshzk48z6vj95hssc-sqitch-mysql-1.2.1/bin/.sqitch-wrapped line 15

    !! The ERROR '1049' was CLEARED by call to disconnect_all method
    <- disconnect_all= ( ) [0 items] (not implemented) at DBI.pm line 758
!   <- DESTROY(DBI::dr=HASH(0x35ad088))= ( undef ) [1 items] during global destruction

@theory
Copy link
Collaborator

theory commented Jan 7, 2023

Hrm. Line 191 calls lock_destination, where at line 1036 it calls try_lock. That method calls initialized in mysql.pm at line 332. That method should simply return false for error 1049, at line 267. With false returned, back at line 332 it should get the false, then call initialize, which should create the database at lines 289-294.

Could it be that line 267 is not actually catching the missing database error, leading it to raise the error on line 268?

@theory theory self-assigned this Jan 7, 2023
@theory
Copy link
Collaborator

theory commented May 20, 2023

1049 is the error that shows up in the debug output you posted, so it should be right.

@theory theory added the waiting Waiting on feedback label Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug engine waiting Waiting on feedback
Projects
None yet
Development

No branches or pull requests

2 participants