<reponame>ClaySheffler/dbt
-- insert v2 of the 11 - 21 records

insert into {database}.{schema}.archive_expected (
    "id",
    "first_name",
    "last_name",
    "email",
    "gender",
    "ip_address",
    "updated_at",
    "valid_from",
    "valid_to",
    "dbt_updated_at",
    "scd_id"
)

select
    "id",
    "first_name",
    "last_name",
    "email",
    "gender",
    "ip_address",
    "updated_at",
    -- fields added by archival
    "updated_at" as "valid_from",
    null::timestamp as "valid_to",
    "updated_at" as "dbt_updated_at",
    md5("id" || '-' || "first_name" || '|' || "updated_at"::text) as "scd_id"
from {database}.{schema}.seed
where "id" >= 10 and "id" <= 20;


-- insert 10 new records
insert into {database}.{schema}.seed ("id", "first_name", "last_name", "email", "gender", "ip_address", "updated_at") values
(21, 'Judy', 'Robinson', '<EMAIL>', 'Female', '192.168.127.12', '2016-09-18 08:27:38'),
(22, 'Kevin', 'Alvarez', '<EMAIL>', 'Male', '192.168.3.11', '2016-07-29 03:07:37'),
(23, 'Barbara', 'Carr', '<EMAIL>', 'Female', '172.16.58.3', '2015-09-24 13:27:23'),
(24, 'William', 'Watkins', '<EMAIL>', 'Male', '78.155.84.6', '2016-03-08 19:13:08'),
(25, 'Judy', 'Cooper', '<EMAIL>', 'Female', '172.16.31.10', '2016-10-05 20:49:33'),
(26, 'Shirley', 'Castillo', '<EMAIL>', 'Female', '192.168.3.11', '2016-06-20 21:12:21'),
(27, 'Justin', 'Harper', '<EMAIL>', 'Male', '192.168.127.12', '2016-05-21 22:56:46'),
(28, 'Marie', 'Medina', '<EMAIL>', 'Female', '192.168.3.11', '2015-10-08 13:44:33'),
(29, 'Kelly', 'Edwards', '<EMAIL>', 'Female', '172.16.58.3', '2015-09-15 06:33:37'),
(30, 'Carl', 'Coleman', '<EMAIL>', 'Male', '192.168.3.11', '2016-05-26 16:46:40');


-- add these new records to the archive table
insert into {database}.{schema}.archive_expected (
    "id",
    "first_name",
    "last_name",
    "email",
    "gender",
    "ip_address",
    "updated_at",
    "valid_from",
    "valid_to",
    "dbt_updated_at",
    "scd_id"
)

select
    "id",
    "first_name",
    "last_name",
    "email",
    "gender",
    "ip_address",
    "updated_at",
    -- fields added by archival
    "updated_at" as "valid_from",
    null::timestamp as "valid_to",
    "updated_at" as "dbt_updated_at",
    md5("id" || '-' || "first_name" || '|' || "updated_at"::text) as "scd_id"
from {database}.{schema}.seed
where "id" > 20;
