fix(milestones): use previous spelling for milestone types (#8886)

# Which Problems Are Solved

https://github.com/zitadel/zitadel/pull/8788 accidentally changed the
spelling of milestone types from PascalCase to snake_case. This breaks
systems where `milestone.pushed` events already exist.

# How the Problems Are Solved

- Use PascalCase again
- Prefix event types with v2. (Previous pushed event type was anyway
ignored).
- Create `milstones3` projection

# Additional Changes

None

# Additional Context

relates to #8788
This commit is contained in:
Livio Spring
2024-11-11 12:28:27 +01:00
committed by GitHub
parent 4a354a568d
commit fb6579e456
8 changed files with 51 additions and 54 deletions

View File

@@ -11,14 +11,14 @@ import (
var (
expectedMilestoneQuery = regexp.QuoteMeta(`
SELECT projections.milestones2.instance_id,
SELECT projections.milestones3.instance_id,
projections.instance_domains.domain,
projections.milestones2.reached_date,
projections.milestones2.last_pushed_date,
projections.milestones2.type,
projections.milestones3.reached_date,
projections.milestones3.last_pushed_date,
projections.milestones3.type,
COUNT(*) OVER ()
FROM projections.milestones2 AS OF SYSTEM TIME '-1 ms'
LEFT JOIN projections.instance_domains ON projections.milestones2.instance_id = projections.instance_domains.instance_id
FROM projections.milestones3 AS OF SYSTEM TIME '-1 ms'
LEFT JOIN projections.instance_domains ON projections.milestones3.instance_id = projections.instance_domains.instance_id
`)
milestoneCols = []string{

View File

@@ -10,7 +10,7 @@ import (
)
const (
MilestonesProjectionTable = "projections.milestones2"
MilestonesProjectionTable = "projections.milestones3"
MilestoneColumnInstanceID = "instance_id"
MilestoneColumnType = "type"
@@ -77,9 +77,6 @@ func (p *milestoneProjection) reducePushed(event eventstore.Event) (*handler.Sta
if err != nil {
return nil, err
}
if e.Agg.Version != milestone.AggregateVersion {
return handler.NewNoOpStatement(event), nil // Skip v1 events.
}
if e.MilestoneType != milestone.InstanceDeleted {
return handler.NewUpdateStatement(
event,

View File

@@ -31,7 +31,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
event: getEvent(timedTestEvent(
milestone.ReachedEventType,
milestone.AggregateType,
[]byte(`{"type": "instance_created"}`),
[]byte(`{"type": "InstanceCreated"}`),
now,
withVersion(milestone.AggregateVersion),
), milestone.ReachedEventMapper),
@@ -43,7 +43,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO projections.milestones2 (instance_id, type, reached_date) VALUES ($1, $2, $3)",
expectedStmt: "INSERT INTO projections.milestones3 (instance_id, type, reached_date) VALUES ($1, $2, $3)",
expectedArgs: []interface{}{
"instance-id",
milestone.InstanceCreated,
@@ -60,7 +60,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
event: getEvent(timedTestEvent(
milestone.ReachedEventType,
milestone.AggregateType,
[]byte(`{"type": "instance_created", "reachedDate":"2006-01-02T15:04:05Z"}`),
[]byte(`{"type": "InstanceCreated", "reachedDate":"2006-01-02T15:04:05Z"}`),
now,
withVersion(milestone.AggregateVersion),
), milestone.ReachedEventMapper),
@@ -72,7 +72,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "INSERT INTO projections.milestones2 (instance_id, type, reached_date) VALUES ($1, $2, $3)",
expectedStmt: "INSERT INTO projections.milestones3 (instance_id, type, reached_date) VALUES ($1, $2, $3)",
expectedArgs: []interface{}{
"instance-id",
milestone.InstanceCreated,
@@ -89,7 +89,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
event: getEvent(timedTestEvent(
milestone.PushedEventType,
milestone.AggregateType,
[]byte(`{"type": "project_created"}`),
[]byte(`{"type": "ProjectCreated"}`),
now,
withVersion(milestone.AggregateVersion),
), milestone.PushedEventMapper),
@@ -101,7 +101,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.milestones2 SET last_pushed_date = $1 WHERE (instance_id = $2) AND (type = $3)",
expectedStmt: "UPDATE projections.milestones3 SET last_pushed_date = $1 WHERE (instance_id = $2) AND (type = $3)",
expectedArgs: []interface{}{
now,
"instance-id",
@@ -118,7 +118,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
event: getEvent(timedTestEvent(
milestone.PushedEventType,
milestone.AggregateType,
[]byte(`{"type": "project_created", "pushedDate":"2006-01-02T15:04:05Z"}`),
[]byte(`{"type": "ProjectCreated", "pushedDate":"2006-01-02T15:04:05Z"}`),
now,
withVersion(milestone.AggregateVersion),
), milestone.PushedEventMapper),
@@ -130,7 +130,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "UPDATE projections.milestones2 SET last_pushed_date = $1 WHERE (instance_id = $2) AND (type = $3)",
expectedStmt: "UPDATE projections.milestones3 SET last_pushed_date = $1 WHERE (instance_id = $2) AND (type = $3)",
expectedArgs: []interface{}{
date,
"instance-id",
@@ -147,7 +147,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
event: getEvent(testEvent(
milestone.PushedEventType,
milestone.AggregateType,
[]byte(`{"type": "instance_deleted"}`),
[]byte(`{"type": "InstanceDeleted"}`),
withVersion(milestone.AggregateVersion),
), milestone.PushedEventMapper),
},
@@ -158,7 +158,7 @@ func TestMilestonesProjection_reduces(t *testing.T) {
executer: &testExecuter{
executions: []execution{
{
expectedStmt: "DELETE FROM projections.milestones2 WHERE (instance_id = $1)",
expectedStmt: "DELETE FROM projections.milestones3 WHERE (instance_id = $1)",
expectedArgs: []interface{}{
"instance-id",
},

View File

@@ -7,7 +7,7 @@ import (
"github.com/zitadel/zitadel/internal/eventstore"
)
//go:generate enumer -type Type -json -linecomment -transform=snake
//go:generate enumer -type Type -json -linecomment
type Type int
const (
@@ -20,7 +20,7 @@ const (
)
const (
eventTypePrefix = "milestone."
eventTypePrefix = "milestone.v2."
ReachedEventType = eventTypePrefix + "reached"
PushedEventType = eventTypePrefix + "pushed"
)

View File

@@ -1,4 +1,4 @@
// Code generated by "enumer -type Type -json -linecomment -transform=snake"; DO NOT EDIT.
// Code generated by "enumer -type Type -json -linecomment"; DO NOT EDIT.
package milestone
@@ -8,11 +8,11 @@ import (
"strings"
)
const _TypeName = "instance_createdauthentication_succeeded_on_instanceproject_createdapplication_createdauthentication_succeeded_on_applicationinstance_deleted"
const _TypeName = "InstanceCreatedAuthenticationSucceededOnInstanceProjectCreatedApplicationCreatedAuthenticationSucceededOnApplicationInstanceDeleted"
var _TypeIndex = [...]uint8{0, 16, 52, 67, 86, 125, 141}
var _TypeIndex = [...]uint8{0, 15, 48, 62, 80, 116, 131}
const _TypeLowerName = "instance_createdauthentication_succeeded_on_instanceproject_createdapplication_createdauthentication_succeeded_on_applicationinstance_deleted"
const _TypeLowerName = "instancecreatedauthenticationsucceededoninstanceprojectcreatedapplicationcreatedauthenticationsucceededonapplicationinstancedeleted"
func (i Type) String() string {
i -= 1
@@ -37,27 +37,27 @@ func _TypeNoOp() {
var _TypeValues = []Type{InstanceCreated, AuthenticationSucceededOnInstance, ProjectCreated, ApplicationCreated, AuthenticationSucceededOnApplication, InstanceDeleted}
var _TypeNameToValueMap = map[string]Type{
_TypeName[0:16]: InstanceCreated,
_TypeLowerName[0:16]: InstanceCreated,
_TypeName[16:52]: AuthenticationSucceededOnInstance,
_TypeLowerName[16:52]: AuthenticationSucceededOnInstance,
_TypeName[52:67]: ProjectCreated,
_TypeLowerName[52:67]: ProjectCreated,
_TypeName[67:86]: ApplicationCreated,
_TypeLowerName[67:86]: ApplicationCreated,
_TypeName[86:125]: AuthenticationSucceededOnApplication,
_TypeLowerName[86:125]: AuthenticationSucceededOnApplication,
_TypeName[125:141]: InstanceDeleted,
_TypeLowerName[125:141]: InstanceDeleted,
_TypeName[0:15]: InstanceCreated,
_TypeLowerName[0:15]: InstanceCreated,
_TypeName[15:48]: AuthenticationSucceededOnInstance,
_TypeLowerName[15:48]: AuthenticationSucceededOnInstance,
_TypeName[48:62]: ProjectCreated,
_TypeLowerName[48:62]: ProjectCreated,
_TypeName[62:80]: ApplicationCreated,
_TypeLowerName[62:80]: ApplicationCreated,
_TypeName[80:116]: AuthenticationSucceededOnApplication,
_TypeLowerName[80:116]: AuthenticationSucceededOnApplication,
_TypeName[116:131]: InstanceDeleted,
_TypeLowerName[116:131]: InstanceDeleted,
}
var _TypeNames = []string{
_TypeName[0:16],
_TypeName[16:52],
_TypeName[52:67],
_TypeName[67:86],
_TypeName[86:125],
_TypeName[125:141],
_TypeName[0:15],
_TypeName[15:48],
_TypeName[48:62],
_TypeName[62:80],
_TypeName[80:116],
_TypeName[116:131],
}
// TypeString retrieves an enum value from the enum constants string name.