33 lines
1.5 KiB
Plaintext
33 lines
1.5 KiB
Plaintext
DESCRIPTION >
|
|
Chunked backfill of free_trials from Postgres into free_trials.
|
|
Chunks by created_at (epoch ms). Cast numeric columns to match datasource schema.
|
|
|
|
NODE migrate
|
|
SQL >
|
|
%
|
|
SELECT
|
|
assumeNotNull(id) AS id,
|
|
created_at::Int64 AS created_at,
|
|
internal_product_id,
|
|
coalesce(duration, 'day') AS duration,
|
|
if(length IS NULL, NULL, length::Float64) AS length,
|
|
toUInt8(if(coalesce(unique_fingerprint, false), 1, 0)) AS unique_fingerprint,
|
|
toUInt8(if(coalesce(is_custom, false), 1, 0)) AS is_custom,
|
|
toUInt8(if(coalesce(card_required, false), 1, 0)) AS card_required,
|
|
'read' AS __action,
|
|
toDateTime64(now(), 6) AS __commit_timestamp,
|
|
0 AS __commit_lsn,
|
|
concat('backfill-', assumeNotNull(id)) AS __idempotency_key
|
|
FROM postgresql(
|
|
'aws-us-east-2-2.pg.psdb.cloud:5432',
|
|
'postgres',
|
|
'free_trials',
|
|
{{tb_secret('PG_USERNAME')}},
|
|
{{tb_secret('PG_PASSWORD')}}
|
|
)
|
|
WHERE created_at > {{Int64(start_epoch_ms, 0)}}
|
|
AND created_at <= {{Int64(end_epoch_ms, 9999999999999)}}
|
|
|
|
TYPE COPY
|
|
TARGET_DATASOURCE free_trials
|