diff --git a/bigquery_etl/cli/stage.py b/bigquery_etl/cli/stage.py index df80205b6c2..c073cee65d3 100644 --- a/bigquery_etl/cli/stage.py +++ b/bigquery_etl/cli/stage.py @@ -310,8 +310,18 @@ def _view_dependencies(artifact_files, sql_dir): if not path.exists(): path.mkdir(parents=True, exist_ok=True) # don't create schema for wildcard and metadata tables + # Create schemas for syndicated tables, stable, live tables and other + # tables not managed by bigquery-etl by doing a dryrun. + # The stage project doesn't have access to prod tables (e.g when referenced) + # so we need to create the schema here and deploy it. if "*" not in name and name != "INFORMATION_SCHEMA": - partitioned_by = "submission_timestamp" + partitioned_by = None + + if any( + dataset.endswith(suffix) for suffix in ("_live", "_stable") + ): + partitioned_by = "submission_timestamp" + schema = Schema.for_table( project=project, dataset=dataset, @@ -321,11 +331,11 @@ def _view_dependencies(artifact_files, sql_dir): ) schema.to_yaml_file(path / SCHEMA_FILE) - if not file_exists_for_dependency: - (path / QUERY_SCRIPT).write_text( - "# Table stub generated by stage deploy" - ) - view_dependencies.add(path / QUERY_SCRIPT) + if not file_exists_for_dependency: + (path / QUERY_SCRIPT).write_text( + "# Table stub generated by stage deploy" + ) + view_dependencies.add(path / QUERY_SCRIPT) # extract UDF references from view definition raw_routines = read_routine_dir() diff --git a/bigquery_etl/view/__init__.py b/bigquery_etl/view/__init__.py index f0e8e356a11..b4f41ac7b3f 100644 --- a/bigquery_etl/view/__init__.py +++ b/bigquery_etl/view/__init__.py @@ -426,9 +426,9 @@ def publish(self, target_project=None, dry_run=False, client=None): if not self.metadata: print(f"Missing metadata for {self.path}") - - table.description = self.metadata.description - table.friendly_name = self.metadata.friendly_name + else: + table.description = self.metadata.description + table.friendly_name = self.metadata.friendly_name if table.labels != self.labels: labels = self.labels.copy()