From 065aef19f193f8f0feb6a756383c66201e69c111 Mon Sep 17 00:00:00 2001 From: MatthewPocock Date: Mon, 19 Feb 2024 23:41:12 +1100 Subject: [PATCH 1/3] add compatiblity for 1.5.0 --- .github/workflows/ci.yml | 2 +- Dockerfile | 2 +- README.md | 1 + dbt/adapters/sqlite/__version__.py | 2 +- dbt/adapters/sqlite/connections.py | 5 ++-- dbt/include/sqlite/macros/adapters.sql | 27 ++++++++----------- .../sqlite/macros/utils/timestamps.sql | 12 +++++++++ setup.py | 2 +- 8 files changed, 31 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..0c48098 100644 --- a/dbt/adapters/sqlite/connections.py +++ b/dbt/adapters/sqlite/connections.py @@ -2,6 +2,7 @@ from contextlib import contextmanager from dataclasses import dataclass, field import glob +import json import os.path import sqlite3 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 json.dumps(self.schemas_and_paths, sort_keys=True) def _connection_keys(self): """ Keys to show when debugging """ @@ -73,7 +74,7 @@ def open(cls, connection: Connection): for ext_path in credentials.extensions: handle.load_extension(ext_path) - + cursor = handle.cursor() for schema in set(schemas_and_paths.keys()) - set(['main']): diff --git a/dbt/include/sqlite/macros/adapters.sql b/dbt/include/sqlite/macros/adapters.sql index f8b99ff..4ff6f35 100644 --- a/dbt/include/sqlite/macros/adapters.sql +++ b/dbt/include/sqlite/macros/adapters.sql @@ -79,14 +79,22 @@ {% 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) -%} + {% 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 +104,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 +115,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..7077963 --- /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 %} diff --git a/setup.py b/setup.py index 0ac10e9..0fe7f40 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', From 54d03dd225dd971fb493cf21fbf56dbce1fd60a2 Mon Sep 17 00:00:00 2001 From: MatthewPocock Date: Sun, 25 Feb 2024 22:07:40 +1100 Subject: [PATCH 2/3] fix install requires --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0fe7f40..29cd0ff 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ def _get_plugin_version(): ] }, install_requires=[ - "dbt-core>=1.5.0" + "dbt-core~=1.5.0" ], classifiers=[ 'Development Status :: 4 - Beta', From ed6cda0e5093869b0721305e4141ca195299ac98 Mon Sep 17 00:00:00 2001 From: MatthewPocock Date: Sat, 20 Apr 2024 19:50:05 +1000 Subject: [PATCH 3/3] use socket gethostname for unique id --- dbt/adapters/sqlite/connections.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dbt/adapters/sqlite/connections.py b/dbt/adapters/sqlite/connections.py index 0c48098..7f1ca19 100644 --- a/dbt/adapters/sqlite/connections.py +++ b/dbt/adapters/sqlite/connections.py @@ -2,9 +2,9 @@ from contextlib import contextmanager from dataclasses import dataclass, field import glob -import json import os.path import sqlite3 +from socket import gethostname from typing import Optional, Tuple, Any, Dict, List @@ -38,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 json.dumps(self.schemas_and_paths, sort_keys=True) + return gethostname() def _connection_keys(self): """ Keys to show when debugging """