snowshu.adapters.target_adapters.base_target_adapter

class snowshu.adapters.target_adapters.base_target_adapter.BaseTargetAdapter(replica_metadata: dict)

Bases: snowshu.adapters.base_sql_adapter.BaseSQLAdapter

All target adapters inherit from this one.

ALLOWED_CREDENTIALS = []
DOCKER_TARGET_PORT = 9999
REQUIRED_CREDENTIALS = ['user', 'password', 'host', 'port', 'database']
copy_replica_data() → Tuple[bool, str]

A service function that copies replica data to a shared location

create_all_database_extensions()
create_and_load_relation(relation) → None
create_database_if_not_exists(database: str) → str
create_function_if_available(function: str, relations: Iterable[Relation]) → None

Applies all available source functions to target.

Looks for a function sql file in ./functions, executes against target for each db if it is.

Parameters
  • function – The name of the function, must match the sql file name exactly.

  • relations – An iterable of relations to apply the function to.

create_or_replace_view(relation) → None

Creates a view of the specified relation in the target adapter.

Must be defined in downstream adapter due to possibility of having different create syntax in various dbs

Parameters

relation – the Relation object to be created as a view.

create_schema_if_not_exists(database: str, schema: str) → str
enable_cross_database() → None

Create x-database links, if available to the target.

Parameters

relations – an iterable of relations to collect databases and schemas from.

finalize_replica() → None

Converts all containers to respective replicas, creates ‘latest’ if any on the running containers are of local arch

image_finalize_bash_commands() → List[str]

returns an ordered list of raw bash commands used to finalize the image.

For many target images some bash cleanup is required, such as remounting data or setting envars. This method returns the ordered commands to do this finalization.

Note

These commands will be run using bin/bash -c execution.

Returns

a list of strings to be run against the container in order.

initialize_replica(source_adapter_name: str, incremental_image: str = None) → None
Launches a container and initializes the replica.

Should be defined in specific target adapters due to different setup of different dbs

Parameters
  • source_adapter_name – the classname of the source adapter

  • incremental_image – the name of incremental image to initialize, if specified will override default image

load_data_into_relation(relation: snowshu.core.models.relation.Relation) → None
quoted_dot_notation(rel: snowshu.core.models.relation.Relation) → str
target_database_is_ready() → bool