refactor(db): split revision preview from meta_json
Preview BIRD-фрагменты в config_revision_preview; meta_json только счётчик префиксов. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -26,9 +26,8 @@ func (p *Postgres) seedDemo(ctx context.Context) error {
|
||||
p1 := uuid.NewString()
|
||||
p2 := uuid.NewString()
|
||||
|
||||
preview := map[string]any{
|
||||
"preview_fragments": map[string]string{
|
||||
"bird.conf": `# EvoBGP demo bundle
|
||||
previewFrags := map[string]string{
|
||||
"bird.conf": `# EvoBGP demo bundle
|
||||
router id 192.0.2.1;
|
||||
|
||||
protocol device {
|
||||
@@ -39,15 +38,12 @@ protocol direct {
|
||||
ipv6;
|
||||
}
|
||||
`,
|
||||
"bird.d/evobgp_demo.conf": "# static demo fragment\n",
|
||||
},
|
||||
"materialized_prefix_count": 128,
|
||||
"bird.d/evobgp_demo.conf": "# static demo fragment\n",
|
||||
}
|
||||
previewB, _ := json.Marshal(preview)
|
||||
parentMeta, _ := json.Marshal(map[string]any{
|
||||
"preview_fragments": map[string]string{"bird.conf": "# parent revision\n"},
|
||||
"materialized_prefix_count": 0,
|
||||
})
|
||||
previewMeta, _ := json.Marshal(map[string]any{"materialized_prefix_count": 128})
|
||||
parentMeta, _ := json.Marshal(map[string]any{"materialized_prefix_count": 0})
|
||||
parentPreview, _ := json.Marshal(map[string]string{"bird.conf": "# parent revision\n"})
|
||||
previewFragsB, _ := json.Marshal(previewFrags)
|
||||
|
||||
tx, err := p.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -76,9 +72,17 @@ protocol direct {
|
||||
VALUES ($1,$2,'sha256:parent',NULL,$3::jsonb)`, parent, tid, string(parentMeta)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO config_revision_preview (revision_id, fragments) VALUES ($1::uuid, $2::jsonb)`, parent, string(parentPreview)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO config_revision (id, tenant_id, content_hash, parent_revision_id, meta_json)
|
||||
VALUES ($1,$2,'sha256:demo-rev-1',$3::uuid,$4::jsonb)`, rid, tid, parent, string(previewB)); err != nil {
|
||||
VALUES ($1,$2,'sha256:demo-rev-1',$3::uuid,$4::jsonb)`, rid, tid, parent, string(previewMeta)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
INSERT INTO config_revision_preview (revision_id, fragments) VALUES ($1::uuid, $2::jsonb)`, rid, string(previewFragsB)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := tx.Exec(ctx, `
|
||||
|
||||
Reference in New Issue
Block a user