mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-15 20:57:15 +00:00
feat(ingest): Add option to change name of database for postgres (#2898)
This commit is contained in:
parent
267efe767f
commit
6e1b2cf4f7
@ -313,6 +313,7 @@ Extracts:
|
|||||||
- List of databases, schema, and tables
|
- List of databases, schema, and tables
|
||||||
- Column types associated with each table
|
- Column types associated with each table
|
||||||
- Also supports PostGIS extensions
|
- Also supports PostGIS extensions
|
||||||
|
- database_alias (optional) can be used to change the name of database to be ingested
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
source:
|
source:
|
||||||
@ -322,6 +323,7 @@ source:
|
|||||||
password: pass
|
password: pass
|
||||||
host_port: localhost:5432
|
host_port: localhost:5432
|
||||||
database: DemoDatabase
|
database: DemoDatabase
|
||||||
|
database_alias: DatabaseNameToBeIngested
|
||||||
include_views: True # whether to include views, defaults to True
|
include_views: True # whether to include views, defaults to True
|
||||||
# table_pattern/schema_pattern is same as above
|
# table_pattern/schema_pattern is same as above
|
||||||
# options is same as above
|
# options is same as above
|
||||||
|
@ -151,6 +151,7 @@ base_dev_requirements = {
|
|||||||
"looker",
|
"looker",
|
||||||
"glue",
|
"glue",
|
||||||
"oracle",
|
"oracle",
|
||||||
|
"postgres",
|
||||||
"sagemaker",
|
"sagemaker",
|
||||||
"datahub-kafka",
|
"datahub-kafka",
|
||||||
"datahub-rest",
|
"datahub-rest",
|
||||||
|
@ -29,6 +29,8 @@ class PostgresConfig(BasicSQLAlchemyConfig):
|
|||||||
|
|
||||||
def get_identifier(self, schema: str, table: str) -> str:
|
def get_identifier(self, schema: str, table: str) -> str:
|
||||||
regular = f"{schema}.{table}"
|
regular = f"{schema}.{table}"
|
||||||
|
if self.database_alias:
|
||||||
|
return f"{self.database_alias}.{regular}"
|
||||||
if self.database:
|
if self.database:
|
||||||
return f"{self.database}.{regular}"
|
return f"{self.database}.{regular}"
|
||||||
return regular
|
return regular
|
||||||
|
@ -120,6 +120,7 @@ class BasicSQLAlchemyConfig(SQLAlchemyConfig):
|
|||||||
password: Optional[pydantic.SecretStr] = None
|
password: Optional[pydantic.SecretStr] = None
|
||||||
host_port: str
|
host_port: str
|
||||||
database: Optional[str] = None
|
database: Optional[str] = None
|
||||||
|
database_alias: Optional[str] = None
|
||||||
scheme: str
|
scheme: str
|
||||||
|
|
||||||
def get_sql_alchemy_url(self, uri_opts=None):
|
def get_sql_alchemy_url(self, uri_opts=None):
|
||||||
|
21
metadata-ingestion/tests/unit/test_postgres_source.py
Normal file
21
metadata-ingestion/tests/unit/test_postgres_source.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from datahub.ingestion.source.postgres import PostgresConfig
|
||||||
|
|
||||||
|
|
||||||
|
def _base_config():
|
||||||
|
return {"username": "user", "password": "password", "host_port": "host:1521"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_database_alias_takes_precendence():
|
||||||
|
config = PostgresConfig.parse_obj(
|
||||||
|
{
|
||||||
|
**_base_config(),
|
||||||
|
"database_alias": "ops_database",
|
||||||
|
"database": "postgres",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert config.get_identifier("superset", "logs") == "ops_database.superset.logs"
|
||||||
|
|
||||||
|
|
||||||
|
def test_database_in_identifier():
|
||||||
|
config = PostgresConfig.parse_obj({**_base_config(), "database": "postgres"})
|
||||||
|
assert config.get_identifier("superset", "logs") == "postgres.superset.logs"
|
Loading…
x
Reference in New Issue
Block a user