mikestefanello / pagoda

Rapid, easy full-stack web development starter kit in Go
MIT License
2.09k stars 108 forks source link

Error initializing ORM #39

Closed ljcbs closed 1 year ago

ljcbs commented 1 year ago

Thanks for making the Repo.

I'm having issues getting the ORM setup correctly. On a fresh clone of the repo following the README and running make up and then make run i'm getting the following error.

go run cmd/web/main.go
panic: failed to create database schema: postgres: unexpected number of rows: 1

goroutine 1 [running]:
github.com/mikestefanello/pagoda/pkg/services.(*Container).initORM(0xc000192370)
    /~/~/~/pagoda-template/pkg/services/container.go:175 +0x1a5
github.com/mikestefanello/pagoda/pkg/services.NewContainer()
    /~/~/~/pagoda-template/pkg/services/container.go:66 +0xdb
main.main()
    /~/~/~/pagoda-template/cmd/web/main.go:18 +0x25
exit status 2
make: *** [run] Error 1

Adding debug to Schema.Create() shows

2023/09/17 15:33:23 driver.Query: query=SHOW server_version_num args=[]
2023/09/17 15:33:23 driver.Tx(ce7868ac-32fc-483e-805f-df638139aab3): started
2023/09/17 15:33:23 Tx(ce7868ac-32fc-483e-805f-df638139aab3).Query: query=SELECT setting FROM pg_settings WHERE name IN ('lc_collate', 'lc_ctype', 'server_version_num', 'crdb_version') ORDER BY name DESC args=[]
panic: failed to create database schema: postgres: unexpected number of rows: 1
...

I've checked this query against the postgres container and it returns

make db
docker exec -it pagoda_db psql postgresql://admin:admin@localhost:5432/app
psql (16.0)
Type "help" for help.

app=# SELECT setting FROM pg_settings WHERE name IN ('lc_collate', 'lc_ctype', 'server_version_num', 'crdb_version') ORDER BY name DESC;
 setting
---------
 160000
(1 row)

Unsure where to go from here, specifically the unexpected number of rows: 1 error and how many rows is it expecting?

mikestefanello commented 1 year ago

You're very welcome. I hope you find it useful once this is cleared up.

I just checked out the repo, dropped any existing containers and ran the same commands. It booted up fine without any errors. What OS are you using? What docker version, etc?

mikestefanello commented 1 year ago

Strange.. I just ran tests here and they failed with the issue you reported: https://github.com/mikestefanello/pagoda/actions/runs/6214367872/job/16866235207

mikestefanello commented 1 year ago

Here's the problem: https://github.com/ent/ent/issues/3750. Looks like we need to pin the PG version to 15 for now.

This commit should do it. Please try again and let me know if that doesn't work for you.