Trying to define foreign keys in Databricks Unity Catalog via dbt. I have figured out the syntax and am able to successfully add the constraints to the tables. However, my issues arise when I try to run all my models at once- in order for the FK constraints to be created, the table which the FK references has to exist first- i.e. if “orders” has a FK to “customers”, the customers table must be created first so that when orders is created and the constraint is defined, it maps to a table/column that exists.
The solution to this is to be able to run my models in a specific order (preferably in an efficient and clean looking way). I know that you can inject dependencies manually in several different ways, and that the order of the models can be defined in this way. However, that turns my dependency graph into a mass of spaghetti even though technically these tables don’t “depend” on each other for anything other than an unenforced FK constraint. I also know that you can tag models, and use multiple “dbt run” commands to run each group of tagged models, but I think this will get out of hand quickly/in general will be confusing.
Is there any way for me to define the order that models get executed based on their FK constraints without creating a mess of dependencies?
Thank you to anybody willing to help.