EntityAPI: Save nested summary info in the SQL database (#61732)
This commit is contained in:
@@ -36,7 +36,7 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
{Name: "slug", Type: migrator.DB_NVarchar, Length: 189, Nullable: false}, // from title
|
||||
|
||||
// The raw entity body (any byte array)
|
||||
{Name: "body", Type: migrator.DB_LongBlob, Nullable: false},
|
||||
{Name: "body", Type: migrator.DB_LongBlob, Nullable: true}, // null when nested or remote
|
||||
{Name: "size", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "etag", Type: migrator.DB_NVarchar, Length: 32, Nullable: false, IsLatin: true}, // md5(body)
|
||||
{Name: "version", Type: migrator.DB_NVarchar, Length: 128, Nullable: false},
|
||||
@@ -79,6 +79,8 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
getLatinPathColumn("slug_path"), ///slug/slug/slug/
|
||||
{Name: "tree", Type: migrator.DB_Text, Nullable: false}, // JSON []{uid, title}
|
||||
{Name: "depth", Type: migrator.DB_Int, Nullable: false}, // starts at 1
|
||||
{Name: "left", Type: migrator.DB_Int, Nullable: false}, // MPTT
|
||||
{Name: "right", Type: migrator.DB_Int, Nullable: false}, // MPTT
|
||||
{Name: "detached", Type: migrator.DB_Bool, Nullable: false}, // a parent folder was not found
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
@@ -93,9 +95,11 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
{Name: "grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: false},
|
||||
{Name: "label", Type: migrator.DB_NVarchar, Length: 191, Nullable: false},
|
||||
{Name: "value", Type: migrator.DB_NVarchar, Length: 1024, Nullable: false},
|
||||
{Name: "parent_grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: true},
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"grn", "label"}, Type: migrator.UniqueIndex},
|
||||
{Cols: []string{"parent_grn"}, Type: migrator.IndexType},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -104,6 +108,7 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
Columns: []*migrator.Column{
|
||||
// Source:
|
||||
{Name: "grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: false},
|
||||
{Name: "parent_grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: true},
|
||||
|
||||
// Address (defined in the body, not resolved, may be invalid and change)
|
||||
{Name: "kind", Type: migrator.DB_NVarchar, Length: 255, Nullable: false},
|
||||
@@ -120,6 +125,7 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
{Cols: []string{"grn"}, Type: migrator.IndexType},
|
||||
{Cols: []string{"kind"}, Type: migrator.IndexType},
|
||||
{Cols: []string{"resolved_to"}, Type: migrator.IndexType},
|
||||
{Cols: []string{"parent_grn"}, Type: migrator.IndexType},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -147,6 +153,34 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
},
|
||||
})
|
||||
|
||||
tables = append(tables, migrator.Table{
|
||||
Name: "entity_nested",
|
||||
Columns: []*migrator.Column{
|
||||
{Name: "grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: false, IsPrimaryKey: true},
|
||||
{Name: "parent_grn", Type: migrator.DB_NVarchar, Length: grnLength, Nullable: false},
|
||||
|
||||
// The entity identifier
|
||||
{Name: "tenant_id", Type: migrator.DB_BigInt, Nullable: false},
|
||||
{Name: "kind", Type: migrator.DB_NVarchar, Length: 255, Nullable: false},
|
||||
{Name: "uid", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},
|
||||
{Name: "folder", Type: migrator.DB_NVarchar, Length: 40, Nullable: false},
|
||||
|
||||
// Summary data (always extracted from the `body` column)
|
||||
{Name: "name", Type: migrator.DB_NVarchar, Length: 255, Nullable: false},
|
||||
{Name: "description", Type: migrator.DB_NVarchar, Length: 255, Nullable: true},
|
||||
{Name: "labels", Type: migrator.DB_Text, Nullable: true}, // JSON object
|
||||
{Name: "fields", Type: migrator.DB_Text, Nullable: true}, // JSON object
|
||||
{Name: "errors", Type: migrator.DB_Text, Nullable: true}, // JSON object
|
||||
},
|
||||
Indices: []*migrator.Index{
|
||||
{Cols: []string{"parent_grn"}},
|
||||
{Cols: []string{"kind"}},
|
||||
{Cols: []string{"folder"}},
|
||||
{Cols: []string{"uid"}},
|
||||
{Cols: []string{"tenant_id", "kind", "uid"}, Type: migrator.UniqueIndex},
|
||||
},
|
||||
})
|
||||
|
||||
// !!! This should not run in production!
|
||||
// The object store SQL schema is still in active development and this
|
||||
// will only be called when the feature toggle is enabled
|
||||
@@ -158,7 +192,7 @@ func addEntityStoreMigrations(mg *migrator.Migrator) {
|
||||
// Migration cleanups: given that this is a complex setup
|
||||
// that requires a lot of testing before we are ready to push out of dev
|
||||
// this script lets us easy wipe previous changes and initialize clean tables
|
||||
suffix := " (v12)" // change this when we want to wipe and reset the object tables
|
||||
suffix := " (v31)" // change this when we want to wipe and reset the object tables
|
||||
mg.AddMigration("EntityStore init: cleanup"+suffix, migrator.NewRawSQLMigration(strings.TrimSpace(`
|
||||
DELETE FROM migration_log WHERE migration_id LIKE 'EntityStore init%';
|
||||
`)))
|
||||
|
||||
Reference in New Issue
Block a user