Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semi-revert previous dsrc migration fix (#137); implement a proper fix #159

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class MetricaApiDataSourceMigrator(DefaultSQLDataSourceMigrator):
table_source_type = SOURCE_TYPE_METRICA_API
with_db_name = True


class AppMetricaApiDataSourceMigrator(DefaultSQLDataSourceMigrator):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from dl_core.connectors.sql_base.data_source_migration import DefaultSQLDataSourceMigrator
from dl_core.data_source_spec.sql import StandardSchemaSQLDataSourceSpec

from dl_connector_postgresql.core.postgresql.constants import (
SOURCE_TYPE_PG_SUBSELECT,
Expand All @@ -8,5 +9,7 @@

class PostgreSQLDataSourceMigrator(DefaultSQLDataSourceMigrator):
table_source_type = SOURCE_TYPE_PG_TABLE
table_dsrc_spec_cls = StandardSchemaSQLDataSourceSpec
subselect_source_type = SOURCE_TYPE_PG_SUBSELECT

default_schema_name = "public"
35 changes: 18 additions & 17 deletions lib/dl_core/dl_core/connectors/sql_base/data_source_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def _resolve_schema_name_for_import(
) -> Optional[str]:
assert attr_name == "schema_name"
schema_name: Optional[str] = getattr(migration_dto, attr_name, None)
if schema_name == self.default_schema_name:
schema_name = None
if schema_name is None:
schema_name = self.default_schema_name
return schema_name

def get_migration_specs(self) -> list[MigrationSpec]:
result: list[MigrationSpec] = []
if self.table_source_type is not None:
assert self.table_dsrc_spec_cls is not None

if self.with_db_name:
result.append(
MigrationSpec(
Expand All @@ -90,23 +91,23 @@ def get_migration_specs(self) -> list[MigrationSpec]:
),
)
)
else:
result.append(
MigrationSpec(
source_type=self.table_source_type,
dto_cls=SQLTableDSMI,
dsrc_spec_cls=self.table_dsrc_spec_cls,
migration_mapping_items=(
MigrationKeyMappingItem(
migration_dto_key="schema_name",
source_spec_key="schema_name",
custom_export_resolver=self._resolve_schema_name_for_export,
custom_import_resolver=self._resolve_schema_name_for_import,
),
MigrationKeyMappingItem(migration_dto_key="table_name", source_spec_key="table_name"),

result.append(
MigrationSpec(
source_type=self.table_source_type,
dto_cls=SQLTableDSMI,
dsrc_spec_cls=self.table_dsrc_spec_cls,
migration_mapping_items=(
MigrationKeyMappingItem(
migration_dto_key="schema_name",
source_spec_key="schema_name",
custom_export_resolver=self._resolve_schema_name_for_export,
custom_import_resolver=self._resolve_schema_name_for_import,
),
)
MigrationKeyMappingItem(migration_dto_key="table_name", source_spec_key="table_name"),
),
)
)

if self.subselect_source_type is not None:
assert self.subselect_dsrc_spec_cls is not None
Expand Down
Loading