From 2a5f0f032a970bac574ccef20070258f17096278 Mon Sep 17 00:00:00 2001 From: Tom Juntunen Date: Sat, 20 Apr 2024 01:51:30 -0700 Subject: [PATCH] add compatiblity for 1.5.0 - sourced from MatthewPocock with a minor adjustment made to the anonymous telemetry `unique_key` to use socket.gethostname() --- .github/workflows/ci.yml | 2 +- Dockerfile | 2 +- README.md | 1 + dbt/adapters/sqlite/__version__.py | 2 +- dbt/adapters/sqlite/connections.py | 3 +- dbt/include/sqlite/macros/adapters.sql | 30 ++++++++----------- .../sqlite/macros/utils/timestamps.sql | 12 ++++++++ setup.py | 2 +- 8 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 dbt/include/sqlite/macros/utils/timestamps.sql diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 531346d..a76eeaa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python_version: ["3.8", "3.9", "3.10"] + python_version: ["3.8", "3.9", "3.10", "3.11"] runs-on: ubuntu-latest diff --git a/Dockerfile b/Dockerfile index c531b93..cdb3813 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt-get update && apt-get -y install git python3 python3-pip python3-venv sq WORKDIR /opt/dbt-sqlite RUN python3 -m pip install --upgrade pip \ - && python3 -m pip install pytest pytest-dotenv dbt-core~=1.4.0 dbt-tests-adapter~=1.4.0 + && python3 -m pip install pytest pytest-dotenv dbt-core~=1.5.0 dbt-tests-adapter~=1.5.0 RUN wget -q https://github.com/nalgeon/sqlean/releases/download/0.15.2/crypto.so RUN wget -q https://github.com/nalgeon/sqlean/releases/download/0.15.2/math.so diff --git a/README.md b/README.md index 15628bb..6c2fd2e 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Use the right version. Starting with the release of dbt-core 1.0.0, versions of dbt-sqlite are aligned to the same major+minor [version](https://semver.org/) of dbt-core. +- versions 1.5.x of this adapter work with dbt-core 1.5.x - versions 1.4.x of this adapter work with dbt-core 1.4.x - versions 1.3.x of this adapter work with dbt-core 1.3.x - versions 1.2.x of this adapter work with dbt-core 1.2.x diff --git a/dbt/adapters/sqlite/__version__.py b/dbt/adapters/sqlite/__version__.py index f5a0a88..4139253 100644 --- a/dbt/adapters/sqlite/__version__.py +++ b/dbt/adapters/sqlite/__version__.py @@ -1 +1 @@ -version = '1.4.0' +version = '1.5.0' diff --git a/dbt/adapters/sqlite/connections.py b/dbt/adapters/sqlite/connections.py index bd37deb..b96bcdb 100644 --- a/dbt/adapters/sqlite/connections.py +++ b/dbt/adapters/sqlite/connections.py @@ -4,6 +4,7 @@ import glob import os.path import sqlite3 +from socket import gethostname from typing import Optional, Tuple, Any, Dict, List @@ -37,7 +38,7 @@ def unique_field(self): Hashed and included in anonymous telemetry to track adapter adoption. Pick a field that can uniquely identify one team/organization building with this adapter """ - return self.host + return gethostname() def _connection_keys(self): """ Keys to show when debugging """ diff --git a/dbt/include/sqlite/macros/adapters.sql b/dbt/include/sqlite/macros/adapters.sql index f8b99ff..18cb88e 100644 --- a/dbt/include/sqlite/macros/adapters.sql +++ b/dbt/include/sqlite/macros/adapters.sql @@ -79,15 +79,24 @@ {% endmacro %} {% macro sqlite__create_table_as(temporary, relation, sql) -%} - create {% if temporary -%} + {% set contract_config = config.get('contract') %} + {% if contract_config.enforced %} + {{exceptions.warn("Model contracts cannot be enforced by sqlite!")}} + {% endif %} + create {% if temporary -%} temporary - {%- endif %} table {{ relation }} - as + {%- endif %} table {{ relation }} + as {{ sql }} {% endmacro %} {% macro sqlite__create_view_as(relation, sql, auto_begin=False) -%} - create view {{ relation }} as + {% set contract_config = config.get('contract') %} + {% if contract_config.enforced %} + {{exceptions.warn("Model contracts cannot be enforced by sqlite!")}} + {% endif %} + create view {{ relation }} + as {{ sql }}; {%- endmacro %} @@ -96,15 +105,6 @@ {# see SQLiteAdapter.rename_relation() #} {% endmacro %} -{% macro sqlite__snapshot_get_time() -%} - datetime() -{%- endmacro %} - -{% macro sqlite__snapshot_string_as_time(timestamp) -%} - {# just return the string; SQLite doesn't have a timestamp data type per se #} - {{ return("'" + timestamp|string + "'") }} -{%- endmacro %} - {# the only allowable schema for temporary tables in SQLite is 'temp', so set that here when making the relation and everything else should Just Work @@ -116,7 +116,3 @@ that here when making the relation and everything else should Just Work {% do return(tmp_relation) %} {% endmacro %} - -{% macro sqlite__current_timestamp() -%} - datetime() -{%- endmacro %} diff --git a/dbt/include/sqlite/macros/utils/timestamps.sql b/dbt/include/sqlite/macros/utils/timestamps.sql new file mode 100644 index 0000000..e75e7a3 --- /dev/null +++ b/dbt/include/sqlite/macros/utils/timestamps.sql @@ -0,0 +1,12 @@ +{% macro sqlite__current_timestamp() -%} + datetime() +{%- endmacro %} + +{% macro sqlite__snapshot_string_as_time(timestamp) -%} + {# just return the string; SQLite doesn''t have a timestamp data type per se #} + {{ return("'" + timestamp|string + "'") }} +{%- endmacro %} + +{% macro sqlite__snapshot_get_time() -%} + datetime() +{%- endmacro %} \ No newline at end of file diff --git a/setup.py b/setup.py index 0ac10e9..29cd0ff 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ def _get_plugin_version(): ] }, install_requires=[ - "dbt-core>=1.4.0" + "dbt-core~=1.5.0" ], classifiers=[ 'Development Status :: 4 - Beta',