I'm trying out the Chitchat go app from the book Go Web Programming. The original version works. When I use a user & password to access postgresql, it can connect to db but fails to create a new User, as shown below:
func db() (database *sql.DB) {
database, err := sql.Open("postgres", "dbname=chitchat user=tom password=tomahawk sslmode=disable")
if err != nil {
log.Fatal(err)
fmt.Println("Db connection failed")
}
return
}
Here's the full code on Github.
However, I've found a temporary solution but it requires granting access to all the sequences in the chitchat database. Even after I've applied a
GRANT ALL PRIVILEGES ON DATABASE chitchat to tom;
it still requires manual grants to each of the table sequences. Here're the steps taken:
1) Grant access to database
GRANT all privileges on database chitchat to tom;
2) List all sequences in chitchat database
SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';
3) Grant access to each of them
GRANT all privileges on sequence users_id_seq to tom;
GRANT all privileges on sequence threads_id_seq to tom;
GRANT all privileges on sequence posts_id_seq to tom;
GRANT all privileges on sequence sessions_id_seq to tom;
Is there a better way? Thanks in advance.