diff --git a/CHANGELOG.md b/CHANGELOG.md index be5c4e9..ac88daf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Migrate CircleCI to GitHub Actions ([#120](https://github.com/dbeatty10/dbt-mysql/issues/120)) - Support dbt v1.4 ([#146](https://github.com/dbeatty10/dbt-mysql/pull/146)) - Support dbt v1.5 ([#145](https://github.com/dbeatty10/dbt-mysql/issues/145)) +- Support connecting via UNIX sockets ([#164](https://github.com/dbeatty10/dbt-mysql/issues/164)) ### Fixes - Fix incremental composite keys ([#144](https://github.com/dbeatty10/dbt-mysql/issues/144)) @@ -12,7 +13,7 @@ - [@lpezet](https://github.com/lpezet) ([#146](https://github.com/dbeatty10/dbt-mysql/pull/146)) - [@moszutij](https://github.com/moszutij) ([#146](https://github.com/dbeatty10/dbt-mysql/pull/146), [#144](https://github.com/dbeatty10/dbt-mysql/issues/144)) - [@wesen](https://github.com/wesen) ([#146](https://github.com/dbeatty10/dbt-mysql/pull/146)) -- [@mwallace582](https://github.com/mwallace582) ([#162](https://github.com/dbeatty10/dbt-mysql/pull/162), [#163](https://github.com/dbeatty10/dbt-mysql/pull/163)) +- [@mwallace582](https://github.com/mwallace582) ([#162](https://github.com/dbeatty10/dbt-mysql/pull/162), [#163](https://github.com/dbeatty10/dbt-mysql/pull/163), [#164](https://github.com/dbeatty10/dbt-mysql/issues/164)) ## dbt-mysql 1.1.0 (Feb 5, 2023) diff --git a/dbt/adapters/mariadb/connections.py b/dbt/adapters/mariadb/connections.py index 9583a7d..6b30f9a 100644 --- a/dbt/adapters/mariadb/connections.py +++ b/dbt/adapters/mariadb/connections.py @@ -17,7 +17,8 @@ @dataclass(init=False) class MariaDBCredentials(Credentials): - server: str + server: Optional[str] = None + unix_socket: Optional[str] = None port: Optional[int] = None database: Optional[str] = None schema: str @@ -62,6 +63,7 @@ def _connection_keys(self): """ return ( "server", + "unix_socket", "port", "database", "schema", @@ -81,7 +83,6 @@ def open(cls, connection): credentials = cls.get_credentials(connection.credentials) kwargs = {} - kwargs["host"] = credentials.server kwargs["user"] = credentials.username kwargs["passwd"] = credentials.password kwargs["buffered"] = True @@ -89,6 +90,11 @@ def open(cls, connection): if credentials.ssl_disabled: kwargs["ssl_disabled"] = credentials.ssl_disabled + if credentials.server: + kwargs["host"] = credentials.server + elif credentials.unix_socket: + kwargs["unix_socket"] = credentials.unix_socket + if credentials.port: kwargs["port"] = credentials.port diff --git a/dbt/adapters/mysql/connections.py b/dbt/adapters/mysql/connections.py index 459782c..d8932dd 100644 --- a/dbt/adapters/mysql/connections.py +++ b/dbt/adapters/mysql/connections.py @@ -17,7 +17,8 @@ @dataclass(init=False) class MySQLCredentials(Credentials): - server: str + server: Optional[str] = None + unix_socket: Optional[str] = None port: Optional[int] = None database: Optional[str] = None schema: str @@ -61,6 +62,7 @@ def _connection_keys(self): """ return ( "server", + "unix_socket", "port", "database", "schema", @@ -80,11 +82,15 @@ def open(cls, connection): credentials = cls.get_credentials(connection.credentials) kwargs = {} - kwargs["host"] = credentials.server kwargs["user"] = credentials.username kwargs["passwd"] = credentials.password kwargs["buffered"] = True + if credentials.server: + kwargs["host"] = credentials.server + elif credentials.unix_socket: + kwargs["unix_socket"] = credentials.unix_socket + if credentials.port: kwargs["port"] = credentials.port diff --git a/dbt/adapters/mysql5/connections.py b/dbt/adapters/mysql5/connections.py index 6c9df5c..f1481a2 100644 --- a/dbt/adapters/mysql5/connections.py +++ b/dbt/adapters/mysql5/connections.py @@ -17,7 +17,8 @@ @dataclass(init=False) class MySQLCredentials(Credentials): - server: str + server: Optional[str] = None + unix_socket: Optional[str] = None port: Optional[int] = None database: Optional[str] = None schema: str @@ -62,6 +63,7 @@ def _connection_keys(self): """ return ( "server", + "unix_socket", "port", "database", "schema", @@ -81,7 +83,6 @@ def open(cls, connection): credentials = cls.get_credentials(connection.credentials) kwargs = {} - kwargs["host"] = credentials.server kwargs["user"] = credentials.username kwargs["passwd"] = credentials.password kwargs["buffered"] = True @@ -89,6 +90,11 @@ def open(cls, connection): if credentials.ssl_disabled: kwargs["ssl_disabled"] = credentials.ssl_disabled + if credentials.server: + kwargs["host"] = credentials.server + elif credentials.unix_socket: + kwargs["unix_socket"] = credentials.unix_socket + if credentials.port: kwargs["port"] = credentials.port