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

Database (shares, albums, etc.) are lost on upgrade #317

Closed
SlavikCA opened this issue Jun 2, 2021 · 7 comments
Closed

Database (shares, albums, etc.) are lost on upgrade #317

SlavikCA opened this issue Jun 2, 2021 · 7 comments
Labels

Comments

@SlavikCA
Copy link

SlavikCA commented Jun 2, 2021

Describe the bug
I'm running piGallery2 via Docker.
DB mounted to the host:

version: '3'
services:
  pigallery2:
    image: bpatrik/pigallery2:nightly-alpine
    volumes:
      - /volume1/hosting/piGallery2/config:/app/data/config
      - /volume1/hosting/piGallery2/db-data:/app/data/db
      - /volume1/pix/Photos_Personal:/app/data/images:ro
      - /volume1/hosting/piGallery2/cache:/app/data/tmp
    environment:
      NODE_ENV: production

Every time I pull new version of the image and restart the container - all my shares are lost.

I can't point to exact builds
Now I'm on commit f2ab96f.
I'll recreate few shares now and we'll try later with another version in a few days again.

Can the issue be because I'm using nightly builds? Will shares be preserved if I use LATEST tag for Docker image instead?

@SlavikCA
Copy link
Author

SlavikCA commented Jun 2, 2021

Also, I think the indexing info is lost on update, too.
But I'll have to verify / confirm that... Is it expected to be preserved? Should re-indexing be run after upgrade?

@bpatrik
Copy link
Owner

bpatrik commented Jun 2, 2021

yeah its kinda what it is. If the DB structure changes, the app just drops the DB (including shares). Proper upgrade/migration queries would needed to fix it. Last time I checked typeorm could not really deal with it by default and I do not have the time fixing it.

If you find this annoying, use releases (latest docket tag) instead of nightly, so that you do not get off guard by a DB drop.

@bpatrik
Copy link
Owner

bpatrik commented Jun 2, 2021

more precisely, if this number changes

/**
* This version indicates that the SQL sql/entities/*Entity.ts files got changed and the db needs to be recreated
*/
export const DataStructureVersion = 25;

, you loose your DB:
if (version && version.version === DataStructureVersion) {
return;
}
Logger.info(LOG_TAG, 'Updating database scheme');
if (!version) {
version = new VersionEntity();
}
version.version = DataStructureVersion;
let users: UserEntity[] = [];
try {
users = await connection.getRepository(UserEntity).createQueryBuilder('user').getMany();
} catch (ex) {
}
await connection.dropDatabase();
await connection.synchronize();
await connection.getRepository(VersionEntity).save(version);
try {
await connection.getRepository(UserEntity).save(users);
} catch (e) {
await connection.dropDatabase();
await connection.synchronize();
await connection.getRepository(VersionEntity).save(version);
Logger.warn(LOG_TAG, 'Could not move users to the new db scheme, deleting them. Details:' + e.toString());
}
}

bpatrik added a commit that referenced this issue Jun 2, 2021
Update Docker README.md #317  to reflect possible data loss on version update.
@SlavikCA
Copy link
Author

SlavikCA commented Jun 2, 2021

If you find this annoying, use releases (latest docket tag) instead of nightly, so that you do not get off guard by a DB drop.

I looked at the code, and it appears, that even if I use LATEST tag, the DB would drop too (if DataStructureVersion gets incremented). It just would do it less frequently. Right?

@bpatrik
Copy link
Owner

bpatrik commented Jun 3, 2021

unfortunately, yes. There are no upgrade scripts implemented.
It is the same / related issue to: #301 (comment)

@bpatrik bpatrik changed the title Shares are lost on upgrade Database (shares, albums, etc.) are lost on upgrade Jun 3, 2021
@bpatrik
Copy link
Owner

bpatrik commented Jun 3, 2021

I renamed the issue to better reflect the actual problem and added a note in the docker README.md so it will catch less people off-guard a6dc01b.

@bpatrik bpatrik added the wontfix label Jun 3, 2021
@bpatrik
Copy link
Owner

bpatrik commented Dec 16, 2022

closing this due to inactivity. Feel free to reopen if you think otherwise.

@bpatrik bpatrik closed this as completed Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants