diff --git a/src/migration/migration.go b/src/migration/migration.go index 50cd5c1..41ce9d0 100644 --- a/src/migration/migration.go +++ b/src/migration/migration.go @@ -365,14 +365,13 @@ func ResetDB() { // Create the HMN database user { - type pgCredentials struct { - User string - Password string - } - credentials := []pgCredentials{ - {config.Config.Postgres.User, config.Config.Postgres.Password}, // Existing HMN user - {getSystemUsername(), ""}, // Postgres.app on Mac - } + credentials := append( + []pgCredentials{ + {config.Config.Postgres.User, config.Config.Postgres.Password, false}, // Existing HMN user + {getSystemUsername(), "", true}, // Postgres.app on Mac + }, + guessCredentials()..., + ) var workingCred pgCredentials var createUserConn *pgconn.PgConn @@ -383,6 +382,9 @@ func ResetDB() { createUserConn, err = connectLowLevel(ctx, cred.User, cred.Password) if err == nil { workingCred = cred + if cred.SafeToPrint { + fmt.Printf("Connected by guessing username \"%s\" and password \"%s\".\n", cred.User, cred.Password) + } break } else { connErrors = append(connErrors, err) @@ -490,3 +492,22 @@ func getSystemUsername() string { } return u.Username } + +type pgCredentials struct { + User string + Password string + SafeToPrint bool +} + +var commonRootUsernames = []string{getSystemUsername(), "postgres", "root"} +var commonRootPasswords = []string{"", "password", "postgres"} + +func guessCredentials() []pgCredentials { + var result []pgCredentials + for _, username := range commonRootUsernames { + for _, password := range commonRootPasswords { + result = append(result, pgCredentials{username, password, true}) + } + } + return result +} diff --git a/src/migration/seed.go b/src/migration/seed.go index c41253c..0abad6e 100644 --- a/src/migration/seed.go +++ b/src/migration/seed.go @@ -178,7 +178,7 @@ func seedUser(ctx context.Context, conn db.ConnOrTx, input models.User) *models. status, name, bio, blurb, signature, darktheme, - showemail, edit_library, + showemail, date_joined, registration_ip, avatar_asset_id ) VALUES ( @@ -187,7 +187,7 @@ func seedUser(ctx context.Context, conn db.ConnOrTx, input models.User) *models. $5, $6, $7, $8, $9, TRUE, - $10, FALSE, + $10, '2017-01-01T00:00:00Z', '192.168.2.1', null ) RETURNING $columns