Vanderhoof / PyDBML

DBML parser and builder for Python
MIT License
101 stars 12 forks source link

inline refs can't have schema on fk table #14

Closed jens-koster closed 2 years ago

jens-koster commented 2 years ago

Hi there! Inline refs with a schema on the FK table like below, causes the exception: "Table public.fk_tbl not present in the database"

Table core.pk_tbl {
    pk_col varchar [pk]
}
Table core.fk_tbl {
    fk_col varchar [ref: > core.pk_tbl.pk_col]
}

I assumed public was a default value for the schema that was not overwritten. Separate refs worked fine, the below dbml is parsable:

Table core.pk_tbl {
    pk_col varchar [pk]
}
Table core.fk_tbl {
    fk_col varchar
}
Ref {
    core.fk_tbl.fk_col > core.pk_tbl.pk_col
}

I had a look and I think I found the missing assignment. Seems to work fine with that change for these two cases at least :-)

off topic: Thanks for doing this! I am using your PyDBML to generate dbml from dbt models. I am thinking to edit the dbml adding notes, pk, not null etc and then create the schema.yml for dbt from that, including the generic tests that can be deduced from the dbml.

Vanderhoof commented 2 years ago

@jens-koster Thanks a lot for finding this! I think your other change accidentally got into this PR? Could you rollback the notes commit so that I could merge this one and your name would appear in contributors section?