I have added primary keys into my SQLMesh models using #4568 as a guide. The @resolve_template macro is really useful for creating the key on the base table rather than the view.
I would also like to add some foreign keys but I don't think it's possible to get the base table for a different model. For example, this works by hardcoding the referenced table but it will break if the referenced model is ever rebuilt with a different fingerprint:
@IF( @runtime_stage = 'creating', ALTER TABLE @SQL('@this_model') ADD CONSTRAINT @resolve_template('FK_@{table_name}_id') FOREIGN KEY (id) REFERENCES schema._table__fingerprint (id) )
Is it possible to retrieve the base table from a different model in the same way that @resolve_template does for the active model?
Thanks
I have added primary keys into my SQLMesh models using #4568 as a guide. The @resolve_template macro is really useful for creating the key on the base table rather than the view.
I would also like to add some foreign keys but I don't think it's possible to get the base table for a different model. For example, this works by hardcoding the referenced table but it will break if the referenced model is ever rebuilt with a different fingerprint:
@IF( @runtime_stage = 'creating', ALTER TABLE @SQL('@this_model') ADD CONSTRAINT @resolve_template('FK_@{table_name}_id') FOREIGN KEY (id) REFERENCES schema._table__fingerprint (id) )Is it possible to retrieve the base table from a different model in the same way that @resolve_template does for the active model?
Thanks