fix: mark table deleted dependencies (#10476)

This commit is contained in:
NiharDoshi99 2023-03-09 14:45:05 +05:30 committed by GitHub
parent 4c6d184ef5
commit ddbc0311e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 4 deletions

View File

@ -11,6 +11,8 @@
"""
Table related pydantic definitions
"""
from typing import Optional
from pydantic import BaseModel
from metadata.generated.schema.entity.data.table import Table
@ -20,3 +22,4 @@ class DeleteTable(BaseModel):
"""Entity Reference of a table to be deleted"""
table: Table
mark_deleted_tables: Optional[bool] = False

View File

@ -339,7 +339,12 @@ class MetadataRestSink(Sink[Entity]):
def delete_table(self, record: DeleteTable):
try:
self.metadata.delete(entity=Table, entity_id=record.table.id)
self.metadata.delete(
entity=Table,
entity_id=record.table.id,
recursive=record.mark_deleted_tables,
)
logger.debug(
f"{record.table.name} doesn't exist in source state, marking it as deleted"
)

View File

@ -429,7 +429,10 @@ class DatabaseServiceSource(
)
for table in database_state:
if str(table.fullyQualifiedName.__root__) not in self.database_source_state:
yield DeleteTable(table=table)
yield DeleteTable(
table=table,
mark_deleted_tables=self.source_config.markDeletedTables,
)
def fetch_all_schema_and_delete_tables(self):
"""

View File

@ -381,9 +381,13 @@ public class TableResource extends EntityResource<Table, TableRepository> {
@QueryParam("hardDelete")
@DefaultValue("false")
boolean hardDelete,
@Parameter(description = "Recursively delete this entity and it's children. (Default `false`)")
@QueryParam("recursive")
@DefaultValue("false")
boolean recursive,
@Parameter(description = "Id of the table", schema = @Schema(type = "UUID")) @PathParam("id") UUID id)
throws IOException {
return delete(uriInfo, securityContext, id, false, hardDelete);
return delete(uriInfo, securityContext, id, recursive, hardDelete);
}
@DELETE

View File

@ -19,7 +19,7 @@
"default": "DatabaseMetadata"
},
"markDeletedTables": {
"description": "Optional configuration to soft delete tables in OpenMetadata if the source tables are deleted.",
"description": "Optional configuration to soft delete tables in OpenMetadata if the source tables are deleted. Also, if the table is deleted, all the associated entities like testSuite, lineage, etc., with that table will be deleted",
"type": "boolean",
"default": true
},