agronholm / agronholm/sqlacodegen

Duplicate Table(Base) created if foreign key exists between two separate schema's in one database

オープン
#426 コメント 7 件 リアクション 0 件 担当者 1 名 @sheinbergon が担当を希望しています GitHub で見る
bug
主要言語
Python
スター
2.4k
フォーク
284
平均マージ
2日 1時間
マージ済み PR(30日)
1

説明

### Things to check first

- [x] I have searched the existing issues and didn't find my bug already reported there

- [x] I have checked that my bug is still present in the latest release

### Sqlacodegen version

sqlacodegen==3.0.0

### SQLAlchemy version

sqlalchemy==2.0.42

### RDBMS vendor

PostgreSQL

### What happened?

We've got a couple separate schema's in a postgres database that are split for separation of concern and organization. Our system has over 120 tables across all schema's. After testing we found that it has something to do with the public default schema.

When running codegen on two schema's (let's say public, SchemaB) where a foreign key exists on a public table that references a SchemaB table, the codegen output creates two separate python classes for the same object. Let's say the table name is User. We end up with a User & User_ class that are 99% the same except for a schema tag and one different foreign key relationship. To make things worse, if the table that is referenced has any additional foreign keys pointing to other tables, it will do the same for every referenced table. We end up with duplicate classes for every referenced column.

I can't share our actual schema, but I'll show the command and what to do to reproduce.

### Database schema for reproducing the bug

sqlacodegen --schema="public,schema_b" --outfile="database/schema.py" --generator=declarative_alpha "postgresql+pg8000://${DB_USER}:${DB_PASSWORD}@0.0.0.0:3306/postgres"

To reproduce, create a table in a public schema and then in a separate schema and make a cross schema foreign key then run the command.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。