Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gorm-example-postgres #18

Merged
merged 5 commits into from
Apr 8, 2024
Merged

gorm-example-postgres #18

merged 5 commits into from
Apr 8, 2024

Conversation

rohaizanr
Copy link
Contributor

@rohaizanr rohaizanr commented Apr 7, 2024

Hello @goxiaoy

I'm seeking your advice.
I have followed your example and come up with example/gorm for Postgres.

Please try it out by:

git clone https://github.com/rohaizanr/saas.git
cd saas; git checkout postgres-example
cd examples/gorm/; docker-compose up -d
go run github.com/go-saas/saas/examples/gorm --driver pgx

Host side ( use shared database):

Open http://localhost:8090/posts (Success)

Multi-tenancy ( use shared database):

Open http://localhost:8090/posts?__tenant=1 (FAILED)

Open http://localhost:8090/posts?__tenant=2 (FAILED)

Single-tenancy ( use separate database):

Open http://localhost:8090/posts?__tenant=3 (FAILED)

Issues

  1. Not able to get tenant 1,2,3 data
  2. Unexpected "%!(EXTRA string=3)" in seed.go:line 33 to 40, I need to manually remove it.

Please help to point out my mistakes, I'm planning to use this in my https://github.com/Dev4w4n/e-masjid.my

Thanks!

@goxiaoy
Copy link
Collaborator

goxiaoy commented Apr 8, 2024

  1. Not able to get tenant 1,2,3 data

according to https://www.postgresql.org/docs/current/datatype-character.html#DATATYPE-CHARACTER
the previous model Tenant will have a blank-padded ID field

type Tenant struct {
	ID string `gorm:"type:char(36)" json:"id"`

So the tenant id queried back will be 1 not 1, which causes the automatic filter failed in the query of Post

  1. Unexpected "%!(EXTRA string=3)" in seed.go:line 33 to 40, I need to manually remove it.

Not sure about why, probably because of the old data during development. May fix it by using FullSaveAssociations mode

@goxiaoy goxiaoy merged commit ad56753 into go-saas:main Apr 8, 2024
1 check passed
@goxiaoy
Copy link
Collaborator

goxiaoy commented Apr 8, 2024

You may need to drop local tables first to apple new db schema

@rohaizanr rohaizanr deleted the postgres-example branch April 8, 2024 13:15
@rohaizanr
Copy link
Contributor Author

thanks @goxiaoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants