Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6019903
feat: add prebuild invalidation via last_invalidated_at timestamp
mtojek Oct 30, 2025
90b75e1
fix: correct NullUUID and NullTime types in API call
mtojek Oct 30, 2025
f8a06c6
WIP
mtojek Oct 30, 2025
4eb3598
Revert "WIP"
mtojek Oct 30, 2025
d197762
codersdk
mtojek Oct 30, 2025
1af3e82
make gen
mtojek Oct 30, 2025
8ba1519
fix
mtojek Oct 30, 2025
7642b17
fix
mtojek Oct 30, 2025
1b574f8
fix: simplify UpdatePresetsLastInvalidatedAt query
mtojek Oct 30, 2025
67f73a7
change query
mtojek Oct 31, 2025
ef05f93
make gen
mtojek Oct 31, 2025
7b73191
fix: presets.sql
mtojek Oct 31, 2025
f9d8da2
make gen
mtojek Oct 31, 2025
d9bfb87
fix: api
mtojek Oct 31, 2025
8428e8a
wip
mtojek Oct 31, 2025
4cf9634
fix: no display_name
mtojek Oct 31, 2025
4e1bf2c
make gen
mtojek Oct 31, 2025
6ee1b31
fix: api
mtojek Oct 31, 2025
0c79a38
make gen
mtojek Oct 31, 2025
3e15712
fix: swagger
mtojek Oct 31, 2025
22e9f30
make gen
mtojek Oct 31, 2025
9aa7308
fix: swagger
mtojek Oct 31, 2025
db67c88
make gen
mtojek Oct 31, 2025
27c06d8
fix: dbauthz
mtojek Oct 31, 2025
18e6d85
move endpoint to enterprise
mtojek Oct 31, 2025
d8ecbab
move endpoint to enterprise
mtojek Oct 31, 2025
1d9e9d8
make gen
mtojek Oct 31, 2025
af6a27f
fmt
mtojek Oct 31, 2025
a785723
fix: extract
mtojek Oct 31, 2025
d8cec90
fix: route
mtojek Oct 31, 2025
0b745d6
fix: route
mtojek Oct 31, 2025
1ca2dcd
Merge branch 'main' into 17917-prebuilds-invalidation
mtojek Nov 18, 2025
47afba2
fix: migrations
mtojek Nov 18, 2025
1e7dab9
integration test
mtojek Nov 18, 2025
abaf831
given when then
mtojek Nov 18, 2025
d6e43da
preset tests
mtojek Nov 18, 2025
5e6af50
fmt
mtojek Nov 18, 2025
41204b0
Update coderd/prebuilds/global_snapshot.go
mtojek Nov 19, 2025
4750292
Update codersdk/templates.go
mtojek Nov 19, 2025
ef725e9
Update enterprise/coderd/templates_test.go
mtojek Nov 19, 2025
89b109a
Update enterprise/coderd/templates.go
mtojek Nov 19, 2025
8ff8bdb
renaming to presets
mtojek Nov 19, 2025
d129996
more renaming
mtojek Nov 19, 2025
aebd96c
make gen
mtojek Nov 19, 2025
ace7e96
wip
mtojek Nov 19, 2025
ae73a5b
wip
mtojek Nov 19, 2025
07cb43b
fix: templates_test.go
mtojek Nov 19, 2025
f9304d5
fix
mtojek Nov 19, 2025
3f7b6e2
make gen
mtojek Nov 19, 2025
6942ddc
fix
mtojek Nov 19, 2025
8c27216
fix
mtojek Nov 19, 2025
e8e7829
test: prebuild is newer than invalidated
mtojek Nov 19, 2025
60b7558
add comment
mtojek Nov 19, 2025
52f97cd
Merge branch 'main' into 17917-prebuilds-invalidation
mtojek Nov 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,18 @@ func AIBridgeToolUsage(usage database.AIBridgeToolUsage) codersdk.AIBridgeToolUs
}
}

func InvalidatedPresets(invalidatedPresets []database.UpdatePresetsLastInvalidatedAtRow) []codersdk.InvalidatedPreset {
var presets []codersdk.InvalidatedPreset
for _, p := range invalidatedPresets {
presets = append(presets, codersdk.InvalidatedPreset{
TemplateName: p.TemplateName,
TemplateVersionName: p.TemplateVersionName,
PresetName: p.TemplateVersionPresetName,
})
}
return presets
}

func jsonOrEmptyMap(rawMessage pqtype.NullRawMessage) map[string]any {
var m map[string]any
if !rawMessage.Valid {
Expand Down
14 changes: 14 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,20 @@ func (q *querier) UpdatePresetPrebuildStatus(ctx context.Context, arg database.U
return q.db.UpdatePresetPrebuildStatus(ctx, arg)
}

func (q *querier) UpdatePresetsLastInvalidatedAt(ctx context.Context, arg database.UpdatePresetsLastInvalidatedAtParams) ([]database.UpdatePresetsLastInvalidatedAtRow, error) {
// Fetch template to check authorization
template, err := q.db.GetTemplateByID(ctx, arg.TemplateID)
if err != nil {
return nil, err
}

if err := q.authorizeContext(ctx, policy.ActionUpdate, template); err != nil {
return nil, err
}

return q.db.UpdatePresetsLastInvalidatedAt(ctx, arg)
}

func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerDaemon); err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,13 @@ func (s *MethodTestSuite) TestTemplate() {
dbm.EXPECT().UpsertTemplateUsageStats(gomock.Any()).Return(nil).AnyTimes()
check.Asserts(rbac.ResourceSystem, policy.ActionUpdate)
}))
s.Run("UpdatePresetsLastInvalidatedAt", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
t1 := testutil.Fake(s.T(), faker, database.Template{})
arg := database.UpdatePresetsLastInvalidatedAtParams{LastInvalidatedAt: sql.NullTime{Valid: true, Time: dbtime.Now()}, TemplateID: t1.ID}
dbm.EXPECT().GetTemplateByID(gomock.Any(), t1.ID).Return(t1, nil).AnyTimes()
dbm.EXPECT().UpdatePresetsLastInvalidatedAt(gomock.Any(), arg).Return([]database.UpdatePresetsLastInvalidatedAtRow{}, nil).AnyTimes()
check.Args(arg).Asserts(t1, policy.ActionUpdate)
}))
}

func (s *MethodTestSuite) TestUser() {
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbfake/dbfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ func (t TemplateVersionBuilder) Do() TemplateVersionResponse {
IsDefault: false,
Description: preset.Description,
Icon: preset.Icon,
LastInvalidatedAt: preset.LastInvalidatedAt,
})
t.logger.Debug(context.Background(), "added preset",
slog.F("preset_id", prst.ID),
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ func Preset(t testing.TB, db database.Store, seed database.InsertPresetParams) d
IsDefault: seed.IsDefault,
Description: seed.Description,
Icon: seed.Icon,
LastInvalidatedAt: seed.LastInvalidatedAt,
})
require.NoError(t, err, "insert preset")
return preset
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template_version_presets DROP COLUMN last_invalidated_at;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE template_version_presets ADD COLUMN last_invalidated_at TIMESTAMPTZ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder to check migration number before merge! 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked 👍 Last in mainline 398.

Thanks for the diligence!

3 changes: 2 additions & 1 deletion coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading