Referencing the base table of a different model

Offen
#5,900 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
52/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python, sql

Rechercherichtung

The issue points to the @resolve_template macro and the existing implementation for resolving the active model's base table, but names no source files or tests. Start by reading the implementation and tests for @resolve_template, then look for how other models are referenced. Done means a referenced model's base table can be retrieved without hardcoding its fingerprint.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I have added primary keys into my SQLMesh models using https://github.com/SQLMesh/sqlmesh/issues/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

Vorherrschende Sprache
Python
Sterne
3.3k
Forks
471
Ø Merge
6 T. 7 Std.
Gemergte PRs (30 T.)
35

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus SQLMesh/sqlmesh

Alle Issues in SQLMesh/sqlmesh

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.