fix(mirror): use correct statements on push (#8414)

# 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
This commit is contained in:
Silvan
2024-08-12 12:33:45 +02:00
committed by GitHub
parent 3f25e36fbd
commit cd3ffbd3eb
4 changed files with 18 additions and 14 deletions

View File

@@ -12,13 +12,12 @@ import (
var (
_ eventstore.Pusher = (*Storage)(nil)
_ eventstore.Querier = (*Storage)(nil)
pushPositionStmt string
)
type Storage struct {
client *database.DB
config *Config
client *database.DB
config *Config
pushPositionStmt string
}
type Config struct {
@@ -28,19 +27,21 @@ type Config struct {
func New(client *database.DB, config *Config) *Storage {
initPushStmt(client.Type())
return &Storage{
client: client,
config: config,
client: client,
config: config,
pushPositionStmt: initPushStmt(client.Type()),
}
}
func initPushStmt(typ string) {
func initPushStmt(typ string) string {
switch typ {
case "cockroach":
pushPositionStmt = ", hlc_to_timestamp(cluster_logical_timestamp()), cluster_logical_timestamp()"
return ", hlc_to_timestamp(cluster_logical_timestamp()), cluster_logical_timestamp()"
case "postgres":
pushPositionStmt = ", statement_timestamp(), EXTRACT(EPOCH FROM clock_timestamp())"
return ", statement_timestamp(), EXTRACT(EPOCH FROM clock_timestamp())"
default:
logging.WithFields("database_type", typ).Panic("position statement for type not implemented")
return ""
}
}