diff --git a/rasgoql/CHANGELOG.md b/rasgoql/CHANGELOG.md index a68de57..a8047f1 100644 --- a/rasgoql/CHANGELOG.md +++ b/rasgoql/CHANGELOG.md @@ -118,6 +118,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed a postgres bug +## [1.6.3] - 2022-06-27 +### Added +- Added a jinja date macro + +## [1.6.4] - 2022-07-05 +### Changed +- Changed default behavior of to_dbt function. Instead of always appending model details to the schema.yml file (which creates duplicate entries for existing models), rql will now check if a model entry already exists in the file and overwrite it. If the model does not exist, it will be appended. + + [1.0.0]: https://pypi.org/project/rasgoql/1.0.0/ [1.0.1]: https://pypi.org/project/rasgoql/1.0.1/ [1.0.2]: https://pypi.org/project/rasgoql/1.0.2/ @@ -137,3 +146,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [1.6.0]: https://pypi.org/project/rasgoql/1.6.0/ [1.6.1]: https://pypi.org/project/rasgoql/1.6.1/ [1.6.2]: https://pypi.org/project/rasgoql/1.6.2/ +[1.6.3]: https://pypi.org/project/rasgoql/1.6.3/ +[1.6.4]: https://pypi.org/project/rasgoql/1.6.4/ diff --git a/rasgoql/rasgoql/utils/dbt.py b/rasgoql/rasgoql/utils/dbt.py index 5f3200c..12cd1c9 100644 --- a/rasgoql/rasgoql/utils/dbt.py +++ b/rasgoql/rasgoql/utils/dbt.py @@ -134,16 +134,25 @@ def save_schema_file( Writes a table def to a dbt schema file """ filepath = os.path.join(output_directory, 'schema.yml') - columns_list = [] - for row in schema: - columns_list.append({"name:": row[0]}) - model_dict = {"name": model_name, "columns": columns_list} - if config_args: - model_dict.update({"config": config_args}) - if not os.path.exists(filepath): - schema_definition = {"version": 2, "models": [model_dict]} + existing_schema = None + if os.path.exists(filepath): + with open(filepath, "r") as _file: + existing_schema = yaml.safe_load(_file) + schema_definition = existing_schema or {"version": 2, "models": []} + + columns_list = [{"name:": row[0]} for row in schema] + for mod in schema_definition["models"]: + if mod.get("name") == model_name: + mod["columns"] = columns_list + if config_args: + mod["config"] = config_args + break else: - schema_definition = [model_dict] - with open(filepath, "a") as _file: + model_dict = {"name": model_name, "columns": columns_list} + if config_args: + model_dict.update({"config": config_args}) + schema_definition["models"].append(model_dict) + + with open(filepath, "w") as _file: yaml.dump(data=schema_definition, Dumper=yaml.SafeDumper, stream=_file, sort_keys=False) return filepath diff --git a/rasgoql/rasgoql/version.py b/rasgoql/rasgoql/version.py index 64085bd..f1722a4 100644 --- a/rasgoql/rasgoql/version.py +++ b/rasgoql/rasgoql/version.py @@ -1,4 +1,4 @@ """ Package version for pypi """ -__version__ = '1.6.3' +__version__ = '1.6.4'