PostgreSQL schemas need smarter support
- Dominant language
- Go
- Stars
- 17.2k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
We need a better support for the postgres schema system.
- [x] The issue is present in the latest release.
- [x] I have searched the [issues](https://github.com/ent/ent/issues) of this repository and believe that this is not a duplicate.
## Current Behavior 😯
It's already possible to define entities schemas through the SchemaConfig feature, which works but it would be easier if it's possible with an annotation on the entity instead the client config.
But now I've conflicting code generation because of "duplicate" table names.
After building with entc I received invalid generated code:
```
validation failed: packages.Load: ...\ent\migrate\schema.go:2400:2: TemplatesColumns redeclared in this block
...\ent\migrate\schema.go:706:2: other declaration of TemplatesColumns
...\ent\migrate\schema.go:2407:2: TemplatesTable redeclared in this block
...\ent\migrate\schema.go:720:2: other declaration of TemplatesTable
```
It's caused because in the database are two `templates` tables. One in the `global` schema and one in the `lead` schema.
The code generation ignores the client schema config and doesn't use the schema as a prefix.
## Expected Behavior 🤔
Schemas are a basic feature of postgres and shouldn't cause conflicts with the code generation.
## Steps to Reproduce 🕹
Create a postgres database with the same table name in two different schemas.
## Your Environment 🌎
| Tech | Version |
| ----------- | ------- |
| Go | 1.17.2 |
| Ent | 0.9.2 |
| Database | Postgres |
| Driver | https://github.com/jackc/pgx |
Thanks for your awesome work. ❤️
Contributor guide
Assessment
This issue has not been assessed yet.