Skip to content

Commit

Permalink
Allow Unix socket connection rather than just TCP (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwallace582 authored Jan 10, 2024
1 parent 5fc842a commit 358d4e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions dbt/adapters/mariadb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,6 +63,7 @@ def _connection_keys(self):
"""
return (
"server",
"unix_socket",
"port",
"database",
"schema",
Expand All @@ -81,14 +83,18 @@ 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.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

Expand Down
10 changes: 8 additions & 2 deletions dbt/adapters/mysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,6 +62,7 @@ def _connection_keys(self):
"""
return (
"server",
"unix_socket",
"port",
"database",
"schema",
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions dbt/adapters/mysql5/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,6 +63,7 @@ def _connection_keys(self):
"""
return (
"server",
"unix_socket",
"port",
"database",
"schema",
Expand All @@ -81,14 +83,18 @@ 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.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

Expand Down

0 comments on commit 358d4e4

Please sign in to comment.