Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Database detected as empty and its tried to be setup again #1712

Closed
marc0s opened this issue Mar 1, 2018 · 4 comments
Closed

Database detected as empty and its tried to be setup again #1712

marc0s opened this issue Mar 1, 2018 · 4 comments

Comments

@marc0s
Copy link

marc0s commented Mar 1, 2018

Description

I'm using a docker-compose setup. Fetch portus:head and restarted my containers. portus didn't come up because it failed with something very similar to this.

Steps to reproduce

  1. pull updated portus:head
  2. restarted containers
  3. And this happened!
  • Expected behavior: I expected to have it working as before
  • Actual behavior: database setup is being tried but it fails with foreign key errors and such

Findings

After some digging, I found out that init is checking if we set PORTUS_INIT_COMMAND, by default it isn't. I manually run the check_db.rb script and found out that it was sending back a DB_EMPTY, which is actually inaccurate. I manually entered into the DB and found that my data was still there.

MariaDB [portus_production]> select count(*) from users;
+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.01 sec)

So, I set PORTUS_INIT_COMMAND to portusctl exec "pumactl -F /srv/Portus/config/puma.rb start" (just as init runs at the end) and my container started flawlessly.

What's portus/db using to determine if the database is empty or not? I think I have run somehow the same docker-compose setup but with 2.3 instead of head once trying to find out the issue (maybe causing the issue, actually?). Might it be the source of the problem if it can modify something that portus/db will interpret as an empty database?

Please tell me if you need anything else.

Thanks!

@ldperron
Copy link

ldperron commented Mar 5, 2018

I got the exact same issue here after performing a pull on the docker image.

Reason:
From /init, this command portusctl exec rails r /srv/Portus/bin/check_db.rb | grep DB yields DB_EMPTY if there is a single missing migration.
Which was my case, I had this migration missing: 20180207145522_change_vulnerabilities_to_medium_text.rb

If I manually run: portusctl rake db:migrate (without lettings db:setup running), then check_db.rb yields DB_READY

@marc0s
Copy link
Author

marc0s commented Mar 28, 2018

I miss the notification for this reply, sorry.

I got it fixed as well. Thanks.

@marc0s marc0s closed this as completed Mar 28, 2018
@ldperron
Copy link

Actually, I would keep this bug open. We should expect init script to detect that there are missing migrations, and try to apply them on startup, instead of trying to wipe out and recreate the database.

@marc0s marc0s reopened this Mar 28, 2018
@mssola mssola added this to the Release 2.4 milestone Apr 5, 2018
mssola added a commit to mssola/Portus that referenced this issue Sep 18, 2018
This task should be used when setting up the database instead of the
usual combination. This handles databases with pending migrations, new
databases, etc.

See SUSE#1639
See SUSE#1712

Signed-off-by: Miquel Sabaté Solà <[email protected]>
mssola added a commit to openSUSE/docker-containers that referenced this issue Sep 18, 2018
The commit 914cc9ebfdee7b22ee934e6cc4bac0bfd6dfa9fd of Portus introduced
the `portus:db:configure` task, which is a replacement for `db:setup` in
containerized environments.

See SUSE/Portus#1639
See SUSE/Portus#1712

Signed-off-by: Miquel Sabaté Solà <[email protected]>
@mssola
Copy link
Collaborator

mssola commented Sep 18, 2018

This has been finally fixed with #1970 and openSUSE/docker-containers@293e289. The head image will contain the fix once it's done building.

Thanks everyone for the feedback 👏

@mssola mssola closed this as completed Sep 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants