按 schema 版本选 profile 并以 information_schema 能力探测放行,取代写死的 version==74;未知版本、脏库、缺表缺列、跨版本搬运一律拒绝并点名原因。 0.9.0 的索引名改从部署配置解析,wiki_log_entries 按 profile 变为可选, 归档部件集合随之一致。
This commit is contained in:
@@ -67,10 +67,13 @@ func (importer *PostgresImporter) Replace(ctx context.Context, identity Postgres
|
||||
return errors.New("begin PostgreSQL document import")
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
var version int
|
||||
var dirty bool
|
||||
if err := tx.QueryRow(ctx, `SELECT version, dirty FROM schema_migrations LIMIT 1`).Scan(&version, &dirty); err != nil || version != 74 || dirty {
|
||||
return errors.New("target WeKnora schema contract mismatch")
|
||||
profile, err := ResolveSchemaProfile(ctx, tx, "target WeKnora")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 目标版本必须与归档同 profile:0.7.1 的归档不能写进 0.9.0,反之亦然。
|
||||
if err := requireSameProfile(snapshot.SchemaVersion, profile, "import"); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1, 0))`, identity.KnowledgeID); err != nil {
|
||||
return errors.New("lock target knowledge")
|
||||
@@ -177,10 +180,12 @@ func (importer *PostgresImporter) ReplaceWiki(ctx context.Context, identity Post
|
||||
return errors.New("begin PostgreSQL wiki import")
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
var version int
|
||||
var dirty bool
|
||||
if err := tx.QueryRow(ctx, `SELECT version, dirty FROM schema_migrations LIMIT 1`).Scan(&version, &dirty); err != nil || version != 74 || dirty {
|
||||
return errors.New("target WeKnora schema contract mismatch")
|
||||
profile, err := ResolveSchemaProfile(ctx, tx, "target WeKnora")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := requireSameProfile(snapshot.SchemaVersion, profile, "wiki import"); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1, 1))`, identity.KnowledgeBaseID); err != nil {
|
||||
return errors.New("lock target wiki knowledge base")
|
||||
@@ -205,10 +210,8 @@ func (importer *PostgresImporter) Disable(ctx context.Context, identity Postgres
|
||||
return errors.New("begin PostgreSQL disable")
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
var version int
|
||||
var dirty bool
|
||||
if err := tx.QueryRow(ctx, `SELECT version, dirty FROM schema_migrations LIMIT 1`).Scan(&version, &dirty); err != nil || version != 74 || dirty {
|
||||
return errors.New("target WeKnora schema contract mismatch")
|
||||
if _, err := ResolveSchemaProfile(ctx, tx, "target WeKnora"); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock(hashtextextended($1, 0))`, identity.KnowledgeID); err != nil {
|
||||
return errors.New("lock target knowledge")
|
||||
@@ -244,9 +247,15 @@ func (importer *PostgresImporter) prepareSnapshot(identity PostgresIdentity, sna
|
||||
return PostgresSnapshot{}, nil, nil, errors.New("PostgreSQL import snapshot is incomplete")
|
||||
}
|
||||
prepared := cloneSnapshot(snapshot)
|
||||
// 表集合按快照所属 profile 判定:0.9.0 的归档里有 wiki_page_issues,
|
||||
// 面向单文档发布的白名单没有它,用白名单会把合法归档判成非法。
|
||||
profile, err := snapshot.schemaProfile()
|
||||
if err != nil {
|
||||
return PostgresSnapshot{}, nil, nil, err
|
||||
}
|
||||
known := map[string]bool{}
|
||||
for index, table := range prepared.Tables {
|
||||
if !validReleaseTable(table.Name) || known[table.Name] || table.RowCount != len(table.Rows) || newTableSnapshot(table.Name, table.Rows).SHA256 != table.SHA256 {
|
||||
if !profile.HasTable(table.Name) || known[table.Name] || table.RowCount != len(table.Rows) || newTableSnapshot(table.Name, table.Rows).SHA256 != table.SHA256 {
|
||||
return PostgresSnapshot{}, nil, nil, errors.New("PostgreSQL import snapshot is invalid")
|
||||
}
|
||||
known[table.Name] = true
|
||||
|
||||
Reference in New Issue
Block a user