feat: Enable custom query condition in snapshot mode (#51)#80
feat: Enable custom query condition in snapshot mode (#51)#80ardakyigit wants to merge 1 commit intomainfrom
Conversation
- Add QueryCondition to SnapshotConfig and publication.Table - Update all snapshot query builders to inject custom conditions - Per-table conditions take precedence over global conditions Fixes #51 Signed-off-by: Arda Akyigit <arda.akyigit@trendyol.com>
|
# Global condition - applies to all tables
snapshot:
enabled: true
mode: initial
queryCondition: "is_active = true" # Only snapshot active records
# Per-table override - takes precedence
publication:
tables:
- name: users
schema: public
queryCondition: "created_at > '2024-01-01'" # Recent users only
- name: orders
schema: public
# Uses global condition (is_active = true)
- name: archived_data
schema: public
queryCondition: "1=1" # Override: snapshot all rowsit works like that? |
| HeartbeatInterval time.Duration `json:"heartbeatInterval" yaml:"heartbeatInterval"` | ||
| Enabled bool `json:"enabled" yaml:"enabled"` | ||
| Resnapshot bool `json:"resnapshot" yaml:"resnapshot"` | ||
| QueryCondition string `json:"queryCondition" yaml:"queryCondition"` |
There was a problem hiding this comment.
We can add omitempty this too because you already did it on https://github.com/Trendyol/go-pq-cdc/pull/80/changes#diff-0d5f530c672480426b61bfb1ac0f072aadc34cfb1c50c816653dc714f2f83206R41
| } | ||
|
|
||
| for _, table := range s.tables { | ||
| tableSchema := table.Schema |
There was a problem hiding this comment.
getQueryCondition methods takes tableSchema as the first parameter, you also define it here.
We can rename it tblSchema and use it in the for.
tblSchema := table.Schema // Farklı isim, karışıklık yok
if tblSchema == "" {
tblSchema = "public"
}| normalizedSchema = "public" | ||
| } | ||
|
|
||
| for _, table := range s.tables { |
There was a problem hiding this comment.
I happened to see this PR and tried it. However, I found per-table QueryCondition not working.
Probably, the s.tables is synthesised from the PGSQL queries and user-provide config. And the synthesizing code is missing in the locations shown below.
Lines 262 to 264 in 7a137ba
Lines 179 to 181 in 7a137ba
Fixes #51