mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
cd3ffbd3eb
# Which Problems Are Solved The mirror command used the wrong position to filter for events if different database technologies for source and destination were used. # How the Problems Are Solved The statements which diverge are stored on the client so that different technologies can use different statements. # Additional Context - https://discord.com/channels/927474939156643850/1256396896243552347
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/zitadel/logging"
|
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
"github.com/zitadel/zitadel/internal/v2/eventstore"
|
|
)
|
|
|
|
var (
|
|
_ eventstore.Pusher = (*Storage)(nil)
|
|
_ eventstore.Querier = (*Storage)(nil)
|
|
)
|
|
|
|
type Storage struct {
|
|
client *database.DB
|
|
config *Config
|
|
pushPositionStmt string
|
|
}
|
|
|
|
type Config struct {
|
|
MaxRetries uint32
|
|
}
|
|
|
|
func New(client *database.DB, config *Config) *Storage {
|
|
initPushStmt(client.Type())
|
|
return &Storage{
|
|
client: client,
|
|
config: config,
|
|
pushPositionStmt: initPushStmt(client.Type()),
|
|
}
|
|
}
|
|
|
|
func initPushStmt(typ string) string {
|
|
switch typ {
|
|
case "cockroach":
|
|
return ", hlc_to_timestamp(cluster_logical_timestamp()), cluster_logical_timestamp()"
|
|
case "postgres":
|
|
return ", statement_timestamp(), EXTRACT(EPOCH FROM clock_timestamp())"
|
|
default:
|
|
logging.WithFields("database_type", typ).Panic("position statement for type not implemented")
|
|
return ""
|
|
}
|
|
}
|
|
|
|
// Health implements eventstore.Pusher.
|
|
func (s *Storage) Health(ctx context.Context) error {
|
|
return s.client.PingContext(ctx)
|
|
}
|