getfider / fider

Open platform to collect and prioritize feedback
https://fider.io
GNU Affero General Public License v3.0
2.87k stars 627 forks source link

[BUG] Migration 201703310857_add_tenant_to_users.up.sql fails on initial start #1092

Closed coehne closed 2 years ago

coehne commented 2 years ago

Fider Cloud or Self Hosted Self-hosted v0.21.1. on heroku and with cockroachdb.

Describe the bug Migrations fail during initial spin up. The log shows a missing field in the DB. The other tables are already created. See logs:

2022-09-28T09:19:38.189026+00:00 heroku[web.1]: Starting process with command ./bin/fider migrate && ./bin/fider 2022-09-28T09:19:40.114841+00:00 app[web.1]: INFO [2022-09-28T09:19:40Z] [MIGRATE] Running migrations... 2022-09-28T09:19:40.115202+00:00 app[web.1]: INFO [2022-09-28T09:19:40Z] [MIGRATE] Found total of 71 migration files. 2022-09-28T09:19:40.582458+00:00 app[web.1]: INFO [2022-09-28T09:19:40Z] [MIGRATE] Current version is 0 2022-09-28T09:19:40.582672+00:00 app[web.1]: INFO [2022-09-28T09:19:40Z] [MIGRATE] Running Version: 201701261850 (201701261850_create_tenants.up.sql) 2022-09-28T09:19:41.315887+00:00 app[web.1]: INFO [2022-09-28T09:19:41Z] [MIGRATE] Running Version: 201702251213 (201702251213_create_users.up.sql) 2022-09-28T09:19:41.465188+00:00 app[web.1]: INFO [2022-09-28T09:19:41Z] [MIGRATE] Running Version: 201702251620 (201702251620_add_tenant_cname.up.sql) 2022-09-28T09:19:40.905693+00:00 app[web.1]: INFO [2022-09-28T09:19:40Z] [MIGRATE] Running Version: 201701281131 (201701281131_rename_domain.up.sql) 2022-09-28T09:19:41.083757+00:00 app[web.1]: INFO [2022-09-28T09:19:41Z] [MIGRATE] Running Version: 201702072040 (201702072040_create_ideas.up.sql) 2022-09-28T09:19:42.016727+00:00 app[web.1]: INFO [2022-09-28T09:19:42Z] [MIGRATE] Running Version: 201703172115 (201703172115_remove_col_defaults.up.sql) 2022-09-28T09:19:41.700903+00:00 app[web.1]: INFO [2022-09-28T09:19:41Z] [MIGRATE] Running Version: 201703172030 (201703172030_add_ideas_userid.up.sql) 2022-09-28T09:19:43.386770+00:00 heroku[web.1]: State changed from starting to crashed 2022-09-28T09:19:43.389881+00:00 heroku[web.1]: State changed from crashed to starting 2022-09-28T09:19:43.127790+00:00 app[web.1]: INFO [2022-09-28T09:19:43Z] [MIGRATE] Running Version: 201703310857 (201703310857_add_tenant_to_users.up.sql) 2022-09-28T09:19:43.198861+00:00 app[web.1]: ERROR [2022-09-28T09:19:43Z] [MIGRATE] Error Trace: 2022-09-28T09:19:43.198863+00:00 app[web.1]: - failed to run migration '201703310857_add_tenant_to_users.up.sql' (app/pkg/dbx/migrate.go:77) 2022-09-28T09:19:43.198863+00:00 app[web.1]: - pq: column "tenant_id" does not exist 2022-09-28T09:19:42.356421+00:00 app[web.1]: INFO [2022-09-28T09:19:42Z] [MIGRATE] Running Version: 201703240709 (201703240709_remove_col_tenants.up.sql) 2022-09-28T09:19:42.623733+00:00 app[web.1]: INFO [2022-09-28T09:19:42Z] [MIGRATE] Running Version: 201703240710 (201703240710_create_comments.up.sql) 2022-09-28T09:19:42.862647+00:00 app[web.1]: INFO [2022-09-28T09:19:42Z] [MIGRATE] Running Version: 201703310824 (201703310824_remove_col_user_providers.up.sql) 2022-09-28T09:19:43.344993+00:00 heroku[web.1]: Process exited with status 1

To Reproduce Follow the "Deploy on Heroku" guide from fider docs except inserting the cockroachDB connection string as DATABASE_URL env variable.

Expected behavior Expecting the app do initial DB migrations and spin up correctly for first start.

Additional context The official Cockroach Labs heroku migration guide does not mention any other steps to do in order to replace the heroku free psql tier which will end in November. (https://www.cockroachlabs.com/blog/migrate-heroku-postgres-cockroachdb-serverless/#how-to-export-a-database-from-heroku-postgres-using-pg_dump)

coehne commented 2 years ago

Found out that cockroachDB hast not implemented 100% of PSQL features yet. Got it working with creating it first in the free heroku instance and then follow the migration guide to import the dump into CockroachDB.