Affects
- Reproduced on 1.12.14 and on
main / 2.0 (server 2.0.0). Not fixed by upgrading.
Summary
A recursive CSV import of a Database Service / Database / Database Schema silently wipes all table constraints (PRIMARY KEY, UNIQUE, and FOREIGN KEY relationships) on every table it processes, even though constraints are never represented in the CSV.
This is user-reachable from the UI: the Manage (⋮) → Export/Import on a Service / Database / Schema page issues importAsync?...&recursive=true, so a normal parent-level re-import in the UI drops constraints.
Steps to reproduce
- Create a table with
tableConstraints (e.g. a PRIMARY_KEY on id, a UNIQUE on email, and a FOREIGN_KEY on a column referring to another table's column).
- Export the parent Database Schema (or Database / Service) recursively:
GET /api/v1/databaseSchemas/name/{fqn}/export?recursive=true
- Re-import it unchanged:
PUT /api/v1/databaseSchemas/name/{fqn}/import?dryRun=false&recursive=true
- Fetch the table:
GET /api/v1/tables/name/{fqn}?fields=tableConstraints.
Expected
tableConstraints unchanged (nothing in the CSV should have removed them).
Actual
tableConstraints is empty [] — PK, UNIQUE, and FK all lost.
Root cause
EntityCsv.createTableEntity(...) (openmetadata-service .../csv/EntityCsv.java) fetches the existing table with a field set that omits tableConstraints:
table = getEntityWithDependencyResolution(
TABLE, tableFqn, "owners,tags,domains,extension", Include.NON_DELETED);
It then populates table-level fields from the CSV row and calls createEntity(...) → repository.createOrUpdate(...). Because tableConstraints was never loaded, the persisted table has tableConstraints = null, so the existing constraints are removed. (The recursive CSV has no constraints column, so they are not re-added.)
Suggested fix
Include tableConstraints (and tablePartition) in the createTableEntity fetch so they carry through the createOrUpdate unchanged. A regression test should assert that a recursive export→import round trip preserves PK/UNIQUE/FK.
Affects
main/2.0(server 2.0.0). Not fixed by upgrading.Summary
A recursive CSV import of a Database Service / Database / Database Schema silently wipes all table constraints (PRIMARY KEY, UNIQUE, and FOREIGN KEY relationships) on every table it processes, even though constraints are never represented in the CSV.
This is user-reachable from the UI: the Manage (⋮) → Export/Import on a Service / Database / Schema page issues
importAsync?...&recursive=true, so a normal parent-level re-import in the UI drops constraints.Steps to reproduce
tableConstraints(e.g. a PRIMARY_KEY onid, a UNIQUE onemail, and a FOREIGN_KEY on a column referring to another table's column).GET /api/v1/databaseSchemas/name/{fqn}/export?recursive=truePUT /api/v1/databaseSchemas/name/{fqn}/import?dryRun=false&recursive=trueGET /api/v1/tables/name/{fqn}?fields=tableConstraints.Expected
tableConstraintsunchanged (nothing in the CSV should have removed them).Actual
tableConstraintsis empty[]— PK, UNIQUE, and FK all lost.Root cause
EntityCsv.createTableEntity(...)(openmetadata-service.../csv/EntityCsv.java) fetches the existing table with a field set that omitstableConstraints:It then populates table-level fields from the CSV row and calls
createEntity(...)→repository.createOrUpdate(...). BecausetableConstraintswas never loaded, the persisted table hastableConstraints = null, so the existing constraints are removed. (The recursive CSV has no constraints column, so they are not re-added.)Suggested fix
Include
tableConstraints(andtablePartition) in thecreateTableEntityfetch so they carry through thecreateOrUpdateunchanged. A regression test should assert that a recursive export→import round trip preserves PK/UNIQUE/FK.