Skip to content

Commit 37c2181

Browse files
committed
feat: format_version
1 parent 6f1501b commit 37c2181

4 files changed

Lines changed: 35 additions & 26 deletions

File tree

internal/schema/introspect.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,18 @@ func IntrospectSchema(ctx context.Context, pool Querier) (*SchemaSnapshot, error
144144
)
145145

146146
snap := &SchemaSnapshot{
147-
PgVersion: pgVersion,
148-
Database: database,
149-
Timestamp: time.Now().UTC(),
150-
Tables: tables,
151-
Enums: enums,
152-
Domains: domains,
153-
Composites: composites,
154-
Views: views,
155-
Functions: functions,
156-
Extensions: extensions,
157-
GUCs: gucs,
147+
FormatVersion: FormatVersion,
148+
PgVersion: pgVersion,
149+
Database: database,
150+
Timestamp: time.Now().UTC(),
151+
Tables: tables,
152+
Enums: enums,
153+
Domains: domains,
154+
Composites: composites,
155+
Views: views,
156+
Functions: functions,
157+
Extensions: extensions,
158+
GUCs: gucs,
158159
}
159160
snap.ContentHash = ComputeContentHash(snap)
160161
return snap, nil
@@ -249,7 +250,6 @@ type (
249250
name string
250251
definition string
251252
}
252-
253253
)
254254

255255
// Fetchers - each uses a named query from sql/introspect.sql
@@ -495,7 +495,6 @@ func fetchTriggers(ctx context.Context, pool Querier) ([]rawTrigger, error) {
495495
})
496496
}
497497

498-
499498
func fetchViews(ctx context.Context, pool Querier) ([]View, error) {
500499
rows, err := query(ctx, pool, "fetch-views")
501500
if err != nil {

internal/schema/snapshot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type (
4646

4747
// Enum values.
4848
const (
49+
FormatVersion = snapshot.FormatVersion
50+
4951
ConstraintPrimaryKey = snapshot.ConstraintPrimaryKey
5052
ConstraintForeignKey = snapshot.ConstraintForeignKey
5153
ConstraintUnique = snapshot.ConstraintUnique

internal/schema/stats.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func CapturePlannerStats(ctx context.Context, pool Querier, schemaRefHash string
4141
}
4242

4343
snap := &PlannerStatsSnapshot{
44+
FormatVersion: FormatVersion,
4445
SchemaRefHash: schemaRefHash,
4546
Database: database,
4647
Timestamp: time.Now().UTC(),
@@ -70,6 +71,7 @@ func CaptureActivityStats(ctx context.Context, pool Querier, schemaRefHash, sour
7071
}
7172

7273
snap := &ActivityStatsSnapshot{
74+
FormatVersion: FormatVersion,
7375
SchemaRefHash: schemaRefHash,
7476
Node: *node,
7577
Tables: tables,

pkg/snapshot/types.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,25 @@ import (
77
"time"
88
)
99

10+
// 0 means legacy. not hashed.
11+
const FormatVersion = 1
12+
1013
// DDL-only schema snapshot; sizing/activity live in AnnotatedSchema
1114
type SchemaSnapshot struct {
12-
PgVersion string `json:"pg_version"`
13-
Database string `json:"database"`
14-
Timestamp time.Time `json:"timestamp"`
15-
ContentHash string `json:"content_hash"`
16-
Source *string `json:"source,omitempty"`
17-
Tables []Table `json:"tables"`
18-
Enums []EnumType `json:"enums"`
19-
Domains []DomainType `json:"domains"`
20-
Composites []CompositeType `json:"composites"`
21-
Views []View `json:"views"`
22-
Functions []Function `json:"functions"`
23-
Extensions []Extension `json:"extensions"`
24-
GUCs []GucSetting `json:"gucs"`
15+
FormatVersion int `json:"format_version"`
16+
PgVersion string `json:"pg_version"`
17+
Database string `json:"database"`
18+
Timestamp time.Time `json:"timestamp"`
19+
ContentHash string `json:"content_hash"`
20+
Source *string `json:"source,omitempty"`
21+
Tables []Table `json:"tables"`
22+
Enums []EnumType `json:"enums"`
23+
Domains []DomainType `json:"domains"`
24+
Composites []CompositeType `json:"composites"`
25+
Views []View `json:"views"`
26+
Functions []Function `json:"functions"`
27+
Extensions []Extension `json:"extensions"`
28+
GUCs []GucSetting `json:"gucs"`
2529
}
2630

2731
type Table struct {
@@ -440,6 +444,7 @@ type IndexActivityEntry struct {
440444

441445
// Persisted planner inputs; schema_ref_hash binds rows to a SchemaSnapshot
442446
type PlannerStatsSnapshot struct {
447+
FormatVersion int `json:"format_version"`
443448
SchemaRefHash string `json:"schema_ref_hash"`
444449
ContentHash string `json:"content_hash"`
445450
Database string `json:"database"`
@@ -455,6 +460,7 @@ type PlannerStatsSnapshot struct {
455460

456461
// Persisted per-node activity counters
457462
type ActivityStatsSnapshot struct {
463+
FormatVersion int `json:"format_version"`
458464
SchemaRefHash string `json:"schema_ref_hash"`
459465
ContentHash string `json:"content_hash"`
460466
Node NodeIdentity `json:"node"`

0 commit comments

Comments
 (0)