sacdallago / mecu

TPCA data analysis tool
http://protein.melting.degree
GNU General Public License v3.0
1 stars 0 forks source link

Can't create users on empty database #50

Closed sacdallago closed 5 years ago

sacdallago commented 5 years ago

-When creating a new database docker instance via:

docker run --rm --name mecu -p 5432:5432 sacdallago/mecu-postgres

by starting the app on the db, you get the following error:

LOG:  database system is ready to accept connections
ERROR:  relation "users" does not exist
STATEMENT:  ALTER TABLE users ADD COLUMN IF NOT EXISTS "isAdmin" BOOLEAN;
ERROR:  relation "users" does not exist at character 13
STATEMENT:  INSERT INTO users ("googleId", "displayName", "allowPost", "deletedAt", "createdAt", "updatedAt", "isAdmin")
                    VALUES
                        ('***', '***', ***, ***, ***, ***, ***),
                        ('***', '***', ***, ***, ***, ***, ***),
                        ('**', '***', ***, ***, ***, ***, ***)
                    ON CONFLICT ("googleId") DO UPDATE
                        SET "isAdmin" = EXCLUDED."isAdmin"

Also: the other SQL seeding statements don't get executed (but maybe I'm doing something wrong?)

sacdallago commented 5 years ago

Seems like the seeding is called before the table creation

sacdallago commented 5 years ago

Note, the seeding worker also complains:

[Thu Jun 06 2019 10:38:48] [ERROR]  [SeedingWorker] SEEDIG ERROR { SequelizeDatabaseError: relation "users" does not exist
....
[Thu Jun 06 2019 10:38:48] [LOG]    [SeedingWorker] seeding done.

On restarting the app, you get:

[Thu Jun 06 2019 10:39:52] [LOG]    [SeedingWorker] CONNECTING TO postgres://***:***@127.0.0.1:5432/mecu
[Thu Jun 06 2019 10:39:52] [WARN]   [SeedingWorker] No private/config.js found... continuing with default config
[Thu Jun 06 2019 10:39:53] [LOG]    [SeedingWorker] Connection has been established successfully.
[Thu Jun 06 2019 10:39:53] [LOG]    [SeedingWorker] doing seeding...
[Thu Jun 06 2019 10:39:53] [LOG]    [SeedingWorker] seeding done.

But nothing is seeded

sacdallago commented 5 years ago

Note: when it fails, the tables won't be created. when restarted, the tables will be created. This makes me think that as mentioned above, the seeding is done before creating the tables

sacdallago commented 5 years ago

Confirmed: It would be necessary to move this code: https://github.com/sacdallago/mecu/blob/develop/app/server/slaveWorker.js#L194 before the migration worker starts if no version is declared --> means the database needs to be created and no migration is necessary, only initialization. If some version of the database exists, then do migrations...

KlausNie commented 5 years ago

fixed with https://github.com/sacdallago/mecu/tree/bugfix/migration-and-seeding-done-after-database-model-creation

sacdallago commented 5 years ago

Just as a reference: the seeding is done in one case when !version, in another case when version < 2. If version is undefined, comparison to anything else renders none, thus that statement doesn't get executed. Better solution: use a switch statement which follows through, e.g.: https://github.com/sacdallago/mecu/pull/52/files#diff-ef76af1f02471541934bd0fdf2a6095eR37